API¶
Parsing and constructing queries¶
This is the core of the library. A parser and the syntax tree definition.
luqum.parser¶
luqum.tree¶
Elements that will constitute the parse tree of a query.
You may use these items to build a tree representing a query, or get a tree as the result of parsing a query string.
-
class
luqum.tree.Item¶ Base class for all items that compose the parse tree.
An item is a part of a request.
-
children¶ As base of a tree structure, an item may have children
-
-
class
luqum.tree.SearchField(name, expr)¶ Indicate wich field the search expression operates on
eg: desc in
desc:(this OR that)Parameters: - name (str) – name of the field
- expr – the searched expression
-
children¶ the only child is the expression
-
class
luqum.tree.BaseGroup(expr)¶ Base class for group of expressions or field values
Parameters: expr – the expression inside parenthesis -
children¶ the only child is the expression
-
-
class
luqum.tree.Group(expr)¶ Group sub expressions
-
class
luqum.tree.FieldGroup(expr)¶ Group values for a query on a field
-
class
luqum.tree.Range(low, high, include_low=True, include_high=True)¶ A Range
Parameters: -
children¶ children are lower and higher bound expressions
-
-
class
luqum.tree.Term(value)¶ Base for terms
Parameters: value (str) – the value -
is_wildcard()¶ Return bool: True if value is the wildcard *
-
iter_wildcards()¶ list wildcards contained in value and their positions
-
split_wildcards()¶ split term on wildcards
-
has_wildcard()¶ Return bool: True if value contains a wildcards
-
-
class
luqum.tree.Phrase(value)¶ A phrase term, that is a sequence of words enclose in quotes
Parameters: value (str) – the value, including the quotes. Eg. '"my phrase"'
-
class
luqum.tree.Regex(value)¶ A regex term, that is a sequence of words enclose in slashes
Parameters: value (str) – the value, including the slashes. Eg. '/my regex/'
-
class
luqum.tree.BaseApprox¶ Base for approximations, that is fuzziness and proximity
-
children¶ As base of a tree structure, an item may have children
-
-
class
luqum.tree.Fuzzy(term, degree=None)¶ Fuzzy search on word
Parameters: - term (Word) – the approximated term
- degree – the degree which will be converted to
decimal.Decimal.
-
class
luqum.tree.Proximity(term, degree=None)¶ Proximity search on phrase
Parameters: - term (Phrase) – the approximated phrase
- degree – the degree which will be converted to
int().
-
class
luqum.tree.Boost(expr, force)¶ A term for boosting a value or a group there of
Parameters: - expr – the boosted expression
- force – boosting force, will be converted to
decimal.Decimal
-
children¶ The only child is the boosted expression
-
class
luqum.tree.BaseOperation(*operands)¶ Parent class for binary operations are binary operation used to join expressions, like OR and AND
Parameters: operands – expressions to apply operation on -
children¶ children are left and right expressions
-
-
class
luqum.tree.UnknownOperation(*operands)¶ Unknown Boolean operator.
Warning
This is used to represent implicit operations (ie: term:foo term:bar), as we cannot know for sure which operator should be used.
Lucene seem to use whatever operator was used before reaching that one, defaulting to AND, but we cannot know anything about this at parsing time…
See also
the
utils.UnknownOperationResolverto resolve those nodes to OR and AND
-
class
luqum.tree.OrOperation(*operands)¶ OR expression
-
class
luqum.tree.AndOperation(*operands)¶ AND expression
-
luqum.tree.create_operation(cls, a, b)¶ Create operation between a and b, merging if a or b is already an operation of same class
-
class
luqum.tree.Unary(a)¶ Parent class for unary operations
Parameters: a – the expression the operator applies on -
children¶ As base of a tree structure, an item may have children
-
-
class
luqum.tree.Plus(a)¶ plus, unary operation
-
class
luqum.tree.Not(a)¶
-
class
luqum.tree.Prohibit(a)¶ The negation
Utilities¶
luqum.naming: Naming query parts¶
luqum.pretty: Pretty printing¶
This module provides a pretty printer for lucene query tree.
-
class
luqum.pretty.Prettifier(indent=4, max_len=80, inline_ops=False)¶ Class to generate a pretty printer.
-
luqum.pretty.prettify= <luqum.pretty.Prettifier object>¶ prettify function with default parameters