Search in sources :

Example 21 with RegexpQuery

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;
}
Also used : MultiTermQuery(org.apache.lucene.search.MultiTermQuery) RegexpQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode) Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 22 with RegexpQuery

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);
}
Also used : CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) IntPoint(org.apache.lucene.document.IntPoint) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 23 with RegexpQuery

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());
}
Also used : MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 24 with RegexpQuery

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;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 25 with RegexpQuery

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));
}
Also used : Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Aggregations

RegexpQuery (org.apache.lucene.search.RegexpQuery)35 Term (org.apache.lucene.index.Term)30 PrefixQuery (org.apache.lucene.search.PrefixQuery)9 WildcardQuery (org.apache.lucene.search.WildcardQuery)9 BooleanQuery (org.apache.lucene.search.BooleanQuery)8 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)8 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)8 Test (org.junit.Test)7 KrillIndex (de.ids_mannheim.korap.KrillIndex)6 Query (org.apache.lucene.search.Query)6 TermQuery (org.apache.lucene.search.TermQuery)6 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)5 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)5 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)4 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)4 Document (org.apache.lucene.document.Document)4 IntPoint (org.apache.lucene.document.IntPoint)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)4 SpanQuery (org.apache.lucene.search.spans.SpanQuery)4