Skip to main content

Build Riak search queries safely and easily.

Project description

rkQuery is a library for programmatically building Riak search queries. It aims to be easy to use, powerful, and protect from injection attacks that would be possible with simple string interpolation.

Example

Just start playing around with the q object:

>>> from rkquery import q
>>> q("some literal")
<q: "some literal">
>>> q(field="literal value")
<q: field:"literal value">
>>> q.not_(blocked="yes")
<q: NOT blocked:"yes">

You can provide multiple arguments, too. The default query combinator is AND:

>>> q("word1", "word2")
<q: "word1" AND "word2">
>>> q(username='foo', password='s3cr3t')
<q: username:"foo" AND password:"s3cr3t">

This is just a synonym for q.all():

>>> q.all("word1", "word2")
<q: "word1" AND "word2">
>>> q.all(username='foo', password='s3cr3t')
<q: username:"foo" AND password:"s3cr3t">

Of course you can construct OR queries, using q.any():

>>> q.any("word1", "word2")
<q: "word1" OR "word2">
>>> q.any(username='foo', email='foo@example.com')
<q: username:"foo" OR email:"foo@example.com">
>>> q(field=q.any("string1", "string2"))
<q: field:("string1" OR "string2")>

Or by combining existing q objects:

>>> q.any("word1", "word2") & q("word3")
<q: ("word1" OR "word2") AND "word3">
>>> q.any(email="foo@example.com", username="foo") & q(password="s3cr3t")
<q: (email:"foo@example.com" OR username:"foo") AND password:"s3cr3t">

There are helpers for negation as well (note that ‘none’ means ‘not any’):

>>> q.none(blocked="yes", cheque_bounced="yes")
<q: NOT (blocked:"yes" OR cheque_bounced:"yes")>
>>> ~q.any(blocked="yes", cheque_bounced="yes")
<q: NOT (blocked:"yes" OR cheque_bounced:"yes")>

You can do range queries with q.range():

>>> q.range("red", "rum")
<q: ["red" TO "rum"]>
>>> q(field=q.range("red", "rum"))
<q: field:["red" TO "rum"]>

Note that the default is an inclusive range (square brackets). The full set of range queries:

>>> q.range_inclusive("red", "rum")
<q: ["red" TO "rum"]>
>>> q.range_exclusive("red", "rum")
<q: {"red" TO "rum"}>
>>> q.between("red", "rum")
<q: {"red" TO "rum"}>

Term boosting is a simple unary operation:

>>> q("red").boost(5)
<q: "red"^5>

As is proximity:

>>> q("See spot run").proximity(20)
<q: "See spot run"~20>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rkquery-0.0.1.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file rkquery-0.0.1.tar.gz.

File metadata

  • Download URL: rkquery-0.0.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rkquery-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7df25bda02c8c32f483b16e1474f712a0b59919eae442a98ded32e1904a07740
MD5 19fc18b13ec8e9eb562d3c5e04859367
BLAKE2b-256 548f6781c7985e147ded4fc729669e36951d0b269f2fb31595bac9fdd3a80f82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page