feat: update version to 0.0.8 and enhance search query filtering in ProjectSearch
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user