The properties that where defined at a given Querqy rule are considered a
JSON document and a rule filter matches the rule if the JsonPath expression
matches this JSON document. What follows is a list of examples that relate to
the above rule definitions:
* ``$[?(@.enabled == true)]`` matches ID2 but not ID1
* ``$[?(@.group == 'electronics')]`` matches ID1 but not ID2
* ``$[?(@.priority > 5)]`` matches ID2 but not ID1
* ``$[?('t1' in @.tenant)]`` matches ID1 but not ID2
* ``$[?(@.priority > 1 && @.culture)].culture[?(@.lang=='en)]`` matches ID2
but not ID1. The expression ``[?(@.priority > 1 && @.culture)]`` first
tests for priority > 1 (both rules matching) and then for the existence of
'culture', which only matches ID2. Then the 'lang' property of 'culture' is
tested for matching 'en'.
.. rst-class:: solr
.. raw:: html
If more than one 'filter' request parameters are passed to a Common Rules
Rewriter, a rule must match all filters to get applied.
.. raw:: html
.. rubric:: Using properties for info logging
Querqy rewriters can emit info log messages that can be directed to various
log message sinks. If configured, the Common Rules Rewriter will emit the value
of the ``_log`` property as a log message. If this property is not defined,
it will use the value of ``_id`` property and fall back to an auto-generated
id if the '_id' property also wasn't specified.
.. include:: hint-rewrite-chain.txt
Reference
=========
Configuration
-------------
.. tabs::
.. group-tab:: Elasticsearch/OpenSearch
``PUT /_querqy/rewriter/common_rules``
.. code-block:: JSON
:linenos:
{
"class": "querqy.elasticsearch.rewriter.SimpleCommonRulesRewriterFactory",
"config": {
"rules" : "notebook =>\nSYNONYM: laptop",
"ignoreCase": true,
"querqyParser": "querqy.rewrite.commonrules.WhiteSpaceQuerqyParserFactory"
}
}
rules
The rule definitions
Default: (empty = no rules)
ignoreCase
Ignore case in input matching for rules?
Default: ``true``
querqyParser
The querqy.rewrite.commonrules.QuerqyParserFactory to use for parsing strings
from the right-hand side of rules into query objects
Default: ``querqy.rewrite.commonrules.WhiteSpaceQuerqyParserFactory``
.. group-tab:: Solr
**Querqy 5**
.. code-block:: JSON
{
"class": "querqy.solr.rewriter.commonrules.CommonRulesRewriterFactory",
"config": {
"rules" : "notebook =>\nSYNONYM: laptop",
"ignoreCase" : true,
"buildTermCache": true,
"boostMethod": "MULTIPLICATIVE",
"allowBooleanInput": true,
"querqyParser": "querqy.rewrite.commonrules.WhiteSpaceQuerqyParserFactory"
}
}
**Querqy 4**
.. code-block:: xml
querqy.solr.SimpleCommonRulesRewriterFactory
rules.txt
true
true
MULTIPLICATIVE
querqy.rewrite.commonrules.WhiteSpaceQuerqyParserFactory
rules
*Querqy 5*: A property containing the rules for rewriting. Remember to escape
the rules for JSON.
*Querqy 4*: The rule definitions file containing the rules for rewriting. The
file is kept in the configset of the collection in ZooKeeper (SolrCloud) or in
the 'conf' folder of the Solr core in standalone or master-slave Solr.
Note that the default maximum file size in ZooKeeper is 1 MB. For Querqy 4,
the file can be gzipped. Querqy will auto-detect whether the file is
compressed, regardless of the file name. Querqy 5 will compress and split
files automatically.
Required.
ignoreCase
Ignore case in input matching for rules?
Default: ``true``
buildTermCache
Whether to build a term cache from matching terms. This is a optimization
that might not be feasable for very large rule lists.
Default: ``true``
boostMethod
*Querqy 5.4*: How to combine UP/DOWN boosts with the score of the main user
query. Available methods are ADDITIVE and MULTIPLICATIVE.
Default: ``ADDITIVE``
allowBooleanInput
*Querqy 5.0*: Whether to interpret the rule input definitions as boolean
expressions.
Default: ``false``
querqyParser
The querqy.rewrite.commonrules.QuerqyParserFactory to use for parsing strings
from the right-hand side of rules into query objects
Default: ``querqy.rewrite.commonrules.WhiteSpaceQuerqyParserFactory``
Request
-------
.. tabs::
.. group-tab:: Elasticsearch/OpenSearch
.. code-block:: JSON
:linenos:
:emphasize-lines: 8-13
{
"query": {
"querqy": {
"rewriters": [
{
"name": "common_rules",
"params": {
"criteria": {
"filter": "",
"sort": "",
"limit": 1,
"limitByLevel": true
}
}
}
]
}
}
}
.. group-tab:: Solr
Parameters must be prefixed by ``querqy..``
Example: ``querqy.common1.criteria.sort=priority desc`` - set 'criteria.sort'
for rewriter 'common1'.
criteria.filter
Only apply rules that match the filter. A JsonPath_ expression that is
evaluated against JSON documents that are created from the properties of the
rules.
Default: (not set)
criteria.sort
Sort rules by a rule property in ascending or descending order
' )
Default: (not set - rules are sorted in the order of definition)
criteria.limit
The number of rules to apply after sorting
Default: (not set - apply all rules)
criteria.limitByLevel
If ``true``, rules having the same sort property value are counted only once
towards the ``limit``.
Default: ``false``
.. _`JsonPath`: https://github.com/json-path/JsonPath