Uses 911K of libraries. Click here for Pure Java version (8578L/43K).
1 | !7 |
2 | |
3 | sclass SearchResult { |
4 | S snippetID; |
5 | S title; |
6 | int occurrences; |
7 | |
8 | sS _fieldOrder = "snippetID title"; |
9 | } |
10 | |
11 | cmodule FullTextSnippetSearch > DynTableWithInput2<SearchResult> { |
12 | switchable int maxResults = 1000; |
13 | switchable int maxTextLength = 100000; |
14 | transient S status; |
15 | |
16 | JComponent mainComponent() { |
17 | ret northAndCenterWithMargin(dm_rightAlignedLabel status(), super.mainComponent()); |
18 | } |
19 | |
20 | start { |
21 | dontPersist(); |
22 | //thread { warmUp(); } |
23 | } |
24 | |
25 | void calc { |
26 | setList(search(input, true)); |
27 | } |
28 | |
29 | void warmUp enter { |
30 | benchFor5Seconds(r { hijackPrint(r { search("this is cool", false) }) }); |
31 | } |
32 | |
33 | L<SearchResult> search(S input, bool setStatus) { |
34 | S mod = dm_require("#1028945/CacheAllSnippets"); |
35 | SS data = cast dm_rcall getData(mod); |
36 | SS titles = cast dm_rcall getTitles(mod); |
37 | |
38 | S index = dm_require("#1029025/SnippetsDeepWordIndex"); |
39 | O indexMod = dm_mod(index); |
40 | S query = upper(input); |
41 | int lQuery = l(query); |
42 | print(query := quote(query)); |
43 | |
44 | long nanos = nanoTime(); |
45 | |
46 | Iterable</*virtual Pair<S, Cl<S>>*/O> pre = cast dm_call_resolved(indexMod, 'snippetPreSearch_withPositions, query, null); |
47 | pre = asList(pre); |
48 | long nanos1 = nanoTime()-nanos; |
49 | |
50 | new L<SearchResult> out; |
51 | if (pre == null) { |
52 | if (setStatus) print("No pres"); |
53 | pre = mapI(keys(data), snippetID -> pair(snippetID, null)); |
54 | } |
55 | int badPres = 0, printBadPres = 100; |
56 | if (nempty(query)) { |
57 | fOr ping (O entry : pre) { |
58 | Pair<S, Cl<Int>> p = quickImportPair(entry); |
59 | S snippetID = p.a; |
60 | Cl<Int> positions = p.b; |
61 | S text = data.get(snippetID); |
62 | continue if l(text) > maxTextLength; |
63 | int n = 0; |
64 | if (positions == null) |
65 | n = countOccurrences(text, query); |
66 | else |
67 | for (int i : positions) |
68 | if (regionMatches(text, i, query, 0, lQuery)) |
69 | ++n; |
70 | else { |
71 | if (printBadPres > 0) { |
72 | --printBadPres; |
73 | print("Bad pre: " + snippetID + "@" + i + " of " + l(text) + ": " + quote(substring(text, i, i+lQuery))); |
74 | } |
75 | ++badPres; |
76 | } |
77 | bool found = n > 0; |
78 | if (found) { |
79 | S title = titles.get(snippetID); |
80 | new SearchResult r; |
81 | r.snippetID = snippetID; |
82 | r.title = title; |
83 | r.occurrences = n; |
84 | out.add(r); |
85 | if (l(out) >= maxResults) break; |
86 | } |
87 | } |
88 | } |
89 | //sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences); |
90 | nanos = max(nanoTime()-nanos, 0); |
91 | if (setStatus) { |
92 | print("Bad pres: " + badPres); |
93 | setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " |
94 | + formatDouble(nanoSecondsToMilliseconds(nanos1), 3) |
95 | + " / " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) |
96 | + " ms")); |
97 | } |
98 | ret out; |
99 | } |
100 | } |
Began life as a copy of #1029017
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: | #1029035 |
Snippet name: | Instant Full-Text Snippet Search v5 [using deep word index] |
Eternal ID of this version: | #1029035/15 |
Text MD5: | e7efb1bb794d9e4f3ce8fc4ceb02b285 |
Transpilation MD5: | 77c989422b9fe2d23a04b2db66f71cd2 |
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:45:34 |
Source code size: | 3038 bytes / 100 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 260 / 1098 |
Version history: | 14 change(s) |
Referenced in: | [show references] |