Custom Query Rules| Hitchhikers Platform

String of Numbers

You can target a 5-7 number string via RegEx (Regular expressions). Regular expressions allow you to search for a pattern of characters, and allows more flexibility when you’re looking for query matches. In this case, this query rule would surface a specific FAQ when a string of numbers is searched.

"rules": [
{
  "criteria": {
    "searchTermMatchesRegex": "\\b\\d{5,7}\\b"
  },
  "actions": [
    {
      "actionType": "BOOST_ENTITIES",
      "entityIds": [
        "FAQ-0"
      ],
      "verticalKey": "faqs"
    }
  ]
}


searchTermContains Multiple Search Terms

When writing query rules to prescibe search behavior, the searchTermContains criteria can be used to trigger a rule when the query contains defined terms. This will do a token match on the search term. If multiple tokens are included, it will make sure they are all present.

For example, the value ["Heart attack","911"] would trigger the rule in the case the query contains both “Heart attack” and “911”.

If, instead, you wanted to make the logic “or” (i.e., trigger the rule when at least 1 of the terms is in the query), you could use searchTermMatchesRegex, using | as an OR operator.

For example, putting the criteria below in the JSON of your query rule would trigger the query rule whenever a query contains “Heart attack” OR “911” (note: multiple terms, each separated by the | OR operater, can be added):

"criteria": {
    "searchTermMatchesRegex": [ ".*(heart attack|911).*"]
}

The result of this code is that the query rule would now be triggered on searches containing either “Heart attack” or “911”. For example, if the action associated with this rule was to boost urgent care locations, this action would be triggered for any of the following example searches:

  • “symptoms of a heart attack”
  • “when to call 911”
  • “should I call 911 if I am having a heart attack”

This can help you avoid having to write multiple query rules that trigger the same action.


Referrer URLs to Filter Location Results

To filter results to only those that pertain to the online location (ie. website) a user originates from, Query Rules can be use to detect the URL a user searched from, map it to a value of the custom field “Query Rules Location”, and filter the result set to only the entities that have that value populated in the custom field.

For example, take someone searching from a page on “https://location1.com/". We will see that a user searched from a page matching this subdomain, map that to the custom field value of “Location 1”, and filter the results such that only results with the field “Query Rules Location” containing “Location 1” appear in the results.

Steps:

1. Mapping URLs to the “Query Rules Locations” custom field

  • Create a custom field called “Query Rules Location” that has a multi-option selections for each location URL.

  • Within each entity type, select which Query Rule location the type falls under within the “Query Rules Location” field.

  • Once all of your locations are labeled correctly, also update the Query Rules Location custom field for all FAQs and Services and click on all the location options within the field. Note: This is so that all FAQs and Services will surface in the Answers experience for all location pages.

2. Create Saved Search Filters

  • In order to filter results in Query Rules based on the location page the user is searching from, we need to create saved search filters for each location page.

  • Within the knowledge graph, create an advanced filter with the following search criteria: Fields with Data includes any of Query Rules Location Query Rules Location includes Choose the Location you want to filter for

  • Apply filter and save the Filter.

3. Creating Query Rule in Search Configuration

Navigate to the Search COnfiguration and add the following:

"rules": [
  {
    "criteria": {
      "referrerPageURLRegex": "^.location1.com"
    },
    "actions": [
      {
        "actionType":"ADD_FILTER",
        "verticals": [
          "faqs", 
          "jobs", 
          "locations"
        ],
        "filter":{
          "savedFilterId":{
            "$eq":"21466424"
          }
        }
      }
    ]
  }
]
Feedback