Show Menu
TOPICS×

About Query Cleaning Rules

Use Query Cleaning Rules to analyze and modify the incoming query.

Using Query Cleaning Rules

This feature is often used when you want to modify site search/merchandising behavior. For example, you could change a blank search to a popular keyword instead of a "*" search, thus promoting a popular product. You can also use query cleaning rules to perform a direct hit, where you redirect to a URL. This can be particularly useful when you detect that someone is searching for a product SKU and you want to skip the search and redirect to that product's page. Query Cleaning can also mine the query and set custom variables that can be used in later processing flow steps. Query cleaning rules are executed in sequence for every query. To alter the order of your rules you can use drag-and-drop. The actual order is not changed until you save it.
The query cleaning rules in a query cleaning module are examined to determine if any of the query parameters must be modified or if any custom variables must be set. Each query cleaning rule consists of two main elements: the rule's actions and optional conditions. An unlimited number of rules and conditions can be specified. The order of these rules is important, as site search/merchandising loops through the rule set rule by rule. When a rule's conditions match, all the associated actions are performed.
After query cleaning is completed, the resulting CGI parameters are used going forward. Any custom variables that were set are available for use by later stages in the processing flow. By default, the system automatically removes leading and trailing white space from the query term.

About Query Cleaning Conditions

Conditions are optional. If you decide that actions are specified for every query, the actions are always taken. Conditions can be based on any CGI query parameter, existing cookie, or custom variable that a previous rule has set. It is considered "best practice" for the first query cleaning rule to run for every query, where it defines and initializes all of the custom variables you plan to use.

About Query Cleaning Actions

All of the actions within a query cleaning rule that has matching conditions are exercised. Actions typically consist of an operation, the data on which to perform the operation, and the value to use.
See the table of options in Adding a query cleaning rule .

About Redirects

The Direct-Hits interface lets you define a set of redirects based on the incoming query term. Redirects within Query Cleaning extends this idea. However, redirects give you finer granularity on when a redirect takes place via specifying conditions and lets you redirect to a dynamic URL rather than a static URL. When you select the redirect action, the row is updated to have a text box where you specify the URL you would like to redirect to. In the URL, you can specify variables or parameters that you would like to substitute via enclosing them in double curly brackets. Custom variables are of higher precedence than CGI parameters in the substitution.

Examples

Assume you have a clothing retail store with a website. If the user clicks Search without any search terms, you want to return a search against jeans, because that's what you are internationally known for. You also want to parse the query term for a gender so that you can create a pre-search rule later, based on the custom variable that uses a different presentation template for each gender.
On condition: 
  query q equal 
Perform the following actions: 
  Set query parameter q to value jeans 
 
On condition: 
  Query q matches regular expression wom[e|a]n[s]|girl[s] 
Perform the following actions: 
  Add custom variable gender 
  Set custom variable gender to value female 
 
On condition: 
  Query q matches regular expression men[s]|boy[s] 
Perform the following actions: 
  Add custom variable gender 
  Set custom variable gender to value male

MegaElectronic is a large electronics store. From analyzing their search data, MegaElectronic has noticed that many their savvy customers often search for a product using the product's SKU, rather than returning a search result for the single product, MegaElectronic would like to redirect to the web page associated with that SKU.
On condition: 
  query q matches regular expression ^\D\D\D-\d\d\d\d$ 
Perform the following actions: 
  redirect to https://www.megaelectronic.com/?sku={{q}}

Adding a query cleaning rule

