Exemple #1
0
            public SpatialIdx()
            {
                Map = docs => from e in docs
                      select new { e.Capacity, e.Venue, e.Date, _ = SpatialIndex.Generate(e.Latitude, e.Longitude) };

                Index(x => x.Venue, FieldIndexing.Analyzed);
            }
Exemple #2
0
        public void PureLucene()
        {
            using (var dir = new RAMDirectory())
            {
                using (var keywordAnalyzer = new KeywordAnalyzer())
                    using (var writer = new IndexWriter(dir, keywordAnalyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
                    {
                        var doc = new Lucene.Net.Documents.Document();

                        var writeShape    = NtsSpatialContext.GEO.ReadShape("LINESTRING (0 0, 1 1, 2 1)");
                        var writeStrategy = SpatialIndex.CreateStrategy("WKT", SpatialSearchStrategy.GeohashPrefixTree, GeohashPrefixTree.GetMaxLevelsPossible());
                        foreach (var f in writeStrategy.CreateIndexableFields(writeShape))
                        {
                            doc.Add(f);
                        }
                        writer.AddDocument(doc);
                        writer.Commit();
                    }


                var         shape     = NtsSpatialContext.GEO.ReadShape("LINESTRING (1 0, 1 1, 1 2)");
                SpatialArgs args      = new SpatialArgs(SpatialOperation.Intersects, shape);
                var         strategy  = SpatialIndex.CreateStrategy("WKT", SpatialSearchStrategy.GeohashPrefixTree, GeohashPrefixTree.GetMaxLevelsPossible());
                var         makeQuery = strategy.MakeQuery(args);
                using (var search = new IndexSearcher(dir))
                {
                    var topDocs = search.Search(makeQuery, 5);
                    Assert.Equal(1, topDocs.TotalHits);
                }
            }
        }