예제 #1
0
        protected List <Document> getDocuments(IEnumerator <SampleData> sampleData)
        {
            var documents = new List <Document>();

            while (sampleData.MoveNext())
            {
                SampleData data     = sampleData.Current;
                var        document = new Document();
                document.Add(new Field("id", data.id, Field.Store.YES, Field.Index.ANALYZED));
                document.Add(new Field("name", data.name, Field.Store.YES, Field.Index.ANALYZED));
                Shape shape = ctx.ReadShape(data.shape);
                shape = convertShapeFromGetDocuments(shape);
                if (shape != null)
                {
                    foreach (var f in strategy.CreateIndexableFields(shape))
                    {
                        document.Add(f);
                    }
                    if (storeShape)
                    {
                        document.Add(new Field(strategy.GetFieldName(), ctx.ToString(shape), Field.Store.YES,
                                               Field.Index.NOT_ANALYZED_NO_NORMS));
                    }
                }

                documents.Add(document);
            }
            return(documents);
        }
        private Document CreateDocument(SearchItem item)
        {
            var doc = new Document();

            doc.Add(new Field(Name, item.Name, Field.Store.YES, Field.Index.ANALYZED));

            // It's not strictly necessary to store the long/lat values explicitely, but could be useful with future Lucene versions.
            doc.Add(new NumericField(Longitude, 7, Field.Store.YES, true).SetDoubleValue(item.Longitude));
            doc.Add(new NumericField(Latitude, 7, Field.Store.YES, true).SetDoubleValue(item.Latitude));

            // These document values will be used when searching the index.
            var shape = (Shape)_spatialContext.MakePoint(item.Longitude, item.Latitude);

            foreach (var field in _strategy.CreateIndexableFields(shape))
            {
                doc.Add(field);
            }
            var point = (Point)shape;

            doc.Add(new Field(_strategy.GetFieldName(), $"{point.GetX().ToString("0.0000000")},{point.GetY().ToString("0.0000000")}", Field.Store.YES, Field.Index.NOT_ANALYZED));

            return(doc);
        }
 public override String ToString()
 {
     return(strategy.GetFieldName());
 }