Uses 911K of libraries. Click here for Pure Java version (8578L/43K).
!7 sclass SearchResult { S snippetID; S title; int occurrences; sS _fieldOrder = "snippetID title"; } cmodule FullTextSnippetSearch > DynTableWithInput2<SearchResult> { switchable int maxResults = 1000; switchable int maxTextLength = 100000; transient S status; JComponent mainComponent() { ret northAndCenterWithMargin(dm_rightAlignedLabel status(), super.mainComponent()); } start { dontPersist(); //thread { warmUp(); } } void calc { setList(search(input, true)); } void warmUp enter { benchFor5Seconds(r { hijackPrint(r { search("this is cool", false) }) }); } L<SearchResult> search(S input, bool setStatus) { S mod = dm_require("#1028945/CacheAllSnippets"); SS data = cast dm_rcall getData(mod); SS titles = cast dm_rcall getTitles(mod); S index = dm_require("#1029025/SnippetsDeepWordIndex"); O indexMod = dm_mod(index); S query = upper(input); int lQuery = l(query); print(query := quote(query)); long nanos = nanoTime(); Iterable</*virtual Pair<S, Cl<S>>*/O> pre = cast dm_call_resolved(indexMod, 'snippetPreSearch_withPositions, query, null); pre = asList(pre); long nanos1 = nanoTime()-nanos; new L<SearchResult> out; if (pre == null) { if (setStatus) print("No pres"); pre = mapI(keys(data), snippetID -> pair(snippetID, null)); } int badPres = 0, printBadPres = 100; if (nempty(query)) { fOr ping (O entry : pre) { Pair<S, Cl<Int>> p = quickImportPair(entry); S snippetID = p.a; Cl<Int> positions = p.b; S text = data.get(snippetID); continue if l(text) > maxTextLength; int n = 0; if (positions == null) n = countOccurrences(text, query); else for (int i : positions) if (regionMatches(text, i, query, 0, lQuery)) ++n; else { if (printBadPres > 0) { --printBadPres; print("Bad pre: " + snippetID + "@" + i + " of " + l(text) + ": " + quote(substring(text, i, i+lQuery))); } ++badPres; } bool found = n > 0; if (found) { S title = titles.get(snippetID); new SearchResult r; r.snippetID = snippetID; r.title = title; r.occurrences = n; out.add(r); if (l(out) >= maxResults) break; } } } //sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences); nanos = max(nanoTime()-nanos, 0); if (setStatus) { print("Bad pres: " + badPres); setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + formatDouble(nanoSecondsToMilliseconds(nanos1), 3) + " / " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) + " ms")); } ret out; } }
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: | 241 / 1074 |
Version history: | 14 change(s) |
Referenced in: | [show references] |