diff --git a/src/plugin.ts b/src/plugin.ts index 5622589..0043862 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -91,13 +91,14 @@ export default class RedisStorage implements IPluginStorage { public async searchV1(query): Promise { 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(); + const text = (query.text || "").replace(/-/g, ' ').trim(); if (!text) return []; 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", "LIMIT", String(offset), String(num)); const searchResult: any = []; + if (result.length <= 1) return []; for (let i = 2; i < result.length; i += 2) { const stat = JSON.parse(result[i][1]); searchResult.push({ @@ -120,6 +121,7 @@ export default class RedisStorage implements IPluginStorage { return searchResult; } catch (error) { this.logger.error(error, "searchV1 error: @{error}"); + return []; } }