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);
}
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 */
}
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);
}
}
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))));
}
}
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);
}
Aggregations