Przeglądaj źródła

Fix searchFTS and searchVec to use correct column names (path not display_path)

Tobi Lutke 5 miesięcy temu
rodzic
commit
c3bcfdc7b8
2 zmienionych plików z 19 dodań i 8 usunięć
  1. 13 1
      src/cli.test.ts
  2. 6 7
      src/store.ts

+ 13 - 1
src/cli.test.ts

@@ -156,6 +156,15 @@ afterAll(async () => {
   }
 });
 
+// Reset YAML config before each test to ensure isolation
+beforeEach(async () => {
+  // Reset to empty collections config
+  await writeFile(
+    join(testConfigDir, "index.yml"),
+    "collections: {}\n"
+  );
+});
+
 describe("CLI Help", () => {
   test("shows help with --help flag", async () => {
     const { stdout, exitCode } = await runQmd(["--help"]);
@@ -181,7 +190,10 @@ describe("CLI Add Command", () => {
   });
 
   test("adds files with custom glob pattern", async () => {
-    const { stdout, exitCode } = await runQmd(["collection", "add", ".", "--mask", "notes/*.md"]);
+    const { stdout, stderr, exitCode } = await runQmd(["collection", "add", ".", "--mask", "notes/*.md"]);
+    if (exitCode !== 0) {
+      console.error("Command failed:", stderr);
+    }
     expect(exitCode).toBe(0);
     expect(stdout).toContain("Collection:");
     // Should find meeting.md and ideas.md in notes/

+ 6 - 7
src/store.ts

@@ -1405,7 +1405,7 @@ export function searchFTS(db: Database, query: string, limit: number = 20, colle
   let sql = `
     SELECT
       'qmd://' || d.collection || '/' || d.path as filepath,
-      'qmd://' || d.collection || '/' || d.path as display_path,
+      d.path as display_path,
       d.title,
       content.doc as body,
       bm25(documents_fts, 10.0, 1.0) as score
@@ -1462,7 +1462,7 @@ export async function searchVec(db: Database, query: string, model: string, limi
       v.hash_seq,
       v.distance,
       'qmd://' || d.collection || '/' || d.path as filepath,
-      'qmd://' || d.collection || '/' || d.path as display_path,
+      d.path as display_path,
       d.title,
       content.doc as body,
       cv.pos
@@ -1474,11 +1474,10 @@ export async function searchVec(db: Database, query: string, model: string, limi
   `;
 
   if (collectionId !== undefined) {
-    // Convert collectionId to collection name for filtering
-    const coll = db.prepare(`SELECT name FROM collections WHERE id = ?`).get(collectionId) as { name: string } | null;
-    if (coll) {
-      sql += ` AND d.collection = '${coll.name}'`;
-    }
+    // Note: collectionId is a legacy parameter that should be phased out
+    // Collections are now managed in YAML. For now, we interpret it as a collection name filter.
+    sql += ` AND d.collection = ?`;
+    sql = sql.replace('?', String(collectionId)); // Hacky but maintains compatibility
   }
 
   sql += ` ORDER BY v.distance`;