The SpatialStrategy encapsulates an approach to indexing and searching based on shapes. Different implementations will support different features. A strategy should document these common elements: Can it index more than one shape per field? What types of shapes can be indexed? What types of query shapes can be used? What types of query operations are supported? This might vary per shape. Does it use the FieldCache, or some other type of cache? When? If a strategy only supports certain shapes at index or query time, then in general it will throw an exception if given an incompatible one. It will not be coerced into compatibility. Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search. Thread-safe. @lucene.experimental
Пример #1
0
		public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
									  double distanceErrorPct = 0.025)
		{
			SpatialOperation spatialOperation;
			var shape = ReadShape(shapeWKT);

			switch (relation)
			{
				case SpatialRelation.Within:
					spatialOperation = SpatialOperation.IsWithin;
					break;
				case SpatialRelation.Contains:
					spatialOperation = SpatialOperation.Contains;
					break;
				case SpatialRelation.Disjoint:
					spatialOperation = SpatialOperation.IsDisjointTo;
					break;
				case SpatialRelation.Intersects:
					spatialOperation = SpatialOperation.Intersects;
					break;
				case SpatialRelation.Nearby:
					// only sort by this, do not filter
					return new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter()));
				default:
					throw new ArgumentOutOfRangeException("relation");
			}
			var args = new SpatialArgs(spatialOperation, shape) { DistErrPct = distanceErrorPct };

			return spatialStrategy.MakeQuery(args);
		}
Пример #2
0
		public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
		                              double distanceErrorPct = 0.025)
		{
			SpatialOperation spatialOperation;
			Shape shape = ShapeReadWriter.ReadShape(shapeWKT);
			switch (relation)
			{
				case SpatialRelation.Within:
					spatialOperation = SpatialOperation.IsWithin;
					break;
				case SpatialRelation.Contains:
					spatialOperation = SpatialOperation.Contains;
					break;
				case SpatialRelation.Disjoint:
					spatialOperation = SpatialOperation.IsDisjointTo;
					break;
				case SpatialRelation.Intersects:
					spatialOperation = SpatialOperation.Intersects;
					break;
				case SpatialRelation.Nearby:
					var nearbyArgs = new SpatialArgs(SpatialOperation.IsWithin, shape);
					nearbyArgs.SetDistPrecision(distanceErrorPct);
					// only sort by this, do not filter
					return new FunctionQuery(spatialStrategy.MakeValueSource(nearbyArgs));
				default:
					throw new ArgumentOutOfRangeException("relation");
			}
			var args = new SpatialArgs(spatialOperation, shape);
			args.SetDistPrecision(distanceErrorPct);

			return spatialStrategy.MakeQuery(args);
		}
Пример #3
0
 public override void TearDown()
 {
     base.TearDown();
     ctx = null;
     strategy = null;
     storeShape = true;
 }
Пример #4
0
		public SpatialField(string fieldName, SpatialOptions options)
		{
			this.options = options;
			ntsContext = CreateNtsContext(options);
			shapeStringReadWriter = new ShapeStringReadWriter(options, ntsContext);
			strategy = CreateStrategy(fieldName, options, ntsContext);
		}
Пример #5
0
		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);
		}
Пример #6
0
		protected void SetUp()
		{
			maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
			fieldInfo = new SimpleSpatialFieldInfo(GetType().Name);
			strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(ctx, maxLength));

			_directory = new RAMDirectory();
			_writer = new IndexWriter(_directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
		}
Пример #7
0
        /// <param name="strategy">Needed to compute intersects</param>
        /// <param name="args">Used in spatial intersection</param>
        /// <param name="field">
        /// This field is used to determine which docs have spatial data via
        /// <see cref="FieldCache.GetDocsWithField(AtomicReader, string)"/>.
        /// Passing null will assume all docs have spatial data.
        /// </param>
        public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string field)
        {
            this.field = field;

            // TODO consider making SpatialArgs cloneable
            SpatialOperation origOp = args.Operation; //copy so we can restore
            args.Operation = SpatialOperation.Intersects; //temporarily set to intersects
            intersectsFilter = strategy.MakeFilter(args);
            args.Operation = origOp;
        }
Пример #8
0
        /// <param name="strategy">Needed to compute intersects</param>
        /// <param name="args">Used in spatial intersection</param>
        /// <param name="field">
        /// This field is used to determine which docs have spatial data via
        /// <see cref="IFieldCache.GetDocsWithField(AtomicReader, string)"/>.
        /// Passing <c>null</c> will assume all docs have spatial data.
        /// </param>
        public DisjointSpatialFilter(SpatialStrategy strategy, SpatialArgs args, string?field)
        {
            // LUCENENET specific - added guard clauses
            if (strategy is null)
            {
                throw new ArgumentNullException(nameof(strategy));
            }
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            this.field = field;

            // TODO consider making SpatialArgs cloneable
            SpatialOperation origOp = args.Operation;       //copy so we can restore

            args.Operation   = SpatialOperation.Intersects; //temporarily set to intersects
            intersectsFilter = strategy.MakeFilter(args);
            args.Operation   = origOp;
        }
