Question

I'm trying to use PyLucene, and I can't find any code examples that actually run in my current version. (See, for example, http://nullege.com/codes/search/PyLucene.StandardAnalyzer).

At some point you need to instantiate an analyzer. It would appear that that should be done by calling lucene.StandardAnalyzer(). However, that gives an error:

lucene.InvalidArgsError: (<type 'StandardAnalyzer'>, '__init__', ())

The reason for the error is pretty clear: the StandardAnalyzer documentation, at http://lucene.apache.org/core/old_versioned_docs/versions/3_0_3/api/core/index.html, says it requires an argument which is a Version object.

So where do I get a Version object?

The following things have appeared in code samples but do not actually work:

  • lucene.Version.LUCENE_CURRENT
  • lucene.Version.LUCENE_30

Those names are undefined. Here's what my lucene.Version class has in it:

>>> print dir(lucene.Version)
['__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_jobject', 'cast_', 'class', 'compareTo', 'declaringClass', 'equals', 'getClass', 'getDeclaringClass', 'hashCode', 'instance_', 'name', 'notify', 'notifyAll', 'of_', 'onOrAfter', 'ordinal', 'parameters_', 'toString', 'valueOf', 'values', 'wait']
Was it helpful?

Solution 2

I figured it out, and now I finally get to post this as the answer:

After you run lucene.initVM(), the lucene.Version object will be populated with various version objects such as lucene.Version.LUCENE_35.

And there is a working PyLucene example at:

http://metaoptimize.com/blog/2010/08/09/pylucene-3-0-in-60-seconds-tutorial-sample-code-for-the-3-0-api/

OTHER TIPS

These days the tarball for a release of PyLucene has a 'samples' directory containing code that will work with that particular version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top