Lucene.Net.Index.IndexReader.GetFieldNames C# (CSharp) Method

GetFieldNames() public abstract method

Get a list of unique field names that exist in this index and have the specified field option information.
public abstract GetFieldNames ( FieldOption fldOption ) : ICollection
fldOption FieldOption specifies which field option should be available for the returned fields ///
return ICollection
		public abstract ICollection<string> GetFieldNames(FieldOption fldOption);

Usage Example

Ejemplo n.º 1
0
        public virtual void  TestGetFieldNames()
        {
            RAMDirectory d = new RAMDirectory();
            // set up writer
            IndexWriter writer = new IndexWriter(d, new StandardAnalyzer(), true);

            AddDocumentWithFields(writer);
            writer.Close();
            // set up reader
            IndexReader reader = IndexReader.Open(d);

            System.Collections.Hashtable fieldNames = (System.Collections.Hashtable)reader.GetFieldNames();
            Assert.IsTrue(fieldNames.Contains("keyword"));
            Assert.IsTrue(fieldNames.Contains("text"));
            Assert.IsTrue(fieldNames.Contains("unindexed"));
            Assert.IsTrue(fieldNames.Contains("unstored"));
            // add more documents
            writer = new IndexWriter(d, new StandardAnalyzer(), false);
            // want to get some more segments here
            for (int i = 0; i < 5 * writer.mergeFactor; i++)
            {
                AddDocumentWithFields(writer);
            }
            // new fields are in some different segments (we hope)
            for (int i = 0; i < 5 * writer.mergeFactor; i++)
            {
                AddDocumentWithDifferentFields(writer);
            }
            writer.Close();
            // verify fields again
            reader     = IndexReader.Open(d);
            fieldNames = (System.Collections.Hashtable)reader.GetFieldNames();
            Assert.AreEqual(9, fieldNames.Count); // the following fields + an empty one (bug?!)
            Assert.IsTrue(fieldNames.Contains("keyword"));
            Assert.IsTrue(fieldNames.Contains("text"));
            Assert.IsTrue(fieldNames.Contains("unindexed"));
            Assert.IsTrue(fieldNames.Contains("unstored"));
            Assert.IsTrue(fieldNames.Contains("keyword2"));
            Assert.IsTrue(fieldNames.Contains("text2"));
            Assert.IsTrue(fieldNames.Contains("unindexed2"));
            Assert.IsTrue(fieldNames.Contains("unstored2"));

            // verify that only indexed fields were returned
            System.Collections.ICollection indexedFieldNames = reader.GetFieldNames(true);
            Assert.AreEqual(6, indexedFieldNames.Count);
            Assert.IsTrue(fieldNames.Contains("keyword"));
            Assert.IsTrue(fieldNames.Contains("text"));
            Assert.IsTrue(fieldNames.Contains("unstored"));
            Assert.IsTrue(fieldNames.Contains("keyword2"));
            Assert.IsTrue(fieldNames.Contains("text2"));
            Assert.IsTrue(fieldNames.Contains("unstored2"));

            // verify that only unindexed fields were returned
            System.Collections.ICollection unindexedFieldNames = reader.GetFieldNames(false);
            Assert.AreEqual(3, unindexedFieldNames.Count); // the following fields + an empty one
            Assert.IsTrue(fieldNames.Contains("unindexed"));
            Assert.IsTrue(fieldNames.Contains("unindexed2"));
        }
All Usage Examples Of Lucene.Net.Index.IndexReader::GetFieldNames