Search in sources :

Example 26 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestStandardQP method testEscapedWildcard.

@Override
public void testEscapedWildcard() throws Exception {
    CommonQueryParserConfiguration qp = getParserConfig(new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false));
    //TODO not correct!!
    WildcardQuery q = new WildcardQuery(new Term("field", "foo?ba?r"));
    assertEquals(q, getQuery("foo\\?ba?r", qp));
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) Term(org.apache.lucene.index.Term)

Example 27 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestBlockJoinValidation method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    directory = newDirectory();
    final IndexWriterConfig config = new IndexWriterConfig(new MockAnalyzer(random()));
    final IndexWriter indexWriter = new IndexWriter(directory, config);
    for (int i = 0; i < AMOUNT_OF_SEGMENTS; i++) {
        List<Document> segmentDocs = createDocsForSegment(i);
        indexWriter.addDocuments(segmentDocs);
        indexWriter.commit();
    }
    indexReader = DirectoryReader.open(indexWriter);
    indexWriter.close();
    indexSearcher = new IndexSearcher(indexReader);
    parentsFilter = new QueryBitSetProducer(new WildcardQuery(new Term("parent", "*")));
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) WildcardQuery(org.apache.lucene.search.WildcardQuery) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 28 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class FieldQueryTest method testHighlightQuery.

public void testHighlightQuery() throws Exception {
    makeIndexStrMV();
    defgMultiTermQueryTest(new WildcardQuery(new Term(F, "d*g")));
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 29 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestPayloadCheckQuery method testRewrite.

public void testRewrite() throws IOException {
    SpanMultiTermQueryWrapper fiv = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "fiv*")));
    SpanMultiTermQueryWrapper hund = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "hund*")));
    SpanMultiTermQueryWrapper twent = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "twent*")));
    SpanMultiTermQueryWrapper nin = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "nin*")));
    SpanNearQuery sq = new SpanNearQuery(new SpanQuery[] { fiv, hund, twent, nin }, 0, true);
    List<BytesRef> payloads = new ArrayList<>();
    payloads.add(new BytesRef("pos: 0"));
    payloads.add(new BytesRef("pos: 1"));
    payloads.add(new BytesRef("pos: 2"));
    payloads.add(new BytesRef("pos: 3"));
    SpanPayloadCheckQuery query = new SpanPayloadCheckQuery(sq, payloads);
    // if query wasn't rewritten properly, the query would have failed with "Rewrite first!"
    checkHits(query, new int[] { 529 });
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) BytesRef(org.apache.lucene.util.BytesRef)

Example 30 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project elasticsearch by elastic.

the class WildcardQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    MappedFieldType fieldType = context.fieldMapper(fieldName);
    Term term;
    if (fieldType == null) {
        term = new Term(fieldName, BytesRefs.toBytesRef(value));
    } else {
        Query termQuery = fieldType.termQuery(value, context);
        term = MappedFieldType.extractTerm(termQuery);
    }
    WildcardQuery query = new WildcardQuery(term);
    MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(rewrite, null);
    QueryParsers.setRewriteMethod(query, rewriteMethod);
    return query;
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) WildcardQuery(org.apache.lucene.search.WildcardQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Term(org.apache.lucene.index.Term)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)69 Term (org.apache.lucene.index.Term)61 BooleanQuery (org.apache.lucene.search.BooleanQuery)28 PrefixQuery (org.apache.lucene.search.PrefixQuery)24 Query (org.apache.lucene.search.Query)21 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)20 TermQuery (org.apache.lucene.search.TermQuery)18 Document (org.apache.lucene.document.Document)17 BoostQuery (org.apache.lucene.search.BoostQuery)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)15 RegexpQuery (org.apache.lucene.search.RegexpQuery)15 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)14 Field (org.apache.lucene.document.Field)13 IndexReader (org.apache.lucene.index.IndexReader)13 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)13 PhraseQuery (org.apache.lucene.search.PhraseQuery)13 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13