Hello all!
I'm starting to look at PyLucene and I'm having some trouble. I'd ask for a
tutorial but I've searched on the web and it seems there is none. I've
looked at the scripts provided in the "samples" directory but it was to no
avail.
I'm trying to do a rather simple task: index a list of files in a local
directory and then search on that index. I've looked at the
BaseIndexingTestCase.py and I've come up with this code:
# Lucene Index Create
# Imports
import PyLucene
import os
# Creating the Index
try:
path_index = os.getcwd()+ r"/index"# Linux
except:
path_index= os.getcwd()+ r"\index" # Windows
writer = PyLucene.IndexWriter(path_index, PyLucene.SimpleAnalyzer(), True) #
Create the Index Writer
# Creating Document Fields
def NewDocument(writer, path_file):
doc = PyLucene.Document()
text_file = open(path_file, 'r')
doc.add(PyLucene.Field("PMID", text_file.readline(),
PyLucene.Field.Store.YES, PyLucene.Field.Index.TOKENIZED))
text_file.close()
writer.addDocument(doc)
for root, dirs, files in os.walk(os.getcwd()+'/Artigos'): # List files in
directory
file_list = files
for i in range(len(file_list)): # Create new document for each file in
directory
NewDocument(writer, os.getcwd()+'/Artigos/'+file_list[i])
#print file_list[i]
writer.optimize()
writer.close()
It is creating the index, or at least it creates 3 files in the directory
/index. However, the search returns no results. Is there something wrong
with the indexing process?
Thank you all in advance,
João Rodrigues
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev