Search in sources :

Example 11 with IntervalQuery

use of org.apache.lucene.queries.intervals.IntervalQuery in project OpenSearch by opensearch-project.

the class IntervalQueryBuilderTests method testOrInterval.

public void testOrInterval() throws IOException {
    String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": {" + "       \"any_of\" : { " + "           \"intervals\" : [" + "               { \"match\" : { \"query\" : \"one\" } }," + "               { \"match\" : { \"query\" : \"two\" } } ] } } } }";
    IntervalQueryBuilder builder = (IntervalQueryBuilder) parseQuery(json);
    Query expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.or(Intervals.term("one"), Intervals.term("two")));
    assertEquals(expected, builder.toQuery(createShardContext()));
    json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": {" + "       \"any_of\" : { " + "           \"intervals\" : [" + "               { \"match\" : { \"query\" : \"one\" } }," + "               { \"match\" : { \"query\" : \"two\" } } ]," + "           \"filter\" : {" + "               \"not_containing\" : { \"match\" : { \"query\" : \"three\" } } } } } } }";
    builder = (IntervalQueryBuilder) parseQuery(json);
    expected = new IntervalQuery(TEXT_FIELD_NAME, Intervals.notContaining(Intervals.or(Intervals.term("one"), Intervals.term("two")), Intervals.term("three")));
    assertEquals(expected, builder.toQuery(createShardContext()));
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) IntervalQuery(org.apache.lucene.queries.intervals.IntervalQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) BoostQuery(org.apache.lucene.search.BoostQuery) IntervalQuery(org.apache.lucene.queries.intervals.IntervalQuery)

Aggregations

IntervalQuery (org.apache.lucene.queries.intervals.IntervalQuery)11 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)10 BooleanQuery (org.apache.lucene.search.BooleanQuery)9 BoostQuery (org.apache.lucene.search.BoostQuery)9 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)9 Query (org.apache.lucene.search.Query)9 BytesRef (org.apache.lucene.util.BytesRef)3 HashSet (java.util.HashSet)1 Term (org.apache.lucene.index.Term)1 IntervalsSource (org.apache.lucene.queries.intervals.IntervalsSource)1 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)1 Result (org.opensearch.percolator.QueryAnalyzer.Result)1 QueryAnalyzer.selectBestResult (org.opensearch.percolator.QueryAnalyzer.selectBestResult)1 Script (org.opensearch.script.Script)1 ScriptContext (org.opensearch.script.ScriptContext)1 ScriptService (org.opensearch.script.ScriptService)1