Example #1
0
        public virtual void TestBadPrefixTreePrune()
        {
            IShape area = ctx.ReadShapeFromWkt("POLYGON((-122.83 48.57, -122.77 48.56, -122.79 48.53, -122.83 48.57))");

            SpatialPrefixTree           trie     = new QuadPrefixTree(ctx, 12);
            TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
            Document doc = new Document();

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

            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);
        }
        public virtual void TestNGramPrefixGridLosAngeles()
        {
            SpatialContext ctx = SpatialContext.GEO;
            TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");

            Spatial4n.Core.Shapes.IShape point = ctx.MakePoint(-118.243680, 34.052230);

            Document losAngeles = new Document();

            losAngeles.Add(new StringField("name", "Los Angeles", Field.Store.YES));
            foreach (IndexableField field in prefixGridStrategy.CreateIndexableFields(point))
            {
                losAngeles.Add(field);
            }
            losAngeles.Add(new StoredField(prefixGridStrategy.FieldName, point.toString()));//just for diagnostics

            addDocumentsAndCommit(Arrays.AsList(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 virtual void TestNGramPrefixGridLosAngeles()
        {
            SpatialContext ctx = SpatialContext.GEO;
            TermQueryPrefixTreeStrategy prefixGridStrategy = new TermQueryPrefixTreeStrategy(new QuadPrefixTree(ctx), "geo");

            Spatial4n.Core.Shapes.IShape point = ctx.MakePoint(-118.243680, 34.052230);

            Document losAngeles = new Document();
            losAngeles.Add(new StringField("name", "Los Angeles", Field.Store.YES));
            foreach (IndexableField field in prefixGridStrategy.CreateIndexableFields(point))
            {
                losAngeles.Add(field);
            }
            losAngeles.Add(new StoredField(prefixGridStrategy.FieldName, point.toString()));//just for diagnostics

            addDocumentsAndCommit(Arrays.AsList(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 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);
		}
Example #5
0
        public virtual void TestBadPrefixTreePrune()
        {

            IShape area = ctx.ReadShapeFromWkt("POLYGON((-122.83 48.57, -122.77 48.56, -122.79 48.53, -122.83 48.57))");

            SpatialPrefixTree trie = new QuadPrefixTree(ctx, 12);
            TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
            Document doc = new Document();
            doc.Add(new TextField("id", "1", Field.Store.YES)); // LUCENENET TODO: Change API to Store.Yes

            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);
        }