public void testCustomProvider() throws IOException { AutomatonProvider myProvider = new AutomatonProvider() { // automaton that matches quick or brown private Automaton quickBrownAutomaton = Operations.union(Arrays .asList(Automata.makeString("quick"), Automata.makeString("brown"), Automata.makeString("bob"))); @Override public Automaton getAutomaton(String name) { if (name.equals("quickBrown")) return quickBrownAutomaton; else return null; } }; RegexpQuery query = new RegexpQuery(newTerm("<quickBrown>"), RegExp.ALL, myProvider, DEFAULT_MAX_DETERMINIZED_STATES); assertEquals(1, searcher.search(query, 5).totalHits); }
public void testCustomProvider() throws IOException { AutomatonProvider myProvider = new AutomatonProvider() { // automaton that matches quick or brown private Automaton quickBrownAutomaton = BasicOperations.union(Arrays .asList(BasicAutomata.makeString("quick"), BasicAutomata.makeString("brown"), BasicAutomata.makeString("bob"))); @Override public Automaton getAutomaton(String name) { if (name.equals("quickBrown")) return quickBrownAutomaton; else return null; } }; RegexpQuery query = new RegexpQuery(newTerm("<quickBrown>"), RegExp.ALL, myProvider); assertEquals(1, searcher.search(query, 5).totalHits); }
/** * Constructs a query for terms matching <code>term</code>. * * @param term regular expression. * @param flags optional RegExp features from {@link RegExp} * @param provider custom AutomatonProvider for named automata * @param maxDeterminizedStates maximum number of states that compiling the * automaton for the regexp can result in. Set higher to allow more complex * queries and lower to prevent memory exhaustion. */ public RegexpQuery(Term term, int flags, AutomatonProvider provider, int maxDeterminizedStates) { super(term, new RegExp(term.text(), flags).toAutomaton( provider, maxDeterminizedStates), maxDeterminizedStates); }
/** * Constructs a query for terms matching <code>term</code>. * * @param term regular expression. * @param flags optional RegExp features from {@link RegExp} * @param provider custom AutomatonProvider for named automata */ public RegexpQuery(Term term, int flags, AutomatonProvider provider) { super(term, new RegExp(term.text(), flags).toAutomaton(provider)); }