Package: csquery
A simple query builder for Amazon Cloudsearch Structured query parser.FeaturesCautionSet upUsagePython SupportLicenseAuthorsContributorsHistoryFeaturesProvide a simple query builder for Amazon Cloudsearch Structured query parser.Please refer to the following link regardingStructured Search Syntax.http://docs.aws.amazon.com/cloudsearch/latest/developerguide/search-api.htmlCautionAt the moment, this library is compatible only toStructured Search Syntax.It does not have any plans corresponding to the other query parser(lucene, dismax, simple).If you want the lucene query builder, it’s a good idea is to use the following library.https://pypi.python.org/pypi/lucene-querybuilderThis library does not handle to generate queries that are not related toStructured Search Syntax. Ex) size, facets …Set upMake environment with pip:$ pip install csqueryUsageandSyntax: (and boost=N EXPRESSION EXPRESSION … EXPRESSIONn)fromcsquery.structuredimportand_,fieldq=and_(title='star',actors='Harrison Ford',year=('',2000))q()#=> (and title:'star' actors:'Harrison Ford' year:{,2000])# with optionq=and_({'title':'star'},{'title':'star2'},boost=2)q()#=> (and boost=2 title:'star' title:'star2')# another writingand_({'title':'star'},{'actors':'Harrison Ford'},{'year':('',2000)})and_(field('star','title'),field('Harrison Ford','actors'),field(('',2000),'year'))orSyntax: (or boost=N EXPRESSION1 EXPRESSION2 … EXPRESSIONn)fromcsquery.structuredimportor_,fieldq=or_(title='star',actors='Harrison Ford',year=('',2000))q()#=> (or title:'star' actors:'Harrison Ford' year:{,2000])# with optionq=or_({'title':'star'},{'title':'star2'},boost=2)q()#=> (or boost=2 title:'star' title:'star2')notSyntax: (not boost=N EXPRESSION)fromcsquery.structuredimportnot_,and_q=not_(and_(actors='Harrison Ford',year=('',2010)))q()#=> (not (and actors:'Harrison Ford' year:{,2010]))# with optionq=not_(and_(actors='Harrison Ford',year=('',2010)),boost=2)q()#=> (not boost=2 (and actors:'Harrison Ford' year:{,2010]))nearSyntax: (near field=FIELD distance=N boost=N ‘STRING’)fromcsquery.structuredimportnearq=near('teenage vampire',boost=2,field='plot',distance=2)q()#=> (near field=plot distance=2 boost=2 'teenage vampire')phraseSyntax: (phrase field=FIELD boost=N ‘STRING’)fromcsquery.structuredimportphraseq=phrase('star',boost=2,field='title')q()#=> (phrase field=title boost=2 'star')prefixSyntax: (prefix field=FIELD boost=N ‘STRING’)fromcsquery.structuredimportprefixq=prefix('star',boost=2,field='title')q()#=> (prefix field=title boost=2 'star')rangeSyntax: (range field=FIELD boost=N RANGE)fromcsquery.structuredimportrange_q=range_((1990,2000))q()#=> (range [1990,2000])q=range_((None,2000))q()#=> (range {,2000])q=range_((1990,))q()#=> (range [1990,})# with opitionq=range_((1990,2000),field='date',boost=2)q()#=> (range field=date boost=2 [1990,2000])# another writingq=range_('[1990,2000]')q()#=> (range [1990,2000])q=range_(('',2000))q()#=> (range {,2000])q=range_('{,2000]')q()#=> (range {,2000])q=range_((1990,None))q()#=> (range [1990,})q=range_((1990,''))q()#=> (range [1990,})q=range_('[1990,}')q()#=> (range [1990,})termSyntax: (term field=FIELD boost=N ‘STRING’|VALUE)fromcsquery.structuredimporttermq=term(2000,field='year',boost=2)q()#=> (term field=year boost=2 2000)q=term('star',field='title',boost=2)q()#=> (term field=title boost=2 'star')Complex query samplefromcsquery.structuredimportand_,or_,not_,termq=and_(not_('test',field='genres'),or_(term('star',field='title',boost=2),term('star',field='plot')))q()#=> (and (not field=genres 'test') (or (term field=title boost=2 'star') (term field=plot 'star')))Using with botohttp://boto.readthedocs.org/en/latest/ref/cloudsearch2.htmlfromcsquery.structuredimportand_fromboto.cloudsearch2.layer2importLayer2conn=Layer2(region='ap-northeast-1',aws_access_key_id=[AWSACCESSSKEYID],aws_secret_access_key=[AWSSECRETKEY],)domain=conn.lookup('search_domain_name')search_service=domain.get_search_service()q=and_(title='star',actors='Harrison Ford',year=('',2000))result=search_service.search(q=q(),parser='structured')Python SupportPython 2.7, 3,3, 3.4 or later.LicenseSource code of this library Licensed under the MIT License.See the LICENSE.rst file for specific terms.Authorstell-k <ffk2005 at gmail.com>ContributorsThanks.@podhmo@furiHistory0.1.4(Nov 25, 2015)Fixed unquoted field value.#4.0.1.3(Nov 20, 2015)Fixed over escaped expression.#3.0.1.2(Nov 18, 2015)Fixed escape bug.#2.0.1.1(Nov 6, 2015)Fixed bug.#1.0.1.0(Jun 8, 2015)First release