feat: update version to 0.0.8 and enhance search query filtering in ProjectSearch

This commit is contained in:
xiongxiao
2026-03-13 22:00:19 +08:00
committed by cnb
parent 711aa221a5
commit b60f365a6b
2 changed files with 13 additions and 9 deletions

View File

@@ -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,