5

I need to parse terms and operators from a lucene query in python.

The syntax is described here: http://lucene.apache.org/core/2_9_4/queryparsersyntax.html

For example, I'd like to get the terms and operators from a query like this:

title:"The Right Way" AND text:go

Are there any existing modules with parsers for lucene queries in python?

I could write a parser using ply or pyparse, but I'd like to know if one exists already or if there are alternative solutions.

4
  • metaoptimize.com/blog/2010/08/09/… Commented Sep 6, 2013 at 17:14
  • Thanks, but I was looking for more of a pure python implementation. Pylucene depends on Java being installed. I use ElasticSearch for my search engine and communicate with it through http requests. Commented Sep 6, 2013 at 17:25
  • 1
    ElasticSearch should handle the query parsing for you, using a query_string query, or similar. Commented Sep 6, 2013 at 19:06
  • I do use a query_string query for search, but want to access the terms searched for in a query on the application side without necessarily executing a query. Commented Sep 6, 2013 at 22:23

1 Answer 1

5

pyparsing offers the lucene parser in the examples folder. pyparsing is written in pure Python without external dependencies. This seems to be the most solid implementation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.