protected virtual Query MakeQueryFromShape(IShape shape) { SpatialArgs args = new SpatialArgs(m_operation, shape); if (!double.IsNaN(m_distErrPct)) { args.DistErrPct = m_distErrPct; } if (m_score) { ValueSource valueSource = m_strategy.MakeDistanceValueSource(shape.Center); return(new CustomScoreQuery(m_strategy.MakeQuery(args), new FunctionQuery(valueSource))); } else { //strategy.makeQuery() could potentially score (isn't well defined) so instead we call // makeFilter() and wrap Filter filter = m_strategy.MakeFilter(args); if (filter is QueryWrapperFilter queryWrapperFilter) { return(queryWrapperFilter.Query); } else { return(new ConstantScoreQuery(filter)); } } }
private void DoSpatialSearch( SpatialContext ctx, SpatialStrategy strategy, TestIndex indexer, double searchRadius, string idToMatch, Func <SpatialArgs, Query> createQuery, int lat, int lng) { var searcher = (LuceneSearcher)indexer.GetSearcher(); var luceneSearcher = searcher.GetLuceneSearcher(); GetXYFromCoords(lat, lng, out var x, out var y); // Make a circle around the search point var args = new SpatialArgs( SpatialOperation.Intersects, ctx.MakeCircle(x, y, DistanceUtils.Dist2Degrees(searchRadius, DistanceUtils.EARTH_MEAN_RADIUS_KM))); var filter = strategy.MakeFilter(args); var query = createQuery(args); // TODO: It doesn't make a whole lot of sense to sort by score when searching on only geo-coords, // typically you would sort by closest distance // Which can be done, see https://github.com/apache/lucene-solr/blob/branch_4x/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialExample.java#L169 TopDocs docs = luceneSearcher.Search(query, filter, MaxResultDocs, new Sort(new SortField(null, SortField.SCORE))); AssertDocMatchedIds(luceneSearcher, docs, idToMatch); // TODO: We should make this possible and allow passing in a Lucene Filter // to the LuceneSearchQuery along with the Lucene Query, then we // don't need to manually perform the Lucene Search //var criteria = (LuceneSearchQuery)searcher.CreateQuery(); //criteria.LuceneQuery(q); //var results = criteria.Execute(); }
public static Filter MakeFilter(SpatialStrategy spatialStrategy, IndexQuery indexQuery) { var spatialQry = indexQuery as SpatialIndexQuery; if (spatialQry == null) { return(null); } var args = new SpatialArgs(SpatialOperation.IsWithin, shapeReadWriter.ReadShape(spatialQry.QueryShape)); return(spatialStrategy.MakeFilter(args)); }
public Filter MakeFilter(SpatialStrategy spatialStrategy, IndexQuery indexQuery) { var spatialQry = indexQuery as SpatialIndexQuery; if (spatialQry == null) { return(null); } var args = new SpatialArgs(SpatialOperation.IsWithin, ReadShape(spatialQry.QueryShape, spatialQry.RadiusUnitOverride)); return(spatialStrategy.MakeFilter(args)); }
public static Filter MakeFilter(IndexQuery indexQuery) { var spatialQry = indexQuery as SpatialIndexQuery; if (spatialQry == null) { return(null); } var args = new SpatialArgs(SpatialOperation.IsWithin, RavenSpatialContext.MakeCircle(spatialQry.Longitude, spatialQry.Latitude, spatialQry.Radius)); return(strategy.MakeFilter(args, fieldInfo)); }