diff --git a/package.json b/package.json index 9fe1985..9e3a1d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/project-search", - "version": "0.0.6", + "version": "0.0.8", "description": "", "main": "index.js", "scripts": { diff --git a/src/project/project-search/index.ts b/src/project/project-search/index.ts index dee636c..6357c25 100644 --- a/src/project/project-search/index.ts +++ b/src/project/project-search/index.ts @@ -92,17 +92,21 @@ export class ProjectSearch { getContent?: boolean; }) { const filter: string[] = []; - if (options?.projectPath) filter.push(`projectPath = "${options.projectPath}"`); + if (options?.projectPath) filter.push(`projectPath STARTS WITH "${options.projectPath}"`); if (options?.repo) filter.push(`repo = "${options.repo}"`); - if (options?.filepath) filter.push(`filepath = "${options.filepath}"`); - if (options?.title) filter.push(`title = "${options.title}"`); + if (options?.filepath) filter.push(`filepath STARTS WITH "${options.filepath}"`); + if (options?.link) filter.push(`link = "${options.link}"`); + // title、summary、description、tags 使用全文搜索(部分匹配) + const searchTerms: string[] = []; + if (options?.title) searchTerms.push(options.title); + if (options?.summary) searchTerms.push(options.summary); + if (options?.description) searchTerms.push(options.description); if (options?.tags) { const tags = Array.isArray(options.tags) ? options.tags : [options.tags]; - tags.forEach(tag => filter.push(`tags = "${tag}"`)); + tags.forEach(tag => searchTerms.push(tag)); } - if (options?.summary) filter.push(`summary = "${options.summary}"`); - if (options?.description) filter.push(`description = "${options.description}"`); - if (options?.link) filter.push(`link = "${options.link}"`); + // 合并到主搜索词 + const fullQuery = [query, ...searchTerms].filter(Boolean).join(' '); const limit = options?.limit ?? 1000; const search = { filter: filter.length ? filter.join(' AND ') : undefined, @@ -114,7 +118,7 @@ export class ProjectSearch { let allHits: FileProjectData[] = []; let offset = 0; while (true) { - const searchResults = await this.index.search(query, { + const searchResults = await this.index.search(fullQuery, { ...search, limit: Math.min(limit - allHits.length, 1000), offset,