@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new ExitableTermsEnum(in.intersect(compiled, startTerm), queryTimeout); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { final List<MultiTermsEnum.TermsEnumIndex> termsEnums = new ArrayList<>(); for(int i=0;i<subs.length;i++) { final TermsEnum termsEnum = subs[i].intersect(compiled, startTerm); if (termsEnum != null) { termsEnums.add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i)); } } if (termsEnums.size() > 0) { return new MultiTermsEnum(subSlices).reset(termsEnums.toArray(MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY)); } else { return TermsEnum.EMPTY; } }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new SortingTermsEnum(in.intersect(compiled, startTerm), docMap, indexOptions, hasPositions()); }
/** * return an automata-based enum for matching up to editDistance from * lastTerm, if possible */ private TermsEnum getAutomatonEnum(int editDistance, BytesRef lastTerm) throws IOException { assert editDistance < automata.length; final CompiledAutomaton compiled = automata[editDistance]; BytesRef initialSeekTerm; if (lastTerm == null) { // This is the first enum we are pulling: initialSeekTerm = null; } else { // We are pulling this enum (e.g., ed=1) after iterating for a while already (e.g., ed=2): initialSeekTerm = compiled.floor(lastTerm, new BytesRefBuilder()); } return terms.intersect(compiled, initialSeekTerm); }
/** Return a {@link TermsEnum} intersecting the provided {@link Terms} * with the terms accepted by this automaton. */ public TermsEnum getTermsEnum(Terms terms) throws IOException { switch(type) { case NONE: return TermsEnum.EMPTY; case ALL: return terms.iterator(); case SINGLE: return new SingleTermsEnum(terms.iterator(), term); case NORMAL: return terms.intersect(this, null); default: // unreachable throw new RuntimeException("unhandled case"); } }
/** Test Terms.intersect on this range, and validates that it returns the same doc ids as using non-intersect TermsEnum. Returns true if * any fake terms were seen. */ private static boolean checkSingleTermRange(String field, int maxDoc, Terms terms, BytesRef minTerm, BytesRef maxTerm, FixedBitSet normalDocs, FixedBitSet intersectDocs) throws IOException { //System.out.println(" check minTerm=" + minTerm.utf8ToString() + " maxTerm=" + maxTerm.utf8ToString()); assert minTerm.compareTo(maxTerm) <= 0; TermsEnum termsEnum = terms.iterator(); TermsEnum.SeekStatus status = termsEnum.seekCeil(minTerm); if (status != TermsEnum.SeekStatus.FOUND) { throw new RuntimeException("failed to seek to existing term field=" + field + " term=" + minTerm); } // Do "dumb" iteration to visit all terms in the range: long normalTermCount = getDocsFromTermRange(field, maxDoc, termsEnum, normalDocs, minTerm, maxTerm, false); // Now do the same operation using intersect: long intersectTermCount = getDocsFromTermRange(field, maxDoc, terms.intersect(new CompiledAutomaton(Automata.makeBinaryInterval(minTerm, true, maxTerm, false), true, false, Integer.MAX_VALUE, true), null), intersectDocs, minTerm, maxTerm, true); if (intersectTermCount > normalTermCount) { throw new RuntimeException("intersect returned too many terms: field=" + field + " intersectTermCount=" + intersectTermCount + " normalTermCount=" + normalTermCount); } if (normalDocs.equals(intersectDocs) == false) { throw new RuntimeException("intersect visited different docs than straight terms enum: " + normalDocs.cardinality() + " for straight enum, vs " + intersectDocs.cardinality() + " for intersect, minTerm=" + minTerm + " maxTerm=" + maxTerm); } //System.out.println(" docs=" + normalTermCount); //System.out.println(" " + intersectTermCount + " vs " + normalTermCount); return intersectTermCount != normalTermCount; }
@Override public TermsEnum intersect(CompiledAutomaton compiled, final BytesRef startTerm) throws IOException { return delegateTerms.intersect(compiled, startTerm); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new ExitableTermsEnum(in.intersect(compiled, startTerm), queryTimeout); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new ExitableTermsEnum(in.intersect(compiled, startTerm), queryTimeout); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new ExitableTermsEnum(in.intersect(compiled, startTerm), queryTimeout); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { final List<MultiTermsEnum.TermsEnumIndex> termsEnums = new ArrayList<>(); for(int i=0;i<subs.length;i++) { final TermsEnum termsEnum = subs[i].intersect(compiled, startTerm); if (termsEnum != null) { termsEnums.add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i)); } } if (termsEnums.size() > 0) { return new MultiTermsEnum(subSlices).reset(termsEnums.toArray(MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY)); } else { return TermsEnum.EMPTY; } }
@Override public TermsEnum intersect(CompiledAutomaton automaton, BytesRef bytes) throws IOException { TermsEnum termsEnum = in.intersect(automaton, bytes); thrower.maybeThrow(Flags.Intersect); return new ThrowingTermsEnum(termsEnum, thrower); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { final List<MultiTermsEnum.TermsEnumIndex> termsEnums = new ArrayList<>(); for(int i=0;i<subs.length;i++) { final TermsEnum termsEnum = subs[i].intersect(compiled, startTerm); if (termsEnum != null) { termsEnums.add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i)); } } if (termsEnums.size() > 0) { return new MultiTermsEnum(subSlices).reset(termsEnums.toArray(MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY)); } else { return TermsEnum.EMPTY; } }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { final List<MultiTermsEnum.TermsEnumIndex> termsEnums = new ArrayList<>(); for(int i=0;i<subs.length;i++) { final TermsEnum termsEnum = subs[i].intersect(compiled, startTerm); if (termsEnum != null) { termsEnums.add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i)); } } if (termsEnums.size() > 0) { return new MultiTermsEnum(subSlices).reset(termsEnums.toArray(MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY)); } else { return TermsEnum.EMPTY; } }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new SortingTermsEnum(in.intersect(compiled, startTerm), docMap, indexOptions, hasPositions()); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new SortingTermsEnum(in.intersect(compiled, startTerm), docMap, indexOptions, hasPositions()); }
@Override public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException { return new SortingTermsEnum(in.intersect(compiled, startTerm), docMap, indexOptions, hasPositions()); }
/** * return an automata-based enum for matching up to editDistance from * lastTerm, if possible */ protected TermsEnum getAutomatonEnum(int editDistance, BytesRef lastTerm) throws IOException { final List<CompiledAutomaton> runAutomata = initAutomata(editDistance); if (editDistance < runAutomata.size()) { //System.out.println("FuzzyTE.getAEnum: ed=" + editDistance + " lastTerm=" + (lastTerm==null ? "null" : lastTerm.utf8ToString())); final CompiledAutomaton compiled = runAutomata.get(editDistance); return new AutomatonFuzzyTermsEnum(terms.intersect(compiled, lastTerm == null ? null : compiled.floor(lastTerm, new BytesRefBuilder())), runAutomata.subList(0, editDistance + 1).toArray(new CompiledAutomaton[editDistance + 1])); } else { return null; } }
/** Return a {@link TermsEnum} intersecting the provided {@link Terms} * with the terms accepted by this automaton. */ public TermsEnum getTermsEnum(Terms terms) throws IOException { switch(type) { case NONE: return TermsEnum.EMPTY; case ALL: return terms.iterator(); case SINGLE: return new SingleTermsEnum(terms.iterator(), term); case NORMAL: return terms.intersect(this, null); default: // unreachable throw new RuntimeException("unhandled case"); } }
/** Return a {@link TermsEnum} intersecting the provided {@link Terms} * with the terms accepted by this automaton. */ public TermsEnum getTermsEnum(Terms terms) throws IOException { switch(type) { case NONE: return TermsEnum.EMPTY; case ALL: return terms.iterator(); case SINGLE: return new SingleTermsEnum(terms.iterator(), term); case NORMAL: return terms.intersect(this, null); default: // unreachable throw new RuntimeException("unhandled case"); } }