Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2898998
D9625.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D9625.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
Sun, Oct 6, 4:47 AM (20 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247912
Default Alt Text
D9625.diff (1 KB)
Attached To
Mode
D9625: [lib] Avoid constructing multiple duplicate tokenizers in SearchIndex
Attached
Detach File
Event Timeline
Log In to Comment