Skip to content

Commit cc70d68

Browse files
authored
feat: add listIds() to SearchProvider (#11)
1 parent e8837c2 commit cc70d68

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/db/sqlite.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ export async function sqlite(config: SqliteConfig): Promise<SearchProvider> {
333333
}
334334
},
335335

336+
async listIds() {
337+
const rows = db.prepare('SELECT id FROM documents_meta').all() as Array<{ id: string }>
338+
return rows.map(r => r.id)
339+
},
340+
336341
async clear() {
337342
db.exec('DELETE FROM documents_fts')
338343
db.exec('DELETE FROM documents_vec')

src/retriv.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ export async function createRetriv(options: RetrivOptions): Promise<SearchProvid
226226
return { count: results[0]?.count ?? 0 }
227227
},
228228

229+
async listIds() {
230+
const driver = drivers.find(d => d.listIds)
231+
const ids = await driver?.listIds?.() ?? []
232+
if (!chunker)
233+
return ids
234+
const parentIds = new Set<string>()
235+
for (const id of ids) {
236+
const sep = id.indexOf('#chunk-')
237+
parentIds.add(sep >= 0 ? id.substring(0, sep) : id)
238+
}
239+
return Array.from(parentIds)
240+
},
241+
229242
async clear() {
230243
await Promise.all(drivers.filter(d => d.clear).map(d => d.clear!()))
231244
parentDocs.clear()

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ export interface SearchProvider {
137137
*/
138138
remove?: (ids: string[]) => Promise<{ count: number }>
139139

140+
/**
141+
* List all indexed document IDs
142+
*/
143+
listIds?: () => Promise<string[]>
144+
140145
/**
141146
* Clear all indexed documents
142147
*/

0 commit comments

Comments
 (0)