Uses 911K of libraries. Click here for Pure Java version (8609L/43K).
1 | !7 |
2 | |
3 | sclass SearchResult { |
4 | S snippetID; |
5 | S title; |
6 | int occurrences; |
7 | |
8 | sS _fieldOrder = "snippetID title occurrences"; |
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 query = upper(input); |
35 | S index = dm_require("#1029008/SnippetsDoubleWordIndex"); |
36 | Cl<S> preSnippetIDs = cast dm_call(index, 'snippetsContainingTextIC_preSearch, query); |
37 | print("Pre-search: " + (preSnippetIDs == null ? "-" : lstr(preSnippetIDs))); |
38 | |
39 | S mod = dm_require("#1028945/CacheAllSnippets"); |
40 | SS data = cast dm_rcall getData(mod); |
41 | SS titles = cast dm_rcall getTitles(mod); |
42 | new L<SearchResult> out; |
43 | if (preSnippetIDs == null) preSnippetIDs = keys(data); |
44 | long nanos = 0; |
45 | if (nempty(query)) { |
46 | nanos = nanoTime(); |
47 | fOr ping (S snippetID : preSnippetIDs) { |
48 | S text = data.get(snippetID); |
49 | continue if l(text) > maxTextLength; |
50 | S title = titles.get(snippetID); |
51 | int n = |
52 | countOccurrencesIC(title, query) |
53 | + countOccurrences_optimizedForZero(text, query); |
54 | if (n > 0) { |
55 | new SearchResult r; |
56 | r.snippetID = snippetID; |
57 | r.title = title; |
58 | r.occurrences = n; |
59 | out.add(r); |
60 | if (l(out) >= maxResults) break; |
61 | } |
62 | } |
63 | nanos = max(nanoTime()-nanos, 0); |
64 | } |
65 | sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences); |
66 | if (setStatus) |
67 | setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) + " ms")); |
68 | ret out; |
69 | } |
70 | } |
Began life as a copy of #1028975
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: | #1029009 |
Snippet name: | Instant Full-Text Snippet Search v3 [using double word index, skips texts > 100k chars] |
Eternal ID of this version: | #1029009/6 |
Text MD5: | b4b2ab5bd7c9eaeb7867748ddc76140b |
Transpilation MD5: | 521202e26db77912e06bcb5a02d76ad4 |
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-16 19:31:32 |
Source code size: | 2176 bytes / 70 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 210 / 310 |
Version history: | 5 change(s) |
Referenced in: | [show references] |