/// <summary> /// Returns the stored fields of the <c>n</c><sup>th</sup> /// <see cref="Documents.Document"/> in this index. This is just /// sugar for using <see cref="DocumentStoredFieldVisitor"/>. /// <para/> /// <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 /// <see cref="Util.IBits"/> returned from <see cref="MultiFields.GetLiveDocs"/>. /// <para/> /// <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="System.IO.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); }
public virtual string[] GetStoredFieldValue(int docid, string fieldname) { DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(fieldname); base.Document(docid, visitor); Document doc = visitor.Document; return(doc.GetValues(fieldname)); }
protected override Document RetrieveDoc(IndexReader ir, int id) { if (m_fieldsToLoad == null) { return(ir.Document(id)); } else { DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(m_fieldsToLoad); ir.Document(id, visitor); return(visitor.Document); } }
public Document[] SearchWithSpecificFields(Query query, int maxResults, params string[] fieldsNeedToLoad) { fieldsNeedToLoad.RequireContainsElement(nameof(fieldsNeedToLoad)); using var readLock = new EnterReaderWriterLock(readerWriteLock); using var searcher = GetUseIndexSearcher(); return(searcher.IndexSearcher.Search(query, maxResults).ScoreDocs.Select(hit => { var visitor = new DocumentStoredFieldVisitor(fieldsNeedToLoad); searcher.IndexSearcher.Doc(hit.Doc, visitor); return visitor.Document; }).ToArray()); }
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(); }
/// <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) { DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(fieldsToLoad); Document(docID, visitor); return visitor.Document; }
/// <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) { DocumentStoredFieldVisitor visitor = new DocumentStoredFieldVisitor(); Document(docID, visitor); return visitor.Document; }