rkQuery

Build Riak search queries safely and easily.
Download

rkQuery Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Public Domain
  • Price:
  • FREE
  • Publisher Name:
  • Zachary Voase
  • Publisher web site:
  • http://github.com/disturbyte/

rkQuery Tags


rkQuery Description

rkQuery is a Python 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.ExampleJust 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: >>>> q(field=q.range("red", "rum"))< q: field: >Note that the default is an inclusive range (square brackets). The full set of range queries:>>> q.range_inclusive("red", "rum")< q: >>>> 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 >Product's homepage


rkQuery Related Software