使用pylucene索引文档时出错

使用pylucene索引文档时出错,lucene,information-retrieval,pylucene,Lucene,Information Retrieval,Pylucene,我想索引一些文件并从中检索一些信息 我使用python中的这段代码为文档编制索引: import sys ; import lucene ; from java.io import File ; from org.apache.lucene.analysis.standard import StandardAnalyzer ; from org.apache.lucene.document import Document, Field ; from org.apache.lucene.inde

我想索引一些文件并从中检索一些信息

我使用python中的这段代码为文档编制索引:

import sys ;
import lucene ;

from java.io import File ;
from org.apache.lucene.analysis.standard import StandardAnalyzer ;
from org.apache.lucene.document import Document, Field ;
from org.apache.lucene.index import IndexWriter, IndexWriterConfig ;
from org.apache.lucene.store import SimpleFSDirectory ;
from org.apache.lucene.util import Version ;

if __name__ == '__main__':
lucene.initVM();
indexDir = SimpleFSDirectory(File("myProjects/python/")) ;
writerConfig =
IndexWriterConfig(Version.LUCENE_4_10_1,StandardAnalyzer());
writer = IndexWriter(indexDir,writerConfig);

print "%d docs in index" % writer.numDocs();
print "Reading lines from sys.stdin..."
n = 0;
l = 0;
for n, l in enumerate(sys.stdin):
    doc = Document ;
    doc.add(Field("text", l, Field.Store.YES, Field.Index.ANALYZED));
    writer.addDocument(doc);
print "Indexed %d lines from stdin (%d docs in index)" %
(n,writer.numDocs());
print "Closing index of %d docs..." % writer.numDocs();
writer.close();
但我面临着这个错误:

Traceback (most recent call last):
File "/home/ahoora/myProjects/python/index.py", line 24, in <module>
doc.add(Field("text", l, Field.Store.YES, Field.Index.ANALYZED));
TypeError: descriptor 'add' requires a 'Document' object but received
a 'Field'
回溯(最近一次呼叫最后一次):
文件“/home/ahoora/myProjects/python/index.py”,第24行,在
添加文档(字段(“文本”,l,Field.Store.YES,Field.Index.ANALYZED));
TypeError:描述符“add”需要“Document”对象,但已收到
“场”
我怎样才能修好它


谢谢

现在问题解决了。我应该写:

doc = Document();