/** Constructs a query for terms starting with <code>prefix</code>. */ public PrefixQuery(Term prefix) { // It's OK to pass unlimited maxDeterminizedStates: the automaton is born small and determinized: super(prefix, toAutomaton(prefix.bytes()), Integer.MAX_VALUE, true); if (prefix == null) { throw new NullPointerException("prefix must not be null"); } }
/** {@inheritDoc} */ @Override public TermsEnum getTermsEnumForSuggestions(final Terms terms) { if (terms == null) { return TermsEnum.EMPTY; } BytesRef prefix = getPrefix(); if (prefix != null) { Automaton prefixAutomaton = PrefixQuery.toAutomaton(prefix); Automaton finalAutomaton; if (suggestPosition == SuggestPosition.LOWER) { Automaton binaryInt = Automata.makeBinaryInterval( getLowerTerm(), includesLower(), getUpperTerm(), includesUpper()); finalAutomaton = Operations.intersection(binaryInt, prefixAutomaton); } else { Automaton binaryInt = Automata.makeBinaryInterval(null, true, getLowerTerm(), !includesLower()); finalAutomaton = Operations.minus(prefixAutomaton, binaryInt, Integer.MIN_VALUE); } CompiledAutomaton compiledAutomaton = new CompiledAutomaton(finalAutomaton); try { return compiledAutomaton.getTermsEnum(terms); } catch (IOException e) { logger.log(Level.WARNING, "Could not compile automaton for range suggestions", e); } } return TermsEnum.EMPTY; }
/** Constructs a query for terms starting with <code>prefix</code>. */ public PrefixQuery(Term prefix) { // It's OK to pass unlimited maxDeterminizedStates: the automaton is born small and determinized: super(prefix, toAutomaton(prefix.bytes()), Integer.MAX_VALUE, true); if (prefix == null) { throw new NullPointerException("prefix must not be null"); } }
/** Constructs a query for terms starting with <code>prefix</code>. */ public PrefixQuery(Term prefix) { // It's OK to pass unlimited maxDeterminizedStates: the automaton is born small and determinized: super(prefix, toAutomaton(prefix.bytes()), Integer.MAX_VALUE, true); if (prefix == null) { throw new NullPointerException("prefix cannot be null"); } }
/** Constructs a query for terms starting with <code>prefix</code>. */ public PrefixQuery(Term prefix) { // It's OK to pass unlimited maxDeterminizedStates: the automaton is born small and determinized: super(prefix, toAutomaton(prefix.bytes()), Integer.MAX_VALUE, true); if (prefix == null) { throw new NullPointerException("prefix cannot be null"); } }
/** * Loads all the prefix terms in the list of terms given the reader. * * @param reader Index reader to use. * @param values The list of values to load. * @param term The term to use. * * @throws IOException If an error is thrown by the prefix term enumeration. */ public static void prefix(IndexReader reader, List<String> values, Term term) throws IOException { Fields fields = MultiFields.getFields(reader); org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field()); if (terms == null) return; TermsEnum prefixes = terms.intersect(new CompiledAutomaton(PrefixQuery.toAutomaton(term.bytes())), term.bytes()); BytesRef val; while ((val = prefixes.next()) != null) { values.add(val.utf8ToString()); } }
/** * Loads all the prefix terms in the list of terms given the reader. * * @param reader Index reader to use. * @param values The list of values to load. * @param term The term to use. * * @throws IOException If an error is thrown by the prefix term enumeration. */ public static void prefix(IndexReader reader, Bucket<Term> bucket, Term term) throws IOException { Fields fields = MultiFields.getFields(reader); org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field()); if (terms == null) return; TermsEnum prefixes = terms.intersect(new CompiledAutomaton(PrefixQuery.toAutomaton(term.bytes())), term.bytes()); BytesRef val; while ((val = prefixes.next()) != null) { Term t = new Term(term.field(), BytesRef.deepCopyOf(val)); bucket.add(t, reader.docFreq(t)); } }