Пример #1
0
        //@ParametersFactory
        public static IList <Object[]> Parameters()
        {
            List <Object[]> ctorArgs = new List <object[]>();

            SpatialContext    ctx = SpatialContext.GEO;
            SpatialPrefixTree grid;
            SpatialStrategy   strategy;

            grid     = new GeohashPrefixTree(ctx, 12);
            strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
            ctorArgs.Add(new Object[] { new Param(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) });

            return(ctorArgs);
        }
Пример #2
0
        public virtual void TestBadPrefixTreePrune()
        {
            trie = new QuadPrefixTree(ctx, 12);
            TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
            Document doc = new Document();

            doc.Add(new TextField("id", "1", Field.Store.YES));

            IShape area = ctx.MakeRectangle(-122.82, -122.78, 48.54, 48.56);

            Field[] fields = strategy.CreateIndexableFields(area, 0.025);
            foreach (Field field in fields)
            {
                doc.Add(field);
            }
            AddDocument(doc);

            IPoint upperleft  = ctx.MakePoint(-122.88, 48.54);
            IPoint lowerright = ctx.MakePoint(-122.82, 48.62);

            Query query = strategy.MakeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.MakeRectangle(upperleft, lowerright)));

            Commit();

            TopDocs search = indexSearcher.Search(query, 10);

            ScoreDoc[] scoreDocs = search.ScoreDocs;
            foreach (ScoreDoc scoreDoc in scoreDocs)
            {
                Console.WriteLine(indexSearcher.Doc(scoreDoc.Doc));
            }

            assertEquals(1, search.TotalHits);
        }
Пример #3
0
        public virtual void TestBadPrefixTreePrune()
        {

            trie = new QuadPrefixTree(ctx, 12);
            TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
            Document doc = new Document();
            doc.Add(new TextField("id", "1", Field.Store.YES));

            IShape area = ctx.MakeRectangle(-122.82, -122.78, 48.54, 48.56);

            Field[] fields = strategy.CreateIndexableFields(area, 0.025);
            foreach (Field field in fields)
            {
                doc.Add(field);
            }
            AddDocument(doc);

            IPoint upperleft = ctx.MakePoint(-122.88, 48.54);
            IPoint lowerright = ctx.MakePoint(-122.82, 48.62);

            Query query = strategy.MakeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.MakeRectangle(upperleft, lowerright)));

            Commit();

            TopDocs search = indexSearcher.Search(query, 10);
            ScoreDoc[] scoreDocs = search.ScoreDocs;
            foreach (ScoreDoc scoreDoc in scoreDocs)
            {
                Console.WriteLine(indexSearcher.Doc(scoreDoc.Doc));
            }

            assertEquals(1, search.TotalHits);
        }
Пример #4
0
        public void testNGramPrefixGridLosAngeles()
        {
            SpatialContext ctx = SpatialContext.GEO;
            TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");

            Shape point = ctx.MakePoint(-118.243680, 34.052230);

            Document losAngeles = new Document();

            losAngeles.Add(new Field("name", "Los Angeles", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
            foreach (var indexableField in prefixGridStrategy.CreateIndexableFields(point))
            {
                losAngeles.Add(indexableField);
            }
            losAngeles.Add(new Field(prefixGridStrategy.GetFieldName(), ctx.ToString(point), Field.Store.YES, Field.Index.NO));

            addDocumentsAndCommit(new List <Document> {
                losAngeles
            });

            // This won't work with simple spatial context...
            SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
            // TODO... use a non polygon query
            //    SpatialArgs spatialArgs = spatialArgsParser.parse(
            //        "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
            //        new SimpleSpatialContext());

            //    Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
            //    SearchResults searchResults = executeQuery(query, 1);
            //    assertEquals(1, searchResults.numFound);
        }
            public IEnumerable <Param> ParamsProvider()
            {
                var ctorArgs = new List <Param>();

                SpatialContext    ctx = SpatialContext.GEO;
                SpatialPrefixTree grid;
                SpatialStrategy   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));

                strategy = new BBoxStrategy(ctx, "bbox");
                ctorArgs.Add(new Param(strategy));

                return(ctorArgs);
            }
Пример #6
0
        public static TopDocs DistanceFilter_TermQueryPrefixTreeStrategy(Searcher searcher, TermQueryPrefixTreeStrategy strategy, Point myLocation)
        {
            var ctx = strategy.GetSpatialContext();

            var q      = new MatchAllDocsQuery();
            var filter = strategy.MakeFilter(new SpatialArgs(SpatialOperation.Intersects,
                                                             ctx.MakeCircle(myLocation,
                                                                            DistanceUtils.Dist2Degrees(2000,
                                                                                                       DistanceUtils
                                                                                                       .EARTH_MEAN_RADIUS_KM))));
            TopDocs hits = searcher.Search(q, filter, 100);

            return(hits);
        }