Пример #1
0
 /// <summary>
 /// Like <seealso cref="#document(int)"/> but only loads the specified
 /// fields.  Note that this is simply sugar for {@link
 /// DocumentStoredFieldVisitor#DocumentStoredFieldVisitor(Set)}.
 /// </summary>
 public Document Document(int docID, ISet<string> fieldsToLoad)
 {
     var visitor = new DocumentStoredFieldVisitor(fieldsToLoad);
     Document(docID, visitor);
     return visitor.Document;
 }
Пример #2
0
        public virtual void Test()
        {
            Assert.IsTrue(Dir != null);
            Assert.IsTrue(FieldInfos != null);
            IndexReader reader = DirectoryReader.Open(Dir);
            Document doc = reader.Document(0);
            Assert.IsTrue(doc != null);
            Assert.IsTrue(doc.GetField(DocHelper.TEXT_FIELD_1_KEY) != null);

            Field field = (Field)doc.GetField(DocHelper.TEXT_FIELD_2_KEY);
            Assert.IsTrue(field != null);
            Assert.IsTrue(field.FieldType().StoreTermVectors);

            Assert.IsFalse(field.FieldType().OmitNorms);
            Assert.IsTrue(field.FieldType().IndexOptions == FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);

            field = (Field)doc.GetField(DocHelper.TEXT_FIELD_3_KEY);
            Assert.IsTrue(field != null);
            Assert.IsFalse(field.FieldType().StoreTermVectors);
            Assert.IsTrue(field.FieldType().OmitNorms);
            Assert.IsTrue(field.FieldType().IndexOptions == FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);

            field = (Field)doc.GetField(DocHelper.NO_TF_KEY);
            Assert.IsTrue(field != null);
            Assert.IsFalse(field.FieldType().StoreTermVectors);
            Assert.IsFalse(field.FieldType().OmitNorms);
            Assert.IsTrue(field.FieldType().IndexOptions == FieldInfo.IndexOptions.DOCS_ONLY);

            DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(DocHelper.TEXT_FIELD_3_KEY);
            reader.Document(0, visitor);
            IList<IndexableField> fields = visitor.Document.Fields;
            Assert.AreEqual(1, fields.Count);
            Assert.AreEqual(DocHelper.TEXT_FIELD_3_KEY, fields[0].Name());
            reader.Dispose();
        }
Пример #3
0
 /// <summary>
 /// Returns the stored fields of the <code>n</code><sup>th</sup>
 /// <code>Document</code> in this index.  this is just
 /// sugar for using <seealso cref="DocumentStoredFieldVisitor"/>.
 /// <p>
 /// <b>NOTE:</b> for performance reasons, this method does not check if the
 /// requested document is deleted, and therefore asking for a deleted document
 /// may yield unspecified results. Usually this is not required, however you
 /// can test if the doc is deleted by checking the {@link
 /// Bits} returned from <seealso cref="MultiFields#getLiveDocs"/>.
 ///
 /// <b>NOTE:</b> only the content of a field is returned,
 /// if that field was stored during indexing.  Metadata
 /// like boost, omitNorm, IndexOptions, tokenized, etc.,
 /// are not preserved.
 /// </summary>
 /// <exception cref="IOException"> if there is a low-level IO error </exception>
 // TODO: we need a separate StoredField, so that the
 // Document returned here contains that class not
 // IndexableField
 public Document Document(int docID)
 {
     var visitor = new DocumentStoredFieldVisitor();
     Document(docID, visitor);
     return visitor.Document;
 }