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

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/project-search", "name": "@kevisual/project-search",
"version": "0.0.6", "version": "0.0.8",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -92,17 +92,21 @@ export class ProjectSearch {
getContent?: boolean; getContent?: boolean;
}) { }) {
const filter: string[] = []; 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?.repo) filter.push(`repo = "${options.repo}"`);
if (options?.filepath) filter.push(`filepath = "${options.filepath}"`); if (options?.filepath) filter.push(`filepath STARTS WITH "${options.filepath}"`);
if (options?.title) filter.push(`title = "${options.title}"`); 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) { if (options?.tags) {
const tags = Array.isArray(options.tags) ? options.tags : [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}"`); const fullQuery = [query, ...searchTerms].filter(Boolean).join(' ');
if (options?.link) filter.push(`link = "${options.link}"`);
const limit = options?.limit ?? 1000; const limit = options?.limit ?? 1000;
const search = { const search = {
filter: filter.length ? filter.join(' AND ') : undefined, filter: filter.length ? filter.join(' AND ') : undefined,
@@ -114,7 +118,7 @@ export class ProjectSearch {
let allHits: FileProjectData[] = []; let allHits: FileProjectData[] = [];
let offset = 0; let offset = 0;
while (true) { while (true) {
const searchResults = await this.index.search(query, { const searchResults = await this.index.search(fullQuery, {
...search, ...search,
limit: Math.min(limit - allHits.length, 1000), limit: Math.min(limit - allHits.length, 1000),
offset, offset,