Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good python parser for a google-like search query?

For some search-based code (in Python), I need to write a query syntax parser that would parse a simple google like query syntax. For example:

all of these words "with this phrase" OR that OR this site:within.site filetype:ps from:lastweek

As search becomes more an more popular, I expected to be able to easily find a python library for doing this and thus avoid having to re-invent the wheel. Sadly, searches on google doesn't yield much.

What would you recommend as a python parsing library for this simple task?

like image 388
Boaz Avatar asked Mar 02 '10 16:03

Boaz


1 Answers

While ply is a more classical approach (a Pythonic variant of lexx + yacc) and thus may be easier to get started with if you're already familiar with such traditional tools, pyparsing is highly pythonic and would be my top recommendation, especially for such simple tasks (which are really more like lexing than "full-blown" parsing... at least until you want to allow possibly-nested parentheses, but pyparsing won't really be troubled by those either;-).

like image 67
Alex Martelli Avatar answered Sep 20 '22 07:09

Alex Martelli