List of usage examples for org.apache.lucene.spatial.query SpatialOperation IsWithin
SpatialOperation IsWithin
To view the source code for org.apache.lucene.spatial.query SpatialOperation IsWithin.
Click Source Link
From source file:bzh.terrevirtuelle.navisu.gazetteer.impl.lucene.GeoNameResolver.java
License:Apache License
/** * Returns a list of location near a certain coordinate. * * @param latitude, @param longitude - Center of search area * @param distanceInMiles - Search Radius in miles * @param indexerPath - Path to Lucene index * @param count - Upper bound to number of results * @return - List of locations sorted by population * @throws IOException/* w w w. java 2 s . c om*/ */ public List<Location> searchNearby(Double latitude, Double longitude, Double distanceInMiles, String indexerPath, int count) throws IOException { double distanceInDeg = DistanceUtils.dist2Degrees(distanceInMiles, DistanceUtils.EARTH_EQUATORIAL_RADIUS_MI); SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, ctx.makeCircle(longitude, latitude, distanceInDeg)); String key = latitude + "-" + longitude; Filter filter = strategy.makeFilter(spatialArgs); IndexSearcher searcher = new IndexSearcher(createIndexReader(indexerPath)); Sort sort = new Sort(populationSort); TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), filter, count, sort); ScoreDoc[] scoreDocs = topDocs.scoreDocs; HashMap<String, List<Location>> allCandidates = new HashMap<String, List<Location>>(); getMatchingCandidates(searcher, allCandidates, key, scoreDocs); List<Location> results = allCandidates.get(key); return results; }
From source file:com.orientechnologies.lucene.manager.OLuceneSpatialIndexManager.java
License:Apache License
@Override public Object get(Object key) { try {// w w w . j a v a 2 s . c o m if (key instanceof OSpatialCompositeKey) { final OSpatialCompositeKey newKey = (OSpatialCompositeKey) key; final SpatialOperation strategy = newKey.getOperation() != null ? newKey.getOperation() : SpatialOperation.Intersects; if (SpatialOperation.Intersects.equals(strategy)) return searchIntersect(newKey, newKey.getMaxDistance(), newKey.getContext()); else if (SpatialOperation.IsWithin.equals(strategy)) return searchWithin(newKey, newKey.getContext()); } else if (key instanceof OCompositeKey) return searchIntersect((OCompositeKey) key, 0, null); } catch (IOException e) { OLogManager.instance().error(this, "Error on getting entry against Lucene index", e); } return null; }
From source file:com.orientechnologies.lucene.manager.OLuceneSpatialIndexManager.java
License:Apache License
public Object searchWithin(OSpatialCompositeKey key, OCommandContext context) throws IOException { Set<OIdentifiable> result = new HashSet<OIdentifiable>(); Shape shape = factory.makeShape(key, ctx); if (shape == null) return null; SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin, shape); IndexSearcher searcher = getSearcher(); Filter filter = strategy.makeFilter(args); return new LuceneResultSet(this, new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter)); }
From source file:com.orientechnologies.lucene.operator.OLuceneWithinOperator.java
License:Apache License
@Override public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) { OIndexDefinition definition = index.getDefinition(); int idxSize = definition.getFields().size(); int paramsSize = keyParams.size(); OIndexCursor cursor;//from w w w. java 2 s . c o m Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setOperation(SpatialOperation.IsWithin)); if (indexResult == null || indexResult instanceof OIdentifiable) cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams)); else cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OSpatialCompositeKey(keyParams)); iContext.setVariable("$luceneIndex", true); return cursor; }
From source file:com.orientechnologies.spatial.engine.OLuceneLegacySpatialIndexEngine.java
License:Apache License
private Object legacySearch(Object key) throws IOException { if (key instanceof OSpatialCompositeKey) { final OSpatialCompositeKey newKey = (OSpatialCompositeKey) key; final SpatialOperation strategy = newKey.getOperation() != null ? newKey.getOperation() : SpatialOperation.Intersects; if (SpatialOperation.Intersects.equals(strategy)) return searchIntersect(newKey, newKey.getMaxDistance(), newKey.getContext()); else if (SpatialOperation.IsWithin.equals(strategy)) return searchWithin(newKey, newKey.getContext()); } else if (key instanceof OCompositeKey) { return searchIntersect((OCompositeKey) key, 0, null); }/* w w w . j a v a 2s . c o m*/ throw new OIndexEngineException("Unknown key" + key, null); }
From source file:com.orientechnologies.spatial.engine.OLuceneLegacySpatialIndexEngine.java
License:Apache License
public Object searchWithin(OSpatialCompositeKey key, OCommandContext context) throws IOException { Set<OIdentifiable> result = new HashSet<OIdentifiable>(); Shape shape = legacyBuilder.makeShape(key, ctx); if (shape == null) return null; SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin, shape); IndexSearcher searcher = searcher(); Filter filter = strategy.makeFilter(args); return new LuceneResultSet(this, new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter)); }
From source file:com.orientechnologies.spatial.operator.OLuceneWithinOperator.java
License:Apache License
@Override public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) { OIndexDefinition definition = index.getDefinition(); int idxSize = definition.getFields().size(); int paramsSize = keyParams.size(); OIndexCursor cursor;//www . j ava2 s . co m Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setOperation(SpatialOperation.IsWithin)); if (indexResult == null || indexResult instanceof OIdentifiable) cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams)); else cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult), new OSpatialCompositeKey(keyParams)); iContext.setVariable("$luceneIndex", true); return cursor; }
From source file:com.orientechnologies.spatial.strategy.SpatialQueryBuilderDWithin.java
License:Apache License
@Override public SpatialQueryContext build(Map<String, Object> query) throws Exception { Shape shape = parseShape(query); System.out.println("qui:: " + shape); SpatialStrategy strategy = manager.strategy(); if (isOnlyBB(strategy)) { shape = shape.getBoundingBox();//from ww w. jav a 2 s . co m } SpatialArgs args1 = new SpatialArgs(SpatialOperation.IsWithin, shape); // SpatialArgs args2 = new SpatialArgs(SpatialOperation., shape); Geometry geo = OShapeFactory.INSTANCE.toGeometry(shape); Filter filter = strategy.makeFilter(args1); return new SpatialQueryContext(null, manager.searcher(), new MatchAllDocsQuery(), filter); }
From source file:com.orientechnologies.spatial.strategy.SpatialQueryBuilderWithin.java
License:Apache License
@Override public SpatialQueryContext build(Map<String, Object> query) throws Exception { Shape shape = parseShape(query); SpatialStrategy strategy = manager.strategy(); if (isOnlyBB(strategy)) { shape = shape.getBoundingBox();/* www . j av a 2 s . com*/ } SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin, shape); Filter filter = strategy.makeFilter(args); return new SpatialQueryContext(null, manager.searcher(), new MatchAllDocsQuery(), filter); }
From source file:com.stratio.cassandra.lucene.search.condition.BitemporalCondition.java
License:Apache License
static SpatialOperation parseSpatialOperation(String operation) { if (operation == null) { throw new IllegalArgumentException("Operation is required"); } else if (operation.equalsIgnoreCase("contains")) { return SpatialOperation.Contains; } else if (operation.equalsIgnoreCase("intersects")) { return SpatialOperation.Intersects; } else if (operation.equalsIgnoreCase("is_within")) { return SpatialOperation.IsWithin; } else {//from w w w.j av a2s . c om throw new IllegalArgumentException("Operation is invalid: " + operation); } }