Query Rules let you make precise, predetermined changes to your search results or search queries, thus allowing you to enhance search experience. For example, you can reposition items in a user’s search results or activate filters based on query terms. Rules can also be enabled for a fixed period of time: this makes Rules a great way of implementing sales or promotions. Query Rules are essentially
If-This-Then-That construct - If search query contains 'Google', then
promote 'Chromebook'. Query Rules serve a very specific purpose as far as search results and merchandising is concerned. When building a commercial search product, customers more often than not require commercializing the product based on certain search queries.
Query rules are available with Production I, II, III and IV cluster plans or with the Enterprise Plan for Self Hosted Appbase.io.
Here are some use cases where Query Rules can help you improve search relevance
- Dynamically update facets based on query. Example if a user is searching for "laptops", show filters related laptops only
- Promote result during discounts / sale on your store
- Hide products that are not available
- Hide irrelevant results
- Replace search term based on data available
If conditions helps in deciding when to trigger a query rule based on which configured actions will be executed. There are 2 types of trigger
This is helpful when you want to execute an action with all the search request. Example you want to always hide a product which is no longer available in store.
This is helpful when you want to execute an action with specific search / filter condition. Example if query
containsa specific search term. There are 4 types of search condition which you can configure
Query is: applied when there is an exact query match
Query contains: applied when a search query contains the specified query
Query starts with: applied when a search query starts with the specified query
Query ends with: applied when a search query ends with the specified query
Here, you can also configure filter condition, which can help you set trigger based on filtering field and value. Example, `brand` is `apple`.
You can also configure rules for specific
indexes in your ElasticSearch cluster and for a specific
time period (example you only want to promote result for a seasonal sale on your ecommerce store ). By default, it is applicable on all the indexes and all the time.
Query Rules also comes with an advanced editor that allows writing truly expressive trigger conditions. A condition is of the form "
$value". It also allows combining conditions with AND/OR and ( ... ) clauses.
A condition can be expressed using one of the following operators. Each operator operates on the
||The field's value set by the search query should exactly match the provided value.|
||The field's value set by the search query should not match the provided value.|
||The provided value is contained within the field's value set by the search query.|
||The provided value is not contained within the field's value set by the search query.|
||The field's value as set by the search query starts with the provided value.|
||The field's value as set by the search query does not start with the provided value.|
||The field's value as set by the search query ends with the provided value.|
||The field's value as set by the search query does not end with the provided value.|
||Provide a regular expression to match the field's value as set by the search query with the provided value.|
Here are some example conditions:
$query exactlyMatches "iphone x"
$query contains "iphone x" AND $query doesNotContain "iphone 8"
$query contains "smart phone" AND brand exactlyMatches "apple"
$query contains "smart phone" AND (brand exactlyMatches "apple" OR brand exactlyMatches "samsung")
Then actions help you configure the actions that you want to invoke when triggering conditions are matched. Following are the actions that you can invoke
Note: Actions are executed in the order in which are the listed in your dashboard. You can drag and drop to change the sequence of executing actions.
Helps in promoting result at certain position in your result set. Example when a user searches for
iphone you want to promote
Helps in hiding certain results from getting included in the actual search results. Example you want to hide products that not available in the store, or you want to hide results that contains irrelevant data.
Helps in sending the custom
JSON data in search response. This will be helpful when you want to send some extra information to frontend, which can help in rendering more specific information.
Helps in replacing the user’s entire search query with another query. Helps in showing relevant results to users, specially when you are aware from the analytics that certain search term is returning no results.
Removing words is the progressive loosening of query constraints to include more results when none are initially found.
For example, imagine an online smartphone shop that sold a limited inventory of iPhones in only 16GB and 32GB varieties. Users searching for “iphone 5 64gb” would see no results. This is not ideal behavior - it would be far better to show users some iPhone 5 results instead of a blank page.
You can remove multiple words by space separated values. E.g.
Rules offers an alternative. You can now replace words instead of adding new ones. For example, if you make
tv a synonym for
television, Rules will replace
television so that only
television is used to search.
Helps in doing more customization with search or handling edge cases around search relevancy. Functions lets you implement any custom action. Example you want to perform natural language processing on search query.
For more information you can read functions docs.
Note: a function linked with Query Rule cannot have its own triggering condition.