CreateIndexableFields() public abstract method

Returns the IndexableField(s) from the shape that are to be added to the Document. These fields are expected to be marked as indexed and not stored.

Note: If you want to store the shape as a string for retrieval in search results, you could add it like this: document.Add(new StoredField(fieldName, ctx.ToString(shape))); The particular string representation used doesn't matter to the Strategy since it doesn't use it.

if given a shape incompatible with the strategy
public abstract CreateIndexableFields ( IShape shape ) : Lucene.Net.Documents.Field[]
shape IShape
return Lucene.Net.Documents.Field[]
        protected virtual List <Document> getDocuments(IEnumerator <SpatialTestData> sampleData)
        {
            List <Document> documents = new List <Document>();

            while (sampleData.MoveNext())
            {
                SpatialTestData data     = sampleData.Current;
                Document        document = new Document();
                document.Add(new StringField("id", data.id, Field.Store.YES));
                document.Add(new StringField("name", data.name, Field.Store.YES));
                IShape shape = data.shape;
                shape = convertShapeFromGetDocuments(shape);
                if (shape != null)
                {
                    foreach (Field f in strategy.CreateIndexableFields(shape))
                    {
                        document.Add(f);
                    }
                    if (storeShape)//just for diagnostics
                    {
                        document.Add(new StoredField(strategy.FieldName, shape.toString()));
                    }
                }

                documents.Add(document);
            }
            return(documents);
        }
Beispiel #2
0
        private Document NewSampleDocument(int id, params IShape[] shapes)
        {
            Document doc = new Document();

            doc.Add(new Int32Field("id", id, Field.Store.YES));
            //Potentially more than one shape in this field is supported by some
            // strategies; see the javadocs of the SpatialStrategy impl to see.
            foreach (IShape shape in shapes)
            {
                foreach (IIndexableField f in strategy.CreateIndexableFields(shape))
                {
                    doc.Add(f);
                }
                //store it too; the format is up to you
                //  (assume point in this example)
                IPoint pt = (IPoint)shape;
                doc.Add(new StoredField(strategy.FieldName, pt.X.ToString(CultureInfo.InvariantCulture) + " " + pt.Y.ToString(CultureInfo.InvariantCulture)));
            }

            return(doc);
        }