Skip to content

Commit 9b63fcd

Browse files
committed
feat(search): add removeDocument method to Tfidf class
This commit introduces a new method, removeDocument, to the Tfidf class in the code-search module. This method allows for the removal of a document from the documents array using a key. If the document is found and removed, the idfCache is invalidated.
1 parent a7a1862 commit 9b63fcd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/code-search/search/tfidf/Tfidf.ts

+16
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ export class TfIdf<K, V> {
357357
}
358358
}
359359

360+
removeDocument(key: string) {
361+
const index = this.documents.findIndex(function (document) {
362+
return (document as any)['__key'] === key;
363+
});
364+
365+
// If found, remove it
366+
if (index > -1) {
367+
this.documents.splice(index, 1);
368+
// Invalidate the cache
369+
this._idfCache = Object.create(null);
370+
return true;
371+
}
372+
373+
return false;
374+
}
375+
360376
/**
361377
* The `tfidf` method is used to calculate the Term Frequency-Inverse Document Frequency (TF-IDF) for a
362378
* given term or array of terms in a specific document. TF-IDF is a numerical statistic that reflects how

0 commit comments

Comments
 (0)