Пример #9
0
        static void Main(string[] args)
        {
            int maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
            strategy = new RecursivePrefixTreeStrategy(
                new GeohashPrefixTree(context, maxLength));

            var dir = new RAMDirectory();
            var writer = new IndexWriter(dir, new SimpleAnalyzer(), true,
                IndexWriter.MaxFieldLength.UNLIMITED);

            AddPoint(writer, "London", -81.233040, 42.983390);
            AddPoint(writer, "East New York", -73.882360, 40.666770);
            AddPoint(writer, "Manhattan", -73.966250, 40.783430);
            AddPoint(writer, "New York City", -74.005970, 40.714270);
            AddPoint(writer, "Oslo", 10.746090, 59.912730);
            AddPoint(writer, "Bergen", 5.324150, 60.392990);
            AddPoint(writer, "Washington, D. C.", -77.036370, 38.895110);

            writer.Close();

            // Origin point - Oslo Spektrum
            const double lat = 59.9138688;
            const double lng = 10.752245399999993;
            const double radius = 600;
            var query = strategy.MakeQuery(new SpatialArgs(SpatialOperation.IsWithin,
                context.MakeCircle(lng, lat, radius)), fieldInfo);

            var searcher = new IndexSearcher(dir);
            var results = searcher.Search(query, null, 100);
            foreach (var topDoc in results.ScoreDocs)
            {
                var name = searcher.Doc(topDoc.doc).Get("Name");
                Console.WriteLine(name);
            }
            searcher.Close();
            dir.Close();
        }
 public ObjGeneratorDistanceValueSourceAnonymousClass(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
 public ObjGeneratorFilterAnonymousClass(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
Пример #12
0
        protected void Init()
        {
            //Typical geospatial context
            //  These can also be constructed from SpatialContextFactory
            this.ctx = SpatialContext.GEO;

            int maxLevels = 11;//results in sub-meter precision for geohash
                               //TODO demo lookup by detail distance
                               //  This can also be constructed from SpatialPrefixTreeFactory
            SpatialPrefixTree grid = new GeohashPrefixTree(ctx, maxLevels);

            this.strategy = new RecursivePrefixTreeStrategy(grid, "myGeoField");

            this.directory = new RAMDirectory();
        }
Пример #13
0
		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);
		}
Пример #14
0
		public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation,
									  double distanceErrorPct = 0.025, SpatialUnits? unitOverride = null)
		{
			SpatialOperation spatialOperation;
			var shape = ReadShape(shapeWKT, unitOverride);

			switch (relation)
			{
				case SpatialRelation.Within:
					spatialOperation = SpatialOperation.IsWithin;
					break;
				case SpatialRelation.Contains:
					spatialOperation = SpatialOperation.Contains;
					break;
				case SpatialRelation.Disjoint:
					spatialOperation = SpatialOperation.IsDisjointTo;
					break;
				case SpatialRelation.Intersects:
					spatialOperation = SpatialOperation.Intersects;
					break;
				case SpatialRelation.Nearby:
					// only sort by this, do not filter
					return new FunctionQuery(spatialStrategy.MakeDistanceValueSource(shape.GetCenter()));
				default:
					throw new ArgumentOutOfRangeException("relation");
			}
			var args = new SpatialArgs(spatialOperation, shape) { DistErrPct = distanceErrorPct };

			if (existingQuery is MatchAllDocsQuery)
				return new CustomScoreQuery(spatialStrategy.MakeQuery(args), new ValueSourceQuery(spatialStrategy.MakeRecipDistanceValueSource(shape)));
			return spatialStrategy.MakeQuery(args);
		}
Пример #15
0
		public Query MakeQuery(Query existingQuery, SpatialStrategy spatialStrategy, SpatialIndexQuery spatialQuery)
		{
			return MakeQuery(existingQuery, spatialStrategy, spatialQuery.QueryShape, spatialQuery.SpatialRelation, spatialQuery.DistanceErrorPercentage, spatialQuery.RadiusUnitOverride);
		}
Пример #16
0
 public ObjGeneratorQueryAnonymousHelper(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
Пример #17
0
 public Param(SpatialStrategy strategy) { this.strategy = strategy; }
Пример #18
0
 internal Param(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
Пример #19
0
 internal Param(SpatialStrategy strategy)
 {
     this.strategy = strategy;
 }
Пример #20
0
		static SpatialIndex()
		{
			maxLength = GeohashPrefixTree.GetMaxLevelsPossible();
			fieldInfo = new SimpleSpatialFieldInfo(Constants.SpatialFieldName);
			strategy = new RecursivePrefixTreeStrategy(new GeohashPrefixTree(RavenSpatialContext, maxLength));
		}