Guides / Managing results / Rules / Merchandising

Adding Search Parameters with JSON Templates

The Visual Editor helps with applying filters within Rules, but you still may need to write JSON to add query parameters (string filters). For example, to add default search parameters with Rules.

This guide shows JSON “templates” for common scenarios that you can adapt to your needs by changing the ATTRIBUTEVALUE pairing to match your data. For example, in an online library, you can set ATTRIBUTE to author and VALUE to 'William Shakespeare' to boost results in the “Shakespeare” category.

Filters

Scenario JSON template
Select a category { "filters":"ATTRIBUTE:VALUE" }
Remove a category { "filters":"NOT ATTRIBUTE:VALUE" }
Remove several categories { "filters":"NOT ATTRIBUTE:VALUE AND NOT ATTRIBUTE:VALUE" }

If you have a multi-word VALUE (such as William Shakespeare), wrap it in single quotes. For example:

1
2
3
{
  "filters":"NOT author:'William Shakespeare' AND NOT author:Plato"
}

If your VALUE contains an apostrophe (such as Tony d’Arbon), prefix the apostrophe with double backslashes and wrap the whole string in single quotes. For example:

1
2
3
{
  "filters":"NOT author:'William Shakespeare' AND NOT author:'Tony d\\'Arbon'"
}

Optional filters

You use filters to exclude non-matching records but use optional filters to either promote or demote records in the search ranking by applying filter scoring. For example, you might want to boost the popularity of books written by John Doe, or, alternatively, bury books not written by John Doe.

If you want to use an attribute as an optional filter, declare it as a facet.

ScenarioJSON templateFilter scoring on affected records
Promote a category {
  "optionalFilters":
    ["ATTRIBUTE:VALUE"]
}
+1
Promote several categories (equally) {
  "optionalFilters":
    ["ATTRIBUTE1:VALUE1",
    "ATTRIBUTE2:VALUE2"]
}
+1 for all records matching one or more filters
Promote several categories (with specified scoring 'weighting' for each) {
  "optionalFilters":
    ["ATTRIBUTE1:VALUE1<score=X>",
    "ATTRIBUTE2:VALUE2<score=Y>"]
}
+X or +Y (whichever matches and has the highest value)
Promote several categories (with a combined score) {
  "optionalFilters":
    "[ATTRIBUTE1:VALUE1",
    "ATTRIBUTE2:VALUE2"],
  "sumOrFiltersScores" :true
}
+1 or +2 depending on the number of filters that match
Promote several categories (with combined weighting) {
  "optionalFilters":
    ["ATTRIBUTE1:VALUE1<score=X>",
    "ATTRIBUTE2:VALUE2<score=Y>"],
  "sumOrFiltersScores" : true
}
+X, +Y, or +X+Y depending on the matching filters
Demote a category {
  "optionalFilters":
    ["ATTRIBUTE:-VALUE"]
}
+1 for all records that don't match the filter
Demote several categories (equally) {
  "optionalFilters":
    ["ATTRIBUTE1:-VALUE1",
    "ATTRIBUTE2:-VALUE2"]
}
+1 for all records that don't match any filter

Unlike filters, you don’t need to wrap a multi-word VALUE with single quotes if it contains spaces. For example:

1
2
3
4
5
6
7
8
9
{
  "optionalFilters":[
    [
      "author:William Shakespeare<score=3>",
      "author:John Doe<score=2>"
    ]
  ],
  "sumOrFiltersScores":true
}
Did you find this page helpful?