use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.
the class AbstractSpatialFieldType method getRangeQuery.
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
if (!minInclusive || !maxInclusive)
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Both sides of spatial range query must be inclusive: " + field.getName());
Point p1 = SpatialUtils.parsePointSolrException(part1, ctx);
Point p2 = SpatialUtils.parsePointSolrException(part2, ctx);
Rectangle bbox = ctx.makeRectangle(p1, p2);
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, bbox);
//won't score by default
return getQueryFromSpatialArgs(parser, field, spatialArgs);
}
use of org.apache.lucene.spatial.query.SpatialArgs in project lucene-solr by apache.
the class DateRangeField method getRangeQuery.
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String startStr, String endStr, boolean minInclusive, boolean maxInclusive) {
if (parser == null) {
//null when invoked by SimpleFacets. But getQueryFromSpatialArgs expects to get localParams.
final SolrRequestInfo requestInfo = SolrRequestInfo.getRequestInfo();
parser = new QParser("", null, requestInfo.getReq().getParams(), requestInfo.getReq()) {
@Override
public Query parse() throws SyntaxError {
throw new IllegalStateException();
}
};
}
Calendar startCal;
if (startStr == null) {
startCal = tree.newCal();
} else {
startCal = parseCalendar(startStr);
if (!minInclusive) {
startCal.add(Calendar.MILLISECOND, 1);
}
}
Calendar endCal;
if (endStr == null) {
endCal = tree.newCal();
} else {
endCal = parseCalendar(endStr);
if (!maxInclusive) {
endCal.add(Calendar.MILLISECOND, -1);
}
}
Shape shape = tree.toRangeShape(tree.toShape(startCal), tree.toShape(endCal));
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.Intersects, shape);
return getQueryFromSpatialArgs(parser, field, spatialArgs);
}
use of org.apache.lucene.spatial.query.SpatialArgs in project ddf by codice.
the class GeoNamesQueryLuceneIndex method createSpatialQuery.
private Query createSpatialQuery(Point shapeCenter, int radiusInKm) {
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
final SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
// Create a spatial filter that will select the documents that are in the specified
// search radius around the metacard's center.
final double searchRadiusDegrees = radiusInKm * DistanceUtils.KM_TO_DEG;
final SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, SPATIAL_CONTEXT.getShapeFactory().circle(shapeCenter, searchRadiusDegrees));
return strategy.makeQuery(args);
}
use of org.apache.lucene.spatial.query.SpatialArgs in project janusgraph by JanusGraph.
the class LuceneExample method example1.
@Test
public void example1() throws Exception {
Directory dir = FSDirectory.open(path.toPath());
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(dir, iwc);
indexDocs(writer, "doc1", ImmutableMap.of("name", "The laborious work of John Doe as we know it", "city", "Blumenkamp", "location", Geoshape.point(51.687882, 6.612053), "time", 1000342034));
indexDocs(writer, "doc2", ImmutableMap.of("name", "Life as we know it or not", "city", "Essen", "location", Geoshape.point(51.787882, 6.712053), "time", 1000342034 - 500));
indexDocs(writer, "doc3", ImmutableMap.of("name", "Berlin - poor but sexy and a display of the extraordinary", "city", "Berlin", "location", Geoshape.circle(52.509535, 13.425293, 50), "time", 1000342034 + 2000));
writer.close();
// Search
IndexReader reader = DirectoryReader.open(FSDirectory.open(path.toPath()));
IndexSearcher searcher = new IndexSearcher(reader);
// Auesee
BooleanQuery.Builder filter = new BooleanQuery.Builder();
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, Geoshape.circle(51.666167, 6.58905, 450).getShape());
filter.add(LongPoint.newRangeQuery("time", 1000342034, 1000342034), BooleanClause.Occur.MUST);
filter.add(new PrefixQuery(new Term("city_str", "B")), BooleanClause.Occur.MUST);
BooleanQuery.Builder qb = new BooleanQuery.Builder();
qb.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD);
qb.add(filter.build(), BooleanClause.Occur.FILTER);
TopDocs docs = searcher.search(qb.build(), MAX_RESULT);
if (docs.totalHits.value >= MAX_RESULT)
throw new RuntimeException("Max results exceeded: " + MAX_RESULT);
Set<String> result = getResults(searcher, docs);
System.out.println(result);
}
Aggregations