Search in sources :

Example 1 with SpanNotQuery

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

the class SpanNotQueryBuilder method doToQuery.

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    Query includeQuery = this.include.toQuery(context);
    assert includeQuery instanceof SpanQuery;
    Query excludeQuery = this.exclude.toQuery(context);
    assert excludeQuery instanceof SpanQuery;
    return new SpanNotQuery((SpanQuery) includeQuery, (SpanQuery) excludeQuery, pre, post);
}
Also used : Query(org.apache.lucene.search.Query) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery)

Example 2 with SpanNotQuery

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

the class QueryAnalyzerTests method testExtractQueryMetadata_spanNotQuery.

public void testExtractQueryMetadata_spanNotQuery() {
    SpanTermQuery spanTermQuery1 = new SpanTermQuery(new Term("_field", "_short_term"));
    SpanTermQuery spanTermQuery2 = new SpanTermQuery(new Term("_field", "_very_long_term"));
    SpanNotQuery spanNotQuery = new SpanNotQuery(spanTermQuery1, spanTermQuery2);
    Result result = analyze(spanNotQuery);
    assertThat(result.verified, is(false));
    assertTermsEqual(result.terms, spanTermQuery1.getTerm());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) QueryAnalyzer.selectTermListWithTheLongestShortestTerm(org.elasticsearch.percolator.QueryAnalyzer.selectTermListWithTheLongestShortestTerm) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery) Result(org.elasticsearch.percolator.QueryAnalyzer.Result)

Example 3 with SpanNotQuery

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

the class SpanNotQueryBuilderTests method doAssertLuceneQuery.

@Override
protected void doAssertLuceneQuery(SpanNotQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
    assertThat(query, instanceOf(SpanNotQuery.class));
    SpanNotQuery spanNotQuery = (SpanNotQuery) query;
    assertThat(spanNotQuery.getExclude(), equalTo(queryBuilder.excludeQuery().toQuery(context.getQueryShardContext())));
    assertThat(spanNotQuery.getInclude(), equalTo(queryBuilder.includeQuery().toQuery(context.getQueryShardContext())));
}
Also used : SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery)

Example 4 with SpanNotQuery

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

the class SpanNotBuilder method getSpanQuery.

@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
    Element includeElem = DOMUtils.getChildByTagOrFail(e, "Include");
    includeElem = DOMUtils.getFirstChildOrFail(includeElem);
    Element excludeElem = DOMUtils.getChildByTagOrFail(e, "Exclude");
    excludeElem = DOMUtils.getFirstChildOrFail(excludeElem);
    SpanQuery include = factory.getSpanQuery(includeElem);
    SpanQuery exclude = factory.getSpanQuery(excludeElem);
    SpanNotQuery snq = new SpanNotQuery(include, exclude);
    float boost = DOMUtils.getAttribute(e, "boost", 1.0f);
    return new SpanBoostQuery(snq, boost);
}
Also used : Element(org.w3c.dom.Element) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery)

Example 5 with SpanNotQuery

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

the class CandidateQueryTests method testDuelSpecificQueries.

public void testDuelSpecificQueries() throws Exception {
    List<ParseContext.Document> documents = new ArrayList<>();
    CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128);
    commonTermsQuery.add(new Term("field", "quick"));
    commonTermsQuery.add(new Term("field", "brown"));
    commonTermsQuery.add(new Term("field", "fox"));
    addQuery(commonTermsQuery, documents);
    BlendedTermQuery blendedTermQuery = BlendedTermQuery.booleanBlendedQuery(new Term[] { new Term("field", "quick"), new Term("field", "brown"), new Term("field", "fox") }, false);
    addQuery(blendedTermQuery, documents);
    SpanNearQuery spanNearQuery = new SpanNearQuery.Builder("field", true).addClause(new SpanTermQuery(new Term("field", "quick"))).addClause(new SpanTermQuery(new Term("field", "brown"))).addClause(new SpanTermQuery(new Term("field", "fox"))).build();
    addQuery(spanNearQuery, documents);
    SpanNearQuery spanNearQuery2 = new SpanNearQuery.Builder("field", true).addClause(new SpanTermQuery(new Term("field", "the"))).addClause(new SpanTermQuery(new Term("field", "lazy"))).addClause(new SpanTermQuery(new Term("field", "doc"))).build();
    SpanOrQuery spanOrQuery = new SpanOrQuery(spanNearQuery, spanNearQuery2);
    addQuery(spanOrQuery, documents);
    SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, spanNearQuery);
    addQuery(spanNotQuery, documents);
    long lowerLong = randomIntBetween(0, 256);
    long upperLong = lowerLong + randomIntBetween(0, 32);
    addQuery(LongPoint.newRangeQuery("long_field", lowerLong, upperLong), documents);
    indexWriter.addDocuments(documents);
    indexWriter.close();
    directoryReader = DirectoryReader.open(directory);
    IndexSearcher shardSearcher = newSearcher(directoryReader);
    // Disable query cache, because ControlQuery cannot be cached...
    shardSearcher.setQueryCache(null);
    Document document = new Document();
    document.add(new TextField("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO));
    long randomLong = randomIntBetween((int) lowerLong, (int) upperLong);
    document.add(new LongPoint("long_field", randomLong));
    MemoryIndex memoryIndex = MemoryIndex.fromDocument(document, new WhitespaceAnalyzer());
    duelRun(queryStore, memoryIndex, shardSearcher);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) WhitespaceAnalyzer(org.apache.lucene.analysis.core.WhitespaceAnalyzer) ArrayList(java.util.ArrayList) BlendedTermQuery(org.apache.lucene.queries.BlendedTermQuery) Term(org.apache.lucene.index.Term) LongPoint(org.apache.lucene.document.LongPoint) Document(org.apache.lucene.document.Document) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) CommonTermsQuery(org.apache.lucene.queries.CommonTermsQuery) SpanNotQuery(org.apache.lucene.search.spans.SpanNotQuery) MemoryIndex(org.apache.lucene.index.memory.MemoryIndex) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TextField(org.apache.lucene.document.TextField) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery)

Aggregations

SpanNotQuery (org.apache.lucene.search.spans.SpanNotQuery)10 Term (org.apache.lucene.index.Term)7 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)6 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)6 SpanQuery (org.apache.lucene.search.spans.SpanQuery)5 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)4 Document (org.apache.lucene.document.Document)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 Query (org.apache.lucene.search.Query)3 SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)3 ArrayList (java.util.ArrayList)2 IndexReader (org.apache.lucene.index.IndexReader)2 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)2 BoostQuery (org.apache.lucene.search.BoostQuery)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 DisjunctionMaxQuery (org.apache.lucene.search.DisjunctionMaxQuery)2 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)2 PrefixQuery (org.apache.lucene.search.PrefixQuery)2 RegexpQuery (org.apache.lucene.search.RegexpQuery)2