You can define rules that clean-up or edit the incoming search query from a customer.
You can only select templates that currently exist. If you do not have any templates, you must first define them.
To add a query cleaning rule
  1. On the product menu, click Rules > Query Cleaning .
  2. On the Query Cleaning Rules page, click Add New Rule .
  3. In the Name field, type the name of the new query cleaning rule.
  4. On the Add Query Cleaning Rule page, use the drop-down lists and text fields to build out your query.
    Option
    Description
    Cookie
    An HTTP cookie. You can define conditions based on cookies that are associated with your domain. Or, you can set a cookie that is written with outgoing search results. Cookies name and values must be Uniform Resource Identifier encoded.
    Custom Variable
    A user-defined variable. Add, delete, or set an unlimited amount of user-defined variables. You can reference any user-defined variables here within Pre-Search Rules and Post-Search Rules.
    System Variable
    Read-only variables set by the internal system that you can check. The following system variables are supported:
    • hostname
      The name of the server host.
    • uri
      The requested uri without the query string.
    • args
      The entire query string.
    • environment
      "Stage" or "live" depending on whether the incoming query was sent to your staged or live environment.
    • referrer
      The URL that the customer came from.
    • user agent
      The "user-agent" string of the customer's browser.
    Query Parameter
    CGI parameters passed to the query.
    Backend Parameter
    Incoming query parameters eventually get translated into backend parameters that are used to perform the search.
    Backend parameters do not show up on navigation elements. As a result, you can hide any additional parameters that you want to apply to a search from your customers. Actions on backend parameters are late-binding; that is, they are applied just before the search is sent.
    Facet
    Special CGI parameters associated with a given facet.
    Rank
    Lets you specify which ranking rule to use in the search. This option only appears when you have some ranking fields and ranking rules defined.
    Store
    The search engine automatically detects what store the user is in based on the host name or the gs_store query parameter, with the latter having precedence. You can create conditions off of the store. In query cleaning only, you can also use an action to over-ride the current store.
    Last Rule
    When the conditions are met for a rule that has last rule set, the query cleaning processing module does not perform any additional rules after the action of the matching rule. This is useful when you have set actions that will cause a later rule to match but you do not want the later rule to fire. Note that, if a rule's action is to perform a redirect, the redirect takes place immediately, so it essentially acts as if the last rule were set.
    Suspend
    Turns off the running of the rule but does not delete the rule.
  5. Click Add .
  6. (Optional) Do one of the following:

Editing a query cleaning rule

You can edit existing query cleaning rules that you have added to the Query Cleaning Rules page.
To edit a query cleaning rule
  1. On the product menu, click Rules > Query Cleaning .
  2. On the Query Cleaning Rules page, under the Actions column of the table, click Edit for the associated rule that you want to edit.
  3. On the Edit Query Cleaning Rule page, use the drop-down lists and text fields to build out your query.
    See the table of options under Adding a query cleaning rule .
  4. Click Save Changes .
  5. (Optional) Do one of the following:

Deleting a query cleaning rule

You can delete query cleaning rules that you no longer need or use.
When you delete a rule, the order that the remaining rules run is adjusted automatically to account for the deletion.
To delete a query cleaning rule
  1. On the product menu, click Rules > Query Cleaning .
  2. On the Query Cleaning Rules page, under the Actions column of the table, click Delete for the associated rule that you want to delete.
  3. In the Confirmation dialog box, click OK .
  4. (Optional) Do one of the following:

Changing the order that query cleaning rules run

You can reorder query cleaning rules to change the order in which they run on presentation templates.
Query cleaning rules run in the order that they were defined. The higher a rule's order number, the later it runs in the process, trumping earlier rules. You reorder rules by entering a new number in the Order column of the table on the Query Cleaning Rules page. You can also use drag-and-drop on rules to change their run order.
To change the order that query cleaning rules run
  1. On the product menu, click Rules > Query Cleaning .
  2. On the Query Cleaning Rules page, do one of the following:
    • Click the Order column header to sort the rules in ascending or descending order.
    • In the Order column, in the text field to the left of a query cleaning rule name, type the order number that you want the rule to run.
    • Drag-and-drop a table row to the position that you want the rule to run. All the order numbers are updated to reflect the new order in which the rules run.
  3. Click Save Changes .
  4. (Optional) Do one of the following: