Uses 911K of libraries. Click here for Pure Java version (8549L/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("#1029043/SnippetsDeepWordPairIndex");
 | 
| 39 | long nanos = nanoTime(); | 
| 40 | |
| 41 | S query = upper(input); | 
| 42 | Iterable</*virtual Pair<S, Cl<S>>*/O> pre = cast dm_call(index, 'snippetPreSearch_withPositions, query); | 
| 43 | long nanos1 = nanoTime()-nanos; | 
| 44 | |
| 45 | new L<SearchResult> out; | 
| 46 |     if (pre == null) {
 | 
| 47 |       if (setStatus) print("No pres");
 | 
| 48 | pre = mapI(keys(data), snippetID -> pair(snippetID, null)); | 
| 49 | } | 
| 50 | int badPres = 0; | 
| 51 |     if (nempty(query)) {
 | 
| 52 |       fOr ping (O entry : pre) {
 | 
| 53 | Pair<S, Cl<Int>> p = quickImportPair(entry); | 
| 54 | S snippetID = p.a; | 
| 55 | Cl<Int> positions = p.b; | 
| 56 | S text = data.get(snippetID); | 
| 57 | continue if l(text) > maxTextLength; | 
| 58 | int n = 0; | 
| 59 | if (positions == null) | 
| 60 | n = countOccurrences(text, query); | 
| 61 | else | 
| 62 | for (int i : positions) | 
| 63 | if (regionMatches(text, i, query, 0, l(query))) | 
| 64 | ++n; | 
| 65 | else | 
| 66 | ++badPres; | 
| 67 | bool found = n > 0; | 
| 68 |         if (found) {
 | 
| 69 | S title = titles.get(snippetID); | 
| 70 | new SearchResult r; | 
| 71 | r.snippetID = snippetID; | 
| 72 | r.title = title; | 
| 73 | r.occurrences = n; | 
| 74 | out.add(r); | 
| 75 | if (l(out) >= maxResults) break; | 
| 76 | } | 
| 77 | } | 
| 78 | } | 
| 79 | //sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences); | 
| 80 | nanos = max(nanoTime()-nanos, 0); | 
| 81 |     if (setStatus) {
 | 
| 82 |       print("Bad pres: " + badPres);
 | 
| 83 | setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " | 
| 84 | + formatDouble(nanoSecondsToMilliseconds(nanos1), 3) | 
| 85 | + " / " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) | 
| 86 | + " ms")); | 
| 87 | } | 
| 88 | ret out; | 
| 89 | } | 
| 90 | } | 
Began life as a copy of #1029035
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: | #1029044 | 
| Snippet name: | Instant Full-Text Snippet Search v6 [using deep word pair index] | 
| Eternal ID of this version: | #1029044/3 | 
| Text MD5: | bec91284e71d3e817c24536ef4bf6058 | 
| Transpilation MD5: | 647ede890dfc2904f8cb2692ad6b2159 | 
| 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:11:12 | 
| Source code size: | 2648 bytes / 90 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 480 / 680 | 
| Version history: | 2 change(s) | 
| Referenced in: | [show references] |