Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33057475
D9625.1768430265.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D9625.1768430265.diff
View Options
diff --git a/lib/shared/search-index.js b/lib/shared/search-index.js
--- a/lib/shared/search-index.js
+++ b/lib/shared/search-index.js
@@ -15,13 +15,16 @@
...
};
+type TokenizeFunc = (str: string) => Token[];
+const defaultTokenize: TokenizeFunc = new Tokenizer().words();
+
class SearchIndex {
tokenize: (str: string) => Token[];
fullTextIndex: { [token: string]: Set<string> };
partialTextIndex: { [token: string]: Set<string> };
- constructor() {
- this.tokenize = new Tokenizer().words();
+ constructor(inputTokenize?: TokenizeFunc) {
+ this.tokenize = inputTokenize ?? defaultTokenize;
this.fullTextIndex = {};
this.partialTextIndex = {};
}
diff --git a/lib/shared/sentence-prefix-search-index.js b/lib/shared/sentence-prefix-search-index.js
--- a/lib/shared/sentence-prefix-search-index.js
+++ b/lib/shared/sentence-prefix-search-index.js
@@ -4,12 +4,15 @@
import SearchIndex from './search-index.js';
+// defaultTokenize used in SearchIndex splits on punctuation
+// We use this alternative because we only want to split on whitespace
+const tokenize = new Tokenizer().re(/\S+/);
+
class SentencePrefixSearchIndex extends SearchIndex {
entries: Set<string>;
constructor() {
- super();
- this.tokenize = new Tokenizer().re(/\S+/);
+ super(tokenize);
this.entries = new Set();
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 10:37 PM (7 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5934380
Default Alt Text
D9625.1768430265.diff (1 KB)
Attached To
Mode
D9625: [lib] Avoid constructing multiple duplicate tokenizers in SearchIndex
Attached
Detach File
Event Timeline
Log In to Comment