!7 srecord noeq Entry( S snippetID, int[] indices // where in the text does the word occur ) {}} cprint SnippetsDoubleWordIndex { transient DoubleWordIndex wordIndex; start-thread { time "Make double word index" { new DoubleWordIndex wordIndex; for (virtual CSnippet sn : dm_allSnippets()) { S snippetID = (S) rcall snippetID(sn); S text = cast rcall text(sn); MultiMap positions = ciMultiMap(); for (IntRange r : wordIndex.wordRange(text)) positions.put(substring(text, r), r.start); for (S word, L indices : asMap()) wordIndex.addWord(word, new Entry(text, toIntArray(indices))); } setField(+wordIndex); } print("Indexed " + nWords(wordIndex.numWords())); } // API // may return null (no pre-search result) Cl snippetsContainingTextIC_preSearch(S query) { ret doubleWordIndex_lookupString(wordIndex, query); } }