// returns a prefiltered list of elements; you still need to do a
// full-text search on those.
// If it returns null, you have to search all elements
static Cl doubleWordIndex_lookupString(DoubleWordIndex index, S query, O... _) {
optPar bool debug;
L ranges = index.wordRanges(query);
if (empty(ranges)) null;
new L> sets;
for (IntRange r : ranges) { // go through words in query
S word = substring(query, r);
Set l;
if (r.start == 0)
if (r.end == l(query)) // bad case - look for part of word
l = msmGetAllAsSet(index.index1.index, containingIC(index.index1.words(), word));
else { // look for ending of word - use reverse index
Cl words = prefixSubSet(index.index2.words(), reversed(word));
l = msmGetAllAsSet(index.index2.index, words);
if (debug)
print(n2(words) + "/" + nEntries(l) + " for: " + word);
}
else if (r.end == l(query)) { // look for start of word
Cl words = prefixSubSet(index.index1.words(), word);
l = msmGetAllAsSet(index.index1.index, words);
if (debug)
print(n2(words) + "/" + nEntries(l) + " for: " + word);
} else // look for complete word
l = index.get(word);
if (empty(l)) ret l;
sets.add(l);
}
Set smallest = smallestCollection(sets), out = smallest;
for (Set set : sets) {
if (set == smallest) continue;
new Set out2;
for (A a : out)
if (set.contains(a))
out2.add(a);
out = out2;
}
ret out;
}