!7 cprint SnippetsDeepWordPairIndex { transient DeepWordPairIndex 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 DeepWordPairIndex wordIndex; wordIndex.regexp = regexp; wordIndex.useHashMaps(); // faster for (virtual CSnippet sn : dm_allSnippets()) { S snippetID = (S) rcall snippetID(sn); S text = cast rcall text(sn); wordIndex.add(snippetID, text); } setField(+wordIndex); } infoBox("Indexed " + nPairs(wordIndex.numPairs())); } // API Iterable>> snippetPreSearch_withPositions(S query, O... _) { Iterable>> l; //time "lookup" { l = wordIndex == null ? null : wordIndex.lookupString_withPositions(query, _); //} ret l; } }