rkQuery
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>
Release files for rkquery 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rkquery-0.0.1.tar.gz | 5.2 kB | Details |
Release files / rkquery-0.0.1.tar.gz
| Download URL | rkquery-0.0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7df25bda02c8c32f483b16e1474f712a0b59919eae442a98ded32e1904a07740
|
|
BLAKE2b-256 checksum How to use checksums |
548f6781c7985e147ded4fc729669e36951d0b269f2fb31595bac9fdd3a80f82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |