MakeQuery() public method

Make a Query based principally on SpatialOperation and IShape from the supplied args. The default implementation is return new ConstantScoreQuery(MakeFilter(args));
If the strategy does not support the shape in . If the strategy does not support the in .
public MakeQuery ( SpatialArgs args ) : ConstantScoreQuery
args Lucene.Net.Spatial.Queries.SpatialArgs
return Lucene.Net.Search.ConstantScoreQuery
Example #1
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);
		}
Example #2
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();
        }
Example #3
0
 protected virtual Query makeQuery(SpatialTestQuery q)
 {
     return(strategy.MakeQuery(q.args));
 }
Example #4
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);
		}
 public object gen(SpatialArgs args)
 {
     return(strategy.MakeQuery(args));
 }
Example #6
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);
		}