On Sat, 27 Jan 2007, ashwin thapar wrote:

I am running Python2.4 and PyLucene Version 2.0.0. I have a folder containing several text files. I successfully run IndexFiles.py form the Python sample files folder. However, when I attempt to run SearchFiles.py, I get the following error message:

Searching for: fast
Traceback (most recent call last):
File "SearchFiles.py", line 37, in ?
  run(searcher, analyzer)
File "SearchFiles.py", line 24, in run
  query = QueryParser.parse(command, "contents", analyzer)
TypeError: descriptor 'parse' requires a 'PyLucene.QueryParser' object but received a 'str'

The same procedure worked without any problem on PyLucene 1.9, the error has only arisen after the upgrade. (I installed the new PyLucene 2.0.0, and am using the PyLucene 2.0.0 sample files

This is a known and fixed bug. Get the latest PyLucene.
I attached the latest SearchFiles.py or get it from [1]

Andi..

[1] http://svn.osafoundation.org/pylucene/trunk/samples/SearchFiles.py
#!/usr/bin/env python
from PyLucene import QueryParser, IndexSearcher, StandardAnalyzer, FSDirectory
from PyLucene import VERSION, LUCENE_VERSION

"""
This script is loosely based on the Lucene (java implementation) demo class 
org.apache.lucene.demo.SearchFiles.  It will prompt for a search query, then it
will search the Lucene index in the current directory called 'index' for the
search query entered against the 'contents' field.  It will then display the
'path' and 'name' fields for each of the hits it finds in the index.  Note that
search.close() is currently commented out because it causes a stack overflow in
some cases.
"""
def run(searcher, analyzer):
    while True:
        print
        print "Hit enter with no input to quit."
        command = raw_input("Query:")
        if command == '':
            return

        print
        print "Searching for:", command
        query = QueryParser("contents", analyzer).parse(command)
        hits = searcher.search(query)
        print "%s total matching documents." % hits.length()

        for i, doc in hits:
            print 'path:', doc.get("path"), 'name:', doc.get("name")


if __name__ == '__main__':
    STORE_DIR = "index"
    print 'PyLucene', VERSION, 'Lucene', LUCENE_VERSION
    directory = FSDirectory.getDirectory(STORE_DIR, False)
    searcher = IndexSearcher(directory)
    analyzer = StandardAnalyzer()
    run(searcher, analyzer)
    searcher.close()
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to