public object ComputeFieldValue(Sitecore.ContentSearch.IIndexable indexable) { var indexableItem = indexable as SitecoreIndexableItem; if (indexableItem == null) return null; var item = (Sitecore.Data.Items.Item)indexableItem; if (item == null) return null; var latLon = item[SourceFieldName]; if (latLon == "" || latLon == "NULL") return null; // Convert from georss point to normal X, Y format latLon = latLon.Replace(" ", ", "); var spatialContext = SpatialContext.GEO; var geohashTree = new GeohashPrefixTree(spatialContext, 10); var strategy = new RecursivePrefixTreeStrategy(geohashTree, FieldName); var shape = spatialContext.ReadShape(latLon); var grid = strategy.GetGrid(); int levelForDistance = grid.GetLevelForDistance(strategy.DistErrPct); IList<Node> list = grid.GetNodes(shape, levelForDistance, true); return list.Select(node => node.GetTokenString()); }
public void CreateSpatialFilterAndWeight(PointRadiusCriterion geoFilter, Filter currentFilter, Weight currentWeight) { var spatialContext = SpatialContext.GEO; var geohashTree = new GeohashPrefixTree(spatialContext, 10); var strategy = new RecursivePrefixTreeStrategy(geohashTree, geoFilter.FieldName); var point = spatialContext.MakePoint(geoFilter.Longitude, geoFilter.Latitude); var spatialArgs = new SpatialArgs(SpatialOperation.Intersects, spatialContext.MakeCircle(point, DistanceUtils.Dist2Degrees(geoFilter.RadiusKm, DistanceUtils.EARTH_MEAN_RADIUS_KM))); var circle = spatialContext.MakeCircle(point, DistanceUtils.Dist2Degrees(geoFilter.RadiusKm, DistanceUtils.EARTH_MEAN_RADIUS_KM)); var circleCells = strategy.GetGrid().GetWorldNode().GetSubCells(circle); var luceneFilters = new List<Filter>(); if (currentFilter != null) luceneFilters.Add(currentFilter); var tempSpatial = strategy.MakeFilter(spatialArgs); luceneFilters.Add(tempSpatial); if (geoFilter.Sort != PointRadiusCriterion.SortOption.None) { var valueSource = strategy.MakeDistanceValueSource(point); var funcQ = new FunctionQuery(valueSource); // this is a bit odd... but boosting the score negatively orders results if (geoFilter.Sort == PointRadiusCriterion.SortOption.Ascending) { funcQ.Boost = -1; } spatialWeight = funcQ.CreateWeight(this); spatialWeight.GetSumOfSquaredWeights(); luceneFilters.Add(new QueryWrapperFilter(currentWeight.Query)); } spatialFilter = new ChainedFilter(luceneFilters.ToArray(), 1); }
public IEnumerable<Param> ParamsProvider() { var ctorArgs = new List<Param>(); SpatialContext ctx = SpatialContext.GEO; SpatialPrefixTree grid = new GeohashPrefixTree(ctx, 12); SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash"); ctorArgs.Add(new Param(strategy)); grid = new QuadPrefixTree(ctx, 25); strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad"); ctorArgs.Add(new Param(strategy)); grid = new GeohashPrefixTree(ctx, 12); strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash"); ctorArgs.Add(new Param(strategy)); strategy = new PointVectorStrategy(ctx, "pointvector"); ctorArgs.Add(new Param(strategy)); return ctorArgs; }
//@ParametersFactory public static IList<Object[]> Parameters() { List<Object[]> ctorArgs = new List<object[]>(); SpatialContext ctx = SpatialContext.GEO; SpatialPrefixTree grid; SpatialStrategy strategy; grid = new QuadPrefixTree(ctx, 25); strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad"); ctorArgs.Add(new Object[] { new Param(strategy) }); grid = new GeohashPrefixTree(ctx, 12); strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash"); ctorArgs.Add(new Object[] { new Param(strategy) }); strategy = new PointVectorStrategy(ctx, "pointvector"); ctorArgs.Add(new Object[] { new Param(strategy) }); strategy = new SerializedDVStrategy(ctx, "serialized"); ctorArgs.Add(new Object[] { new Param(strategy) }); return ctorArgs; }