0
Je souhaite indexer certains fichiers et y récupérer des informations.erreur lors de l'indexation d'un document avec pylucene
J'utilise ce morceau de code en python document index:
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();
mais je face à cette erreur:
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'
Comment puis-je résoudre ce problème?
Merci