Lucene.net返回文档中的所有字段

Lucene.net返回文档中的所有字段,lucene,lucene.net,Lucene,Lucene.net,我正在lucene.Net中存储数据 我添加了一个包含多个字段的文档: var doc = new Document(); doc.Add(new Field("CreationDate", dt, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("FileName", path, Field.Store.YES, Field.Index.ANALYZED)); doc.Add(new Field("Directory",

我正在lucene.Net中存储数据 我添加了一个包含多个字段的文档:

var doc = new Document();

doc.Add(new Field("CreationDate", dt, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("FileName", path, Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("Directory", dtpath, Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.Add(new Field("Text", text.ToString(), Field.Store.YES, Field.Index.ANALYZED));
...
writer.AddDocument(doc);
我想浏览每个文档的所有项目和返回字段“CreationDate”和“Directory”。 但一个术语只能包含一个字段:

var termnum=reader.Terms(新术语(“CreationDate”)

如何使其返回这两个字段

谢谢
Martin

当您迭代搜索结果时,请阅读文档并从中加载值:

int docId = hits[i].doc;  
Document doc = searcher.Doc(docId); 
String creationDate = doc.Get("CreationDate");
String directory = doc.get("Directory");
// ...and so on

您可以通过以下方式获取包含给定术语的所有文档的枚举:

var termDocEnum = reader.TermDocs(new Term("CreationDate"));
您可以使用该枚举使用docId获取文档:

Document doc = searcher.doc(termDocEnum.doc);
这样就可以很容易地使用来获取您要查找的信息

注意,正如前面所暗示的,这将只获取给定术语具有指定值的文档!如果这是一个问题,您可以为每个相关参数调用TermDocs一次,并根据需要合并集合(使用docId上索引的哈希表或类似的方法可以很容易地完成),或者调用没有参数的TermDocs,并使用来查找适当的术语(如有必要,需要再次手动进行合并)

从“terms”方法传递的termnum不会给您一个docId(我相信,您必须使用termDocs方法在枚举中的每个术语中获取它们)