Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

First Steps

The simplest PyQPL implementation could look like this

Basic PyQPL Usage

When using PyQPL your primary task will be defining a 


Code Block
languagepy
themeMidnight
from pyqpl.parser import QPLParser
from pyqpl.qpl import QPLOptions
from pyqpl.translator import ElasticsearchTranslator

options = QPLOptions(fields='content')
parser = QPLParser(options=options)
translator = ElasticsearchTranslator()

qpl_query = parser.parse_query('This is PyQPL')

engine_query = translator.to_engine_query(qpl_query)

print(qpl_query)
print(engine_query)

Copy that to a file main.py.

Execute the file, and the output of qpl_query, will be de text representation of the operand, returned by the parse_query function.

Code Block
or(terms(This,is,PyQPL))

While the engine_query, will be the engine specific query, return by the translator (an Elasticsearch translator in this case), after processing the qpl_query, ready to be sent to the search engine, or be modified later on

Code Block
{
  'multi_match': {
    'query': 'This is PyQPL',
    'fields': [
      'content'
    ]
  }
}
Info

The output above was indented for explanatory proposes 


Although the parse_query step can be replace with the manual creation of the query, the process will be the same

Code Block
languagepy
themeMidnight
from pyqpl.qpl import QPL, QPLOptions
from pyqpl.translator import ElasticsearchTranslator

options = QPLOptions(fields='content')
qpl = QPL(options=options)
translator = ElasticsearchTranslator()

qpl_query = qpl.or_(operands=qpl.terms(terms=['This', 'is', 'PyQPL']))

engine_query = translator.to_engine_query(qpl_query)

print(qpl_query)
print(engine_query)

Being the process:

  1. The definition of the QPLOptions
  2. The creation of a QPL query, regardless of the method used for it (Parsed or Manual)
  3. The Query Translation into an engine specific