public NodeQuery build(final QueryNode queryNode) throws QueryNodeException { final RegexpQueryNode regexpNode = (RegexpQueryNode) queryNode; final NodeRegexpQuery q = new NodeRegexpQuery(new Term(regexpNode.getFieldAsString(), regexpNode.textToBytesRef())); final MultiNodeTermQuery.RewriteMethod method = (MultiNodeTermQuery.RewriteMethod) queryNode .getTag(MultiNodeTermRewriteMethodProcessor.TAG_ID); if (method != null) { q.setRewriteMethod(method); } return q; }
@Test public void testRegexQueries() throws Exception { final Query reg = new LuceneProxyNodeQuery( new NodeRegexpQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "s*e")) ); this._assertSirenQuery(reg, "/s*e/"); }
private int regexQueryNrHits(final String regex) throws IOException { final NodeRegexpQuery query = new NodeRegexpQuery(this.newTerm(regex)); return searcher.search(dq(query), 5).totalHits; }
final NodeRegexpQuery q = new NodeRegexpQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "[a-z][123]")); this._assertSirenQuery(config, q, "/[a-z][123]/"); config.put(ConfigurationKeys.LOWERCASE_EXPANDED_TERMS, true); final Query escaped = new NodeRegexpQuery(new Term(df, "[a-z]\\/[123]")); this._assertSirenQuery(config, escaped, "/[a-z]\\/[123]/"); final Query escaped2 = new NodeRegexpQuery(new Term(df, "[a-z]\\*[123]")); this._assertSirenQuery(config, escaped2, "/[a-z]\\*[123]/"); config.put(KeywordConfigurationKeys.DATATYPES_ANALYZERS, dtAnalyzers); final NodeBooleanQuery complex = new NodeBooleanQuery(); complex.add(new NodeRegexpQuery(new Term(df, "[a-z]\\/[123]")), NodeBooleanClause.Occur.MUST); complex.add(new NodeTermQuery(new Term(df, "/etc/init.d/")), Occur.MUST); complex.add(new NodeTermQuery(new Term(df, "/etc/init[.]d/lucene/")), Occur.SHOULD); this._assertSirenQuery(config, complex, "+/[a-z]\\/[123]/ +\"/etc/init.d/\" OR \"/etc\\/init\\[.\\]d/lucene/\" "); Query re = new NodeRegexpQuery(new Term(df, "http.*")); this._assertSirenQuery(config, re, "/http.*/"); re = new NodeRegexpQuery(new Term(df, "http~0.5")); this._assertSirenQuery(config, re, "/http~0.5/"); re = new NodeRegexpQuery(new Term(df, "boo")); this._assertSirenQuery(config, re, "/boo/"); two.add(new NodeRegexpQuery(new Term(df, "foo")), Occur.SHOULD); two.add(new NodeRegexpQuery(new Term(df, "bar")), Occur.SHOULD); this._assertSirenQuery(config, two, "/foo/ /bar/");
public void testCustomProvider() throws IOException { final AutomatonProvider myProvider = new AutomatonProvider() { // automaton that matches quick or brown private final Automaton quickBrownAutomaton = BasicOperations.union(Arrays .asList(BasicAutomata.makeString("quick"), BasicAutomata.makeString("brown"), BasicAutomata.makeString("bob"))); public Automaton getAutomaton(final String name) { if (name.equals("quickBrown")) return quickBrownAutomaton; else return null; } }; final NodeRegexpQuery query = new NodeRegexpQuery(this.newTerm("<quickBrown>"), RegExp.ALL, myProvider); assertEquals(1, searcher.search(dq(query), 5).totalHits); }