Skip to content

Commit

Permalink
fix: use query.from and query.size for searchV1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Oct 24, 2023
1 parent 0659f1f commit 3fbd97e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,18 @@ export default class RedisStorage implements IPluginStorage<RedisConfig> {
}

/**
* Search api implementation for verdaccio-redis-search-patch and verdaccio@6
* @param query
* Search api v1 implementation for verdaccio-redis-search-patch and verdaccio@5
* @param query search query object with {text, from, size}
*/
public async searchV1(query): Promise<any> {
this.logger.debug({ query }, "searchV1 query: @{query}");
// Redis-search treats hyphen as separator, refs https://forum.redis.com/t/query-with-dash-is-treated-as-negation/119
const text = (query.text || "").replace(/-/g, ' ').trim();
if (!text) return [];
// const offset = query.from || 0;
// const num = query.size || 250;
const offset = query.from || 0;
const num = query.size || 250;
try {
const result: any = await this.redisClient.call("FT.SEARCH", "ve-pkg-stat-idx", text, "return", "1", "stat");
// const result: any = await this.redisClient.call("FT.SEARCH", "ve-pkg-stat-idx", text, "return", "1", "stat", "LIMIT", String(offset), String(num));
const result: any = await this.redisClient.call("FT.SEARCH", "ve-pkg-stat-idx", text, "return", "1", "stat", "LIMIT", String(offset), String(num));
const searchResult: any = [];
if (result.length <= 1) return [];
for (let i = 2; i < result.length; i += 2) {
Expand Down

0 comments on commit 3fbd97e

Please sign in to comment.