One the options are set, create a parser and pass the options as argument
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl = QPL(options=options) |
With the instance created, create a query with any of the operator functions available
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl_query = qpl.or_(operands=qpl.terms(terms=['This', 'is', 'PyQPL'])) |
The qpl_query will be an object of type Operator, which will contain all the operators of the query. At this point the qpl query is truly engine agnostic, and it needs a translator to be an engine query
Operator Functions
The operator functions are listed bellow, each one have 1 o more examples, but they may not exemplify all the variations of types and formats the function can accept. Don't worry, the python code for this functions has defines all the types and formats each parameter can accept.
The parameter operands
refers to an Operator, string, number or list, it depends of the function you are using what allows
The fields
, boost
and slop
parameters are optional, since they have a default in QPLOptions, but if you want to overwrite that default an specific value
Term
One single term
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.term(term='one', fields=['title'], boost=1.0) |
Terms
Multiple terms, a simplification of term
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.terms(terms=['one', 'two'], fields=['title'], boost=1.0) |
Tip |
---|
Make sure the end search engine(s) to which this query will be translated supports terms |
Phrase
A literal phare
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.phrase(phrase='this is a phrase', fields=['title'], boost=1.0) |
Or
An "or" of one or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.or_(operands=qpl.term(term='one'))
qpl.or_(operands=[qpl.term(term='one'), qpl.term(term='two')]) |
And
An "and" of one or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.and_(operands=qpl.term(term='one'))
qpl.and_(operands=[qpl.term(term='one'), qpl.term(term='two')]) |
Not
A not of one or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.not_(operands=qpl.term(term='one'))
qpl.not_(operands=[qpl.term(term='one'), qpl.term(term='two')]) |
Range
A range of number with a start and an end
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.range(start=0.5, end=20, fields=['title'], boost=1.0) |
Date Range
A range of dates with a start and an end
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.date_range(start='27/12/22', end='22/06/23', fields=['title'], boost=1.0) |
Wildcard
A wildcard where * is zero or many and ? mean one character
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.wildcard(wildcard='*.py', fields=['title'], boost=1.0) |
Tip |
---|
The wildcard operator function does not required the wildcard option of QPLOptions in true, this option only applies for the parser |
Near
A near clause between 2 or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.near(operands=[qpl.or_(operands=[qpl.term(term='one'), qpl.term(term='two')])], fields=['title'], slop=10) |
Before
A before clause between 2 or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.before(operands=[qpl.or_(operands=[qpl.term(term='one'), qpl.term(term='two')])], fields=['title'], slop=2) |
Adjacent
A adjacent clause between 2 or more operands
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.adj(operands=[qpl.or_(operands=[qpl.term(term='one'), qpl.term(term='two')])], fields=['title'], slop=0) |
Span Not
A span not clause between a set of operands to include and a set of operands to exclude
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.span_not(include=qpl.term(term='one'), exclude=qpl.term(term='two'), fields=['title'], slop=0) |
Manually
specifiedSpecified Operator
There's also a manual way to specified the operator to use with the op function. This function is also the way to use custom operators, which will be address in the Custom Operator page
Code Block |
---|
language | py |
---|
theme | MidnightDJango |
---|
|
qpl.op(type_='term', operands='one', fields=['title'], boost=1.0) |