Package: im-qsb
# im_qsbThis package provides methods for safely describing App Engine Search API Query as a json structure (a QSpec).You can construct a QSpec manually or by using the qsb_X methodsYou can render any QSpec to a Search API Query String using render_query_string()The github repo is [here](https://github.com/emlynoregan/im_qsb).[![Build Status](https://travis-ci.org/emlynoregan/im_qsb.svg?branch=master)](https://travis-ci.org/emlynoregan/im_qsb)## InstallUse the python package for this library. You can find the package online [here](https://pypi.org/project/im-qsb/).Change to your Python App Engine project's root folder and do the following:> pip install im_qsb --target libOr add it to your requirements.txt. You'll also need to set up vendoring, see [app engine vendoring instructions here](https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27).# QSpecA QSpec is a json structure for describing a Search Engine API query, which is converted to a querystring using the following rules:## string QSpec:qspec format: <string or unicode>renders to: quote delimited and escaped unicode string valueexample: 'Fred "Freddy" Frog' => u'"Fred \"Freddy\" Frog"'construct method: qsb_string(<string or unicode>)## number QSpec:qspec format: <number>renders to: a numeric valueexample: 47 => u'47'construct method: qsb_number(<number>)## boolean QSpec:qspec format: <boolean>renders to: '1' or '0'example: True => '1'construct method: qsb_boolean(<boolean>)## unquoted QSpec:qspec format: { "unquoted": <string or unicode> }renders to: an escaped but not quote delimited unicode string valueexample: { "unquoted": 'Fred "Freddy" Frog' } => u'Fred \"Freddy\" Frog'construct method: qsb_unquoted(<string or unicode>)## field QSpec:qspec format: { "fieldname": <string or unicode> }renders to: a valid fieldname, with invalid characters replaced with "_"example: 'first*name' => u'firse_name'construct method: qsb_field(<string or unicode>)## equality QSpecqspec format: { "op": "=", "field": <field QSpec>, "value": <QSpec> }renders to: an equality comparisonexample: {"op":"=", "field": {"fieldname":"name"}, "value": "Frodo"} => u'name:"Frodo"'construct method: qsb_eq(<field QSpec>, <QSpec>)## inequality QSpecqspec format: qspec format: { "op": "!=", "field": <field QSpec>, "value": <QSpec> }renders to: an inequality comparisonexample: {"op":"!=", "field": {"fieldname":"name"}, "value": "Frodo"} => u'NOT (name:"Frodo")'construct method: qsb_neq(<field QSpec>, <QSpec>)## paren QSpecqspec format: { "op": "paren", "arg": <QSpec> }renders to: wraps parens around a QSpecexample: {"op": "paren", "arg": 47} => u'(47)'construct method: qsb_paren(<QSpec>)## stem QSpecqspec format: { "op": "stem", "arg": <QSpec> }renders to: adds a stem to a QSpecexample: {"op": "stem", "arg": "Harry"} => u'~"Harry"'construct method: qsb_stem(<QSpec>)## less-than QSpecqspec format: { "op": "<", "field": <field QSpec>, "value": <QSpec> }renders to: a less-than comparisonexample: {"op":"<", "field": {"fieldname":"amount"}, "value": 43} => u'amount<43'construct method: qsb_lt(<field QSpec>, <QSpec>)## less-than-or-equal-to QSpecqspec format: { "op": "<=", "field": <field QSpec>, "value": <QSpec> }renders to: a less-than-or-equal-to comparisonexample: {"op":"<=", "field": {"fieldname":"amount"}, "value": 47.2} => u'amount<=47.2'construct method: qsb_le(<field QSpec>, <QSpec>)## greater-than QSpecqspec format: { "op": ">", "field": <field QSpec>, "value": <QSpec> }renders to: a greater-than comparisonexample: {"op":">", "field": {"fieldname":"amount"}, "value": -1} => u'amount>-1'construct method: qsb_gt(<field QSpec>, <QSpec>)## greater-than-or-equal-to QSpecqspec format: { "op": ">=", "field": <field QSpec>, "value": <QSpec> }renders to: a greater-than-or-equal-to comparisonexample: {"op":">=", "field": {"fieldname":"amount"}, "value": 0} => u'amount>=0'construct method: qsb_ge(<field QSpec>, <QSpec>)## and QSpecqspec format: { "op": "AND", args: [<list of QSpec>] }renders to: a space separated list of QSpecs, which is a valid way to express AND relationships.example: {"op":"AND", "args": ["X", "Y", "Z"] => u'"X" "Y" "Z"'construct method: qsb_and(<QSpec>, ...)## or QSpecqspec format: { "op": "OR", args: [<list of QSpec>] }renders to: an OR separated list of QSpecs.example: {"op":"OR", "args": ["noodle", {"quoted": "poodle"}]} => u'"noodle" OR poodle'construct method: qsb_or(<QSpec>, ...)## not QSpecqspec format: { "op": "NOT", arg: <QSpec> }renders to: a negation of a QSpecs.example: {"op":"NOT", "args":"noodle"} => u'NOT "noodle"'construct method: qsb_not(<QSpec>)## geopoint QSpecqspec format: { "op": "geopoint", left: <number QSpec>, right: <number QSpec> }renders to: a geopoint specificationexample: {"op":"geopoint", "left": 12, "right": 42.7} => u'geopoint(12,42.7)'construct method: qsb_geopoint(<number QSpec>, <number QSpec>)## distance QSpecqspec format: { "op": "distance", left: <QSpec>, right: <QSpec> }renders to: a distance specificationexample: {"op": "distance", "left": {"op":"geopoint", "left": 12, "right": 42.7}, "right": {"fieldname": "home"}}=> u'distance(geopoint(12,42.7),home)'construct method: qsb_distance(<QSpec>, <QSpec>)## rendered QSpecqspec format: { "rendered": <Querystring> }renders to: the pre-rendered querystringexample: {"rendered": "userid: 1234"} => u'userid: 1234'construct method: qsb_rendered(<Querystring>)