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