This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Easily create Lucene query strings without having to learn the language itself. The syntax is simple to use and allows creating larger queries from multiple smaller ones. A basic lesson on proper Lucene queries can be found here.

Supports Python 2.6+.

Getting Started

>>> from lucenequerybuilder import Q

Creating Queries

A basic query can be given by passing in a string into Q’s constructor.

>>> q = Q('a')
>>> q = Q('The quick brown fox')

The query builder will automatically detect whether a term (no whitespace) or a phrase (multiple terms together seaparated by whitespace) and properly bound them with quotation marks.

All terms and phrases are expected to be unescaped, and will be escaped:

>>> q = Q(r'The *quick* brown (fox)')

>>> str(q)

'"The \\*quick\\* brown \\(fox\\)"'

Range Queries

Ranges are also easy to put into a query. There are two types of range queries, inclusive range and exclusive range. These are passed into the query builder with keyword arguments.

>>> q = Q(inrange=(1,5))
>>> q = Q(exrange=['egg','hgg'])

Ranges will work with any list-like object of length 2.

Chaining Queries

You can chain queries with & (AND), | (OR), & ~ (AND NOT), + (MUST), and - (MUST NOT). AND, OR, and AND NOT require a query before and after it shows up. MUST and MUST NOT only work on the query directly afterwards. Some examples are below:

>>> q = Q('a') & Q('b')

>>> q = Q('a') & ~Q('b')

>>> q = +Q('a') -Q('b')

Nested Queries

Queries can be nested inside of each other to create new queries. This makes it easy to group queries together. Examples below:

>>> q = Q(Q('a') & Q('b')) & ~Q('c')

>>> q = Q(Q(Q('a') | Q(inrange=[1,2])) +Q('c))

Fields

Fields can be added to queries by putting in a field as your first argument. Fields cannot have any whitespace and cannot be nested inside each other. The following examples are valid queries:

>>> q = Q('name', 'Edward')

>>> q = Q('text', 'Mary had a little lamb')

>>> q = Q('age', inrange=[10, 9001])

The following examples are invalid queries which will raise an error:

>>> q = Q('name', Q('lastname', 'Purcell'))

>>> q = Q('bad', Q('range', inrange=[10, 9001]))

Fuzzy Queries

A fuzzy term query can be accomplished using the fuzzy keyword:

>>> q = Q('name', fuzzy=('edd', .2))

>>> str(q)

'name:(edd~0.200)'

The first element in the fuzzy tuple is the term, and the second is the similarity ratio- a float, str, or decimal between 0 and 1.

If you drop the second element, and just provide a str, the string will signify to use Lucene’s default ratio - 0.5:

>>> q = Q('name', fuzzy='edd')

>>> str(q)

'name:(edd~)'

Wildcard Queries

To keep wildcard queries from having ‘?’ and ‘*’ from being escaped, simple include the wildcard flag:

>>> str(Q('c?t', wildcard=True))

'c?t'

which will match ‘cat’ or ‘cot’.

Boosting & Wildcard Queries

These queries are not yet supported, but will be soon. Feel free to add support yourself and request a pull!

Release History

Release History

0.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
lucene-querybuilder-0.2.tar.gz (6.9 kB) Copy SHA256 Checksum SHA256 Source Aug 12, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting