Search in sources :

Example 16 with MatchNoDocsQuery

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

the class TestSolrCoreParser method testGoodbye.

public void testGoodbye() throws IOException, ParserException {
    final Query query = parseXmlString("<GoodbyeQuery/>");
    assertTrue(query instanceof MatchNoDocsQuery);
}
Also used : Query(org.apache.lucene.search.Query) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) SpanBoostQuery(org.apache.lucene.search.spans.SpanBoostQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery)

Example 17 with MatchNoDocsQuery

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

the class SimpleTermRewriteQuery method rewrite.

@Override
public Query rewrite(IndexReader reader) throws IOException {
    final List<Query> luceneSubQueries = new ArrayList<>();
    srndQuery.visitMatchingTerms(reader, fieldName, new SimpleTerm.MatchingTermVisitor() {

        @Override
        public void visitMatchingTerm(Term term) throws IOException {
            luceneSubQueries.add(qf.newTermQuery(term));
        }
    });
    return (luceneSubQueries.size() == 0) ? new MatchNoDocsQuery() : (luceneSubQueries.size() == 1) ? luceneSubQueries.get(0) : SrndBooleanQuery.makeBooleanQuery(/* luceneSubQueries all have default weight */
    luceneSubQueries, BooleanClause.Occur.SHOULD);
/* OR the subquery terms */
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) IOException(java.io.IOException)

Example 18 with MatchNoDocsQuery

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

the class LatLonPoint method newBoxQuery.

// static methods for generating queries
/**
   * Create a query for matching a bounding box.
   * <p>
   * The box may cross over the dateline.
   * @param field field name. must not be null.
   * @param minLatitude latitude lower bound: must be within standard +/-90 coordinate bounds.
   * @param maxLatitude latitude upper bound: must be within standard +/-90 coordinate bounds.
   * @param minLongitude longitude lower bound: must be within standard +/-180 coordinate bounds.
   * @param maxLongitude longitude upper bound: must be within standard +/-180 coordinate bounds.
   * @return query matching points within this box
   * @throws IllegalArgumentException if {@code field} is null, or the box has invalid coordinates.
   */
public static Query newBoxQuery(String field, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) {
    // and should not drag in extra bogus junk! TODO: should encodeCeil just throw ArithmeticException to be less trappy here?
    if (minLatitude == 90.0) {
        // range cannot match as 90.0 can never exist
        return new MatchNoDocsQuery("LatLonPoint.newBoxQuery with minLatitude=90.0");
    }
    if (minLongitude == 180.0) {
        if (maxLongitude == 180.0) {
            // range cannot match as 180.0 can never exist
            return new MatchNoDocsQuery("LatLonPoint.newBoxQuery with minLongitude=maxLongitude=180.0");
        } else if (maxLongitude < minLongitude) {
            // encodeCeil() with dateline wrapping!
            minLongitude = -180.0;
        }
    }
    byte[] lower = encodeCeil(minLatitude, minLongitude);
    byte[] upper = encode(maxLatitude, maxLongitude);
    // Crosses date line: we just rewrite into OR of two bboxes, with longitude as an open range:
    if (maxLongitude < minLongitude) {
        // Disable coord here because a multi-valued doc could match both rects and get unfairly boosted:
        BooleanQuery.Builder q = new BooleanQuery.Builder();
        // E.g.: maxLon = -179, minLon = 179
        byte[] leftOpen = lower.clone();
        // leave longitude open
        NumericUtils.intToSortableBytes(Integer.MIN_VALUE, leftOpen, Integer.BYTES);
        Query left = newBoxInternal(field, leftOpen, upper);
        q.add(new BooleanClause(left, BooleanClause.Occur.SHOULD));
        byte[] rightOpen = upper.clone();
        // leave longitude open
        NumericUtils.intToSortableBytes(Integer.MAX_VALUE, rightOpen, Integer.BYTES);
        Query right = newBoxInternal(field, lower, rightOpen);
        q.add(new BooleanClause(right, BooleanClause.Occur.SHOULD));
        return new ConstantScoreQuery(q.build());
    } else {
        return newBoxInternal(field, lower, upper);
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery)

Example 19 with MatchNoDocsQuery

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

the class BaseGeoPointTestCase method testEquals.

public void testEquals() throws Exception {
    Query q1, q2;
    Rectangle rect = nextBox();
    q1 = newRectQuery("field", rect.minLat, rect.maxLat, rect.minLon, rect.maxLon);
    q2 = newRectQuery("field", rect.minLat, rect.maxLat, rect.minLon, rect.maxLon);
    assertEquals(q1, q2);
    // changing the field is unrelated to that.
    if (q1 instanceof MatchNoDocsQuery == false) {
        assertFalse(q1.equals(newRectQuery("field2", rect.minLat, rect.maxLat, rect.minLon, rect.maxLon)));
    }
    double lat = nextLatitude();
    double lon = nextLongitude();
    q1 = newDistanceQuery("field", lat, lon, 10000.0);
    q2 = newDistanceQuery("field", lat, lon, 10000.0);
    assertEquals(q1, q2);
    assertFalse(q1.equals(newDistanceQuery("field2", lat, lon, 10000.0)));
    double[] lats = new double[5];
    double[] lons = new double[5];
    lats[0] = rect.minLat;
    lons[0] = rect.minLon;
    lats[1] = rect.maxLat;
    lons[1] = rect.minLon;
    lats[2] = rect.maxLat;
    lons[2] = rect.maxLon;
    lats[3] = rect.minLat;
    lons[3] = rect.maxLon;
    lats[4] = rect.minLat;
    lons[4] = rect.minLon;
    if (supportsPolygons()) {
        q1 = newPolygonQuery("field", new Polygon(lats, lons));
        q2 = newPolygonQuery("field", new Polygon(lats, lons));
        assertEquals(q1, q2);
        assertFalse(q1.equals(newPolygonQuery("field2", new Polygon(lats, lons))));
    }
}
Also used : Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery)

Example 20 with MatchNoDocsQuery

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

the class TestUnifiedHighlighterStrictPhrases method testMatchNoDocsQuery.

public void testMatchNoDocsQuery() throws IOException {
    highlighter = new UnifiedHighlighter(null, indexAnalyzer);
    highlighter.setHighlightPhrasesStrictly(true);
    String content = "whatever";
    Object o = highlighter.highlightWithoutSearcher("body", new MatchNoDocsQuery(), content, 1);
    assertEquals(content, o);
}
Also used : MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery)

Aggregations

MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)42 Query (org.apache.lucene.search.Query)25 BooleanQuery (org.apache.lucene.search.BooleanQuery)14 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 TermQuery (org.apache.lucene.search.TermQuery)11 Term (org.apache.lucene.index.Term)9 ArrayList (java.util.ArrayList)7 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)7 Directory (org.apache.lucene.store.Directory)7 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)7 Document (org.apache.lucene.document.Document)6 IndexSearcher (org.apache.lucene.search.IndexSearcher)6 IndexReader (org.apache.lucene.index.IndexReader)5 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)5 List (java.util.List)4 DirectoryReader (org.apache.lucene.index.DirectoryReader)4 BytesRef (org.apache.lucene.util.BytesRef)4 LongPoint (org.apache.lucene.document.LongPoint)3 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)3