!7 cprint SnippetsDeepWordIndex { transient DeepWordIndex wordIndex; // string = snippet ID switchable S regexp = "\\w+|\\S"; // a word or a non-space start-thread { dm_reloadOnFieldChange regexp(); time "Make double word index" { print("Making index"); new DeepWordIndex wordIndex; wordIndex.regexp = regexp; wordIndex.useHashMaps = true; wordIndex.sortEntries = true; for (virtual CSnippet sn : dm_allSnippets()) { S snippetID = (S) rcall snippetID(sn); S text = cast rcall text(sn); wordIndex.add(snippetID, text); } wordIndex.doneAdding(); setField(+wordIndex); } infoBox("Indexed " + nWords(wordIndex.numWords())); } // API Iterable>> snippetPreSearch_withPositions(S query, O... _) { long nanos = nanoTime(); Iterable>> l; //time "lookup" { l = wordIndex == null ? null : wordIndex.lookupString_withPositions(query, _); //} //print((nanoTime()-nanos) + " nanos in pre"); ret l; } }