use of org.apache.lucene.search.RegexpQuery in project lucene-solr by apache.
the class RegexpQueryNodeBuilder method build.
@Override
public RegexpQuery build(QueryNode queryNode) throws QueryNodeException {
RegexpQueryNode regexpNode = (RegexpQueryNode) queryNode;
// TODO: make the maxStates configurable w/ a reasonable default (QueryParserBase uses 10000)
RegexpQuery q = new RegexpQuery(new Term(regexpNode.getFieldAsString(), regexpNode.textToBytesRef()));
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
q.setRewriteMethod(method);
}
return q;
}
use of org.apache.lucene.search.RegexpQuery in project lucene-solr by apache.
the class SynonymTokenizer method testRegexQuery.
public void testRegexQuery() throws Exception {
query = new RegexpQuery(new Term(FIELD_NAME, "ken.*"));
searcher = newSearcher(reader);
hits = searcher.search(query, 100);
int maxNumFragmentsRequired = 2;
QueryScorer scorer = new QueryScorer(query, FIELD_NAME);
Highlighter highlighter = new Highlighter(this, scorer);
for (int i = 0; i < hits.totalHits; i++) {
final int docId = hits.scoreDocs[i].doc;
final Document doc = searcher.doc(docId);
String text = doc.get(FIELD_NAME);
TokenStream tokenStream = getAnyTokenStream(FIELD_NAME, docId);
highlighter.setTextFragmenter(new SimpleFragmenter(40));
String result = highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired, "...");
if (VERBOSE)
System.out.println("\t" + result);
}
assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 5);
}
use of org.apache.lucene.search.RegexpQuery in project lucene-solr by apache.
the class TestMemoryIndexAgainstRAMDir method testPassesIfWrapped.
// LUCENE-3831
public void testPassesIfWrapped() throws IOException {
RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
SpanQuery wrappedquery = new SpanOrQuery(new SpanMultiTermQueryWrapper<>(regex));
MemoryIndex mindex = randomMemoryIndex();
mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));
// This passes though
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
TestUtil.checkReader(mindex.createSearcher().getIndexReader());
}
use of org.apache.lucene.search.RegexpQuery in project lucene-solr by apache.
the class SolrQueryParserBase method newRegexpQuery.
/**
* Builds a new RegexpQuery instance
* @param regexp Regexp term
* @return new RegexpQuery instance
*/
protected Query newRegexpQuery(Term regexp) {
RegexpQuery query = new RegexpQuery(regexp);
SchemaField sf = schema.getField(regexp.field());
query.setRewriteMethod(sf.getType().getRewriteMethod(parser, sf));
return query;
}
use of org.apache.lucene.search.RegexpQuery in project lucene-solr by apache.
the class FieldQueryTest method testRegexpQuery.
public void testRegexpQuery() throws Exception {
makeIndexStrMV();
Term term = new Term(F, "d[a-z].g");
defgMultiTermQueryTest(new RegexpQuery(term));
}
Aggregations