예제 #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);
        }
예제 #2
0
        public static IEnumerable <Document> CreateSearchDocuments(IList <Deal> deals, SpatialStrategy strategy)
        {
            var docs = new List <Document>(deals.Count());
            var ctx  = strategy.GetSpatialContext();

            foreach (var deal in deals)
            {
                foreach (var location in deal.Locations)
                {
                    var doc = new Document();
                    doc.Add(new Field(TitleFieldName, deal.Title, Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field(SupplierFieldName, deal.Supplier, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    doc.Add(new Field(LocationNameFieldName, location.Name, Field.Store.YES, Field.Index.NOT_ANALYZED));

                    foreach (var f in strategy.CreateIndexableFields(ctx.MakePoint(location.Latitude, location.Longitude)))
                    {
                        doc.Add(f);
                    }

                    docs.Add(doc);
                }
            }

            return(docs);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="docId"></param>
        /// <param name="rng"></param>
        /// <param name="ctx"></param>
        /// <param name="percentageWithSpatialFields">ensures that some documents are missing spatial fields. This forces the cache to use FixedBitSet rather than MatchAllBits or MatchNoBits</param>
        /// <returns></returns>
        private Document CreateRandomDoc(int docId, Random rng, SpatialContext ctx, double percentageWithSpatialFields)
        {
            var doc = new Document();

            var idField = new NumericField("locationId", Field.Store.YES, true);

            idField.SetIntValue(docId);

            doc.Add(idField);

            if (rng.NextDouble() > percentageWithSpatialFields)
            {
                return(doc);
            }

            Point shape = ctx.MakePoint(DistanceUtils.NormLonDEG(rng.NextDouble() * 360.0), DistanceUtils.NormLatDEG(rng.NextDouble() * 180.0));

            foreach (AbstractField field in _spatialStrategy.CreateIndexableFields(shape))
            {
                doc.Add(field);
            }

            doc.Add(_spatialStrategy.CreateStoredField(shape));

            return(doc);
        }
예제 #4
0
        /// <summary>
        /// Adds the location to the index to be used for spatial queries
        /// </summary>
        /// <param name="doc">Document to add the location</param>
        /// <param name="phi">Latitude(φ)</param>
        /// <param name="lamda">Longitude(λ)</param>
        internal void AddLocation(Document doc, double phi, double lamda)
        {
            IPoint point = SpatialContext.MakePoint(phi, lamda);

            foreach (var field in spatialStrategy.CreateIndexableFields(point))
            {
                doc.Add(field);
            }
            doc.Add(new StringField(spatialStrategy.FieldName, FormattableString.Invariant($"POINT ({point.X} {point.Y})"), Field.Store.YES));
        }
예제 #5
0
        public IEnumerable <AbstractField> CreateIndexableFields(object value)
        {
            var shape = value as Shape;

            if (shape != null || TryReadShape(value, out shape))
            {
                return(strategy.CreateIndexableFields(shape)
                       .Concat(new[] { new Field(Constants.SpatialShapeFieldName, WriteShape(shape), Field.Store.YES, Field.Index.NO), }));
            }

            return(Enumerable.Empty <AbstractField>());
        }
        public static Document CreateDocument(string name, Shape shape, SpatialStrategy strategy)
        {
            var document = new Document();

            document.Add(new Field(IdFieldName, name, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            foreach (var f in strategy.CreateIndexableFields(shape))
            {
                document.Add(f);
            }

            return(document);
        }
예제 #7
0
        private void Indexer_DocumentWriting(LuceneEngine.DocumentWritingEventArgs e, SpatialContext ctx, SpatialStrategy strategy)
        {
            double lat = double.Parse(e.ValueSet.Values["lat"].First().ToString());
            double lng = double.Parse(e.ValueSet.Values["lng"].First().ToString());

            GetXYFromCoords(lat, lng, out var x, out var y);
            Shape geoPoint = ctx.MakePoint(x, y);

            foreach (AbstractField field in strategy.CreateIndexableFields(geoPoint))
            {
                e.Document.Add(field);
            }
        }
예제 #8
0
        public AbstractField[] CreateIndexableFields(object value)
        {
            var shape = value as Shape;
            if (shape != null || TryReadShape(value, out shape))
            {
                var fields = Strategy.CreateIndexableFields(shape);
                Array.Resize(ref fields, fields.Length + 1);
                fields[fields.Length - 1] = new Field(Constants.Documents.Indexing.Fields.SpatialShapeFieldName, WriteShape(shape), Field.Store.YES, Field.Index.NO);

                return fields;
            }

            return Array.Empty<AbstractField>();
        }
예제 #9
0
        public static Document CreateDocument(string id, Shape shape, SpatialStrategy strategy)
        {
            var document = new Document();

            document.Add(new Field("id", id, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            foreach (var f in strategy.CreateIndexableFields(shape))
            {
                document.Add(f);
            }

            //document.Add(new Field(strategy.GetFieldName(), strategy.GetSpatialContext().ToString(shape), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));

            return(document);
        }
예제 #10
0
        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);
        }
예제 #11
0
        // LUCENENET specific: de-nested IShapeConverter

        public override Document MakeDocument()
        {
            DocState docState = GetDocState();

            Document doc = base.MakeDocument();

            // Set SPATIAL_FIELD from body
            DocData docData = docState.docData;
            //   makeDocument() resets docState.getBody() so we can't look there; look in Document
            string shapeStr = doc.GetField(DocMaker.BODY_FIELD).GetStringValue();
            IShape shape    = MakeShapeFromString(strategy, docData.Name, shapeStr);

            if (shape != null)
            {
                shape = shapeConverter.Convert(shape);
                //index
                foreach (Field f in strategy.CreateIndexableFields(shape))
                {
                    doc.Add(f);
                }
            }

            return(doc);
        }