!7 sclass SearchResult { S snippetID; S title; //int occurrences; sS _fieldOrder = "snippetID title"; } cmodule FullTextSnippetSearch > DynTableWithInput2 { 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 { dm_showPoorMansProfile(r { benchFor5Seconds(r { hijackPrint(r { search("this is cool", false) }) }); }); } L search(S input, bool setStatus) { S query = upper(input); S index = dm_require("#1029010/SnippetsDeepDoubleWordIndex"); long nanos = nanoTime(); Iterable preSnippetIDs = cast dm_call(index, 'snippetsContainingTextIC_preSearch, query); //print("Pre-search: " + (preSnippetIDs == null ? "-" : lstr(preSnippetIDs))); S mod = dm_require("#1028945/CacheAllSnippets"); SS data = cast dm_rcall getData(mod); SS titles = cast dm_rcall getTitles(mod); new L out; if (preSnippetIDs == null) preSnippetIDs = keys(data); int scanned = 0; if (nempty(query)) { fOr ping (S snippetID : preSnippetIDs) { S text = data.get(snippetID); continue if l(text) > maxTextLength; S title = titles.get(snippetID); /*int n = countOccurrencesIC(title, query) + countOccurrences_optimizedForZero(text, query); bool found = n > 0;*/ scanned += l(text); bool found = contains(text, query); if (found) { new SearchResult r; r.snippetID = snippetID; r.title = title; //r.occurrences = n; out.add(r); if (l(out) >= maxResults) break; } } } nanos = max(nanoTime()-nanos, 0); print("Scanned chars: " + scanned); //sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences); if (setStatus) setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) + " ms")); ret out; } }