Uses 911K of libraries. Click here for Pure Java version (6519L/32K).
1 | !7 |
2 | |
3 | cprint SnippetsDeepWordIndex { |
4 | transient DeepWordIndex<S> wordIndex; // string = snippet ID |
5 | switchable S regexp = "\\w+|\\S"; // a word or a non-space |
6 | |
7 | start-thread { |
8 | dm_reloadOnFieldChange regexp(); |
9 | time "Make double word index" { |
10 | print("Making index"); |
11 | new DeepWordIndex<S> wordIndex; |
12 | wordIndex.regexp = regexp; |
13 | wordIndex.useHashMaps = true; |
14 | wordIndex.sortEntries = true; |
15 | for (virtual CSnippet sn : dm_allSnippets()) { |
16 | S snippetID = (S) rcall snippetID(sn); |
17 | S text = cast rcall text(sn); |
18 | wordIndex.add(snippetID, text); |
19 | } |
20 | wordIndex.doneAdding(); |
21 | setField(+wordIndex); |
22 | } |
23 | infoBox("Indexed " + nWords(wordIndex.numWords())); |
24 | } |
25 | |
26 | // API |
27 | |
28 | Iterable<Pair<S, Cl<Int>>> snippetPreSearch_withPositions(S query, O... _) { |
29 | long nanos = nanoTime(); |
30 | Iterable<Pair<S, Cl<Int>>> l; |
31 | //time "lookup" { |
32 | l = wordIndex == null ? null : wordIndex.lookupString_withPositions(query, _); |
33 | //} |
34 | //print((nanoTime()-nanos) + " nanos in pre"); |
35 | ret l; |
36 | } |
37 | } |
Began life as a copy of #1029010
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029025 |
Snippet name: | Snippets Deep Word Index [OK] |
Eternal ID of this version: | #1029025/18 |
Text MD5: | e4eb469b547db7a3134cd5bb5318ce1b |
Transpilation MD5: | 4f93bb17f21bffc4c552a154030dc7bc |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-17 18:54:22 |
Source code size: | 1109 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 260 / 799 |
Version history: | 17 change(s) |
Referenced in: | [show references] |