This section provides you with detailed background information on the Fredhopper Query Language.
URL query string arguments
All Fredhopper query string arguments are prefixed with "fh_". In the table below, they are grouped by relevance, and a short explanation on each of them is provided.
| Parameter name | Values | Appearance | Description |
|---|---|---|---|
| fh_session | 0..1 | Session-ID in which the current request was triggered. Fredhopper does not use this information for its response but requires it for reporting purposes. | |
| fh_location | URL encoded location query //.... | 0..1 | Location query (see Location section) |
| fh_secondid | valid secondid | 0..N | Specifies the secondid (the fredhopper internal unique identifier) of an item to be displayed in the detail or compare page. For compare pages the second ids of all products are provided by multiple fh_secondid parameters. |
| fh_secondid2 | valid secondid | 0..1 | Specifies the secondid of a secondary item to be shown in combination with the primary item (specified using fh_secondid) on a detail page. This parameter overrides any (default) selection that would be done otherwise to determine the secondary item. |
| fh_view | "home", "summary", "lister", "detail", "compare", "search" | 0..1 | Specifies the page template if given, otherwise it will be automatically calculated based on the other query parameters. Also see an overview of the different types |
| fh_refview | previous view | 0..1 | The view of the page the user came from (for reporting) |
| fh_reftheme | previous theme | 0..1 | Previous promotion clicked by user (for reporting) |
| fh_reffacet | previous facet | 0..1 | Previous facet clicked by user (for reporting) |
| fh_refsearch | previous search term | 0..1 | In case of redirect this is the search term that caused the redirect |
| fh_oneslice | no value | 0..1 | Fredhopper appends this to facet links in case they lead to a single result and the business.xml has the setting for this redirect switched on |
| fh_start_index | Integer | 0..1 | Start item position in lister |
| fh_view_size | Integer / |
0..1 | Number of items to show in lister./ |
| fh_sort_by | attribute_type or $function_attribute_type | 0..1 | Sort items by attribute_type or function_attribute_type. Example: Sort descending by price fh_sort_by=-price. Multiple sort keys need to be separated by comma. |
| fh_log | 0 or absent | 0..1 | If you do not want a request to show up in the biz.log. Use this for example for the startupcrawler or in a publish script to check if the application started. Use fh_log=0 to not log requests. |
| fh_nothemes | set/unset | 0..1 | If present Fredhopper will not return any themes (campaigns) for the current query. |
| fh_allowed_modification | comma-separated list of modification types | 0..4 | Can be any combination of the following values: BLOCKING, REPLACING, MOVING, REDIRECTING. |
| fh_disable_redirect | true/false | If true, Fredhopper will suppress all search redirects for the current query. | |
| fh_facets | comma-separated list of facet IDs | 0..1 | Force the facets with the specified ids to be shown on top of the facet map regardless the rules set from the Business Manager. If the number of facets specified is less than the max number of facets configured, the list will be filled with the next facets from the normal facet list |
| fh_maxdisplaynrvalues_'facetName' | Integer | 0..1 | If present and equal to '-1' Fredhopper will return all possible values of the facet with name 'facetName'. |
|
fh_displayfields_mode |
preview live none |
0..1 |
Preview (only valid and set by default on a prepublished environment) - render preview display fields none- for each item render secondid field only |
| fh_anid | UUID | This id is generated by the tracker and allows the Recommendations service to relate the user to their previous activity. Note, however, that it is not random - it corresponds to the device fingerprint. (Since FAS 19.2) | |
| fh_app_id | String | Is used to identify the domain for the request and is the same you passed to the setUp call when configuring the tracker. (Since FAS 19.2) | |
| fh_user_seed | Integer (10,20,30... 90) | Is a uniformly random generated number intended to be used for A/B testing. Currently takes values 0, 10, 20, ... 90. (Since FAS 19.2) | |
| fh_session_id | String |
To request a variant of a given FHR page for a non-caching solution. |
|
| fh_abtests | String separated by a semicolon, with the A/B test ID and variant ID combinations separated by a colon |
To request a variant of a given FHR page for a caching solution. Should follow the format test-1:variant-for-test-1;test-2:variant-for-test-2;test-3:variant-for-test-3;... |
Some times FAS response contains more information than needed. For example, a user might navigate to the next page, so everything he/she need is the next batch of items. Yet, FAS will calculate and render facets, campaigns, etc. fh_suppress parameter tells FAS to ignore certain parts of a response. It makes queries faster and responses smaller and sharper.
Currently there are following possible values:
| Parameter name | Values | Appearance | Description | Since FAS Version |
|---|---|---|---|---|
| fh_suppress | facets:url-params | 0..1 | If present, link tags of filter sections in a response will not have the <url-params/> sub-tag. It can be used if a customer generates URL parameters for facets and does not need ones provided by FAS. Using this parameter can significantly reduce the response size. | 8.1.15 |
| fh_suppress | facets | 0..1 | If present, facets are not rendered. | 8.2.0 |
| fh_suppress | items | 0..1 | If present, items are not rendered. | 8.2.0 |
| fh_suppress | campaigns | 0..1 | If present, campaigns are not rendered. Equivalent to fh_nothemes=1 |
8.2.0 |
| fh_suppress | redirect | 0..1 | If present, will suppress all redirects for the current query. Equivalent to fh_disable_redirect=true |
8.2.0 |
| fh_suppress | modifications:all | 0..1 | If present, no result modifications will be applied to a current query. Equivalent to fh_allowed_modification= |
8.2.0 |
| fh_suppress | modifications:block | 0..1 | If present, no blocking result modifications will be applied to a current query. Equivalent to fh_allowed_modification=REPLACING,MOVING |
8.2.0 |
| fh_suppress | modifications:move | 0..1 | If present, no moving result modifications will be applied to a current query. Equivalent to fh_allowed_modification=REPLACING,BLOCKING |
8.2.0 |
| fh_suppress | modifications:replace-location | 0..1 | If present, no location replacement result modifications will be applied to a current query. Equivalent to fh_allowed_modification=MOVING,BLOCKING |
8.2.0 |
Examples
...&fh_suppress=redirect,facets --- FAS will not check if redirect is needed and will not render facets
...&fh_suppress=modifications:block,facets:url-params --- FAS will render facets, but leave URL parameters in facet sections empty. It will also not apply any blocking result modifications.
Note
It is recommended to use fh_suppress parameter instead of old arameters fh_allowed_modification, fh_disable_redirect and fh_nothemes when integrating with FAS 8.2 and onwards.
Location
A location query (or location string) is a constraint-based, textual representation of a selection of items and maps directly to a hypercube. As an additional filter it may contain a search term. A location string typically contains the universe in which the hypercube is located and the locale of the user, which maps to an availability dimension: only items of the universe available in the user's locale are acceptable. Queries in the Fredhopper system are in the form of an X-path like notation. The query is equal to a point or shape in the index.
| Selection | Basetype(s) | Description |
|---|---|---|
| attribute=value | set,int,float,text | attibute is equal to value |
| attribute<value | int,float,text | attribute is less than value |
| attribute>value | int,float,text | attribute is greater than or equal to value |
| value1<attribute<value2 | int,float,text | value1 <= atrribute < value2 |
| value1>attribute>value2 | int,float,text | value1 > attribute >= value2 |
| attribute={value1,value2,...} | set,list | attribute values are equal to value1 and value2 |
| attribute<{value1,value2,...} | set,list,hierarchical | attribute may contain any of value, value2,... |
| attribute>{value1,value2,...} | set,list | attribute contains all of value1, value2, ... The separator between values is "," |
| attribute>{value1;value2;...} | set,list | attribute contains at least one out of value1, value2, ... The separator between values is ";" |
A query can be negated by prefixing the selection with the '!' character, for example
!attribute=value to request items that have an attribute attribute that has not the value value.
Syntax of a search query criterion
/$s=search_term[;p=pass_id][;t=template_profile_id]
All special characters in the search term such as control characters, utf8 chars and delimiters must be criterion encoded: \uXXXX Where XXXX is the hexadecimal representation of the corresponding unicode code point. Delimiters are: @ !\"#$%&'()*+,-./:;<=>[]^{}|`~
| Character | Encoding |
|---|---|
| space | \u0020 |
| ! | \u0021 |
| " | \u0022 |
| # | \u0023 |
| / | \u002f |
| @ | \u0040 |
See the source code of UnicodeEncoder.java in file FAS/client/java/fredhopper-query-lang-*.src.zip for how to build this encoding.
Example queries
All examples are for universe products and English locale. Note: always prefix location queries with fh_location to make them valid. For example: fh_location=//catalog01/en_US/color=red.
Using triggers as attribute value(s) (since FAS 21.4)
Attribute values can be replaced with a custom trigger url parameter. The value will be resolved the trigger parameter value supplied as part of the request. If the trigger is not supplied, the respective selection will be ignored
| Selection | Description |
|---|---|
| attribute=[trigger_url_param;] | Single value selection with a trigger |
| attribute={[trigger_url_param;]} | Multiple value selection with trigger |
Example request:
http://<server>:<port>/preview?fh_location=catalog01/en_GB/attribute=[trigger_url_param;]&trigger_url_param=actual_value
Properly encoding a date criterion
As with a search query criterion, you need to encode certain utf8 characters: \uXXXX Where XXXX is the hexadecimal representation of the corresponding unicode code point. Delimiters are: @ !\"#$%&'()*+,-./:;<=>[]^{}|`~
The most important character you need to worry about is the colon ':' character, as it is used in the ISO 8601 date format, which FAS uses. Here's an example of a properly encoded date criterion:
/release_date>2021-10-08T13\u003A45\u003A00Z
You can alternatively convert the date to milliseconds since 00:00:00 UTC on 1 January 1970 and use that instead. The same example using milliseconds is
/release_date>1633700700000
| Basic queries | |
|---|---|
| Get all red products | //catalog01/en_US/color=red |
| Get all red products in category women | //catalog01/en_US/color=red/categories< {products_women} |
| Get all red products in category women and sub category shirts | //catalog01/en_US/color=red/categories< {products_women}/categories<{products_women_shirts} |
| Number queries | |
| Get all which are cheaper than 50 EUR | //catalog01/en_US/price<50 |
| Get all which are costs between 20 EUR (inclusive) and 50 EUR (exclusive) | //catalog01/en_US/20<price<50 |
| Set selections | |
| Get all products that red AND green (among others) | //catalog01/en_US/color>{red,green} |
| Get all products that have no other value than red or green. This query matches on items that are either red AND green, just red, just green or have no colour at all. | //catalog01/en_US/color<{red,green} |
| Get all products that are exactly red AND green (and no other colors) | //catalog01/en_US/color={red;green} |
| Get all products that red OR green | //catalog01/en_US/color>{red;green} |
| Geo queries | |
| Find all red products that are 50km around my current position (x=200, y=56). Fredhopper uses its attribute functions to perform geo searches. Attribute functions generate output based on one or more inputs. The following example uses the attribute function GeoFunction to launch a geo search. The Distance parameter is obligatory. | //catalog01/en_US/color=red/geo(200,56)<50 |
| Search queries | |
| Get all products that match on "ring" | //catalog01/en_US/$s=ring |
| Get all products that match on "säge" (German umlaut) | //catalog01/en_US/$s=s\u00E4ge |
| Get all products that match on "dvd player" (note the space) | //catalog01/en_US/$s=dvd\u0020player |
| Get all products that match on "ring" and are red (after search refinement) | //catalog01/en_US/$s=ring/color=red |
| Get all womens products that match on "ring" (scoped search). Make sure to include the precise location that defines the constrain. | //catalog01/en_US/categories<{products_women}/$s=ring |
| Get all products that match on "ring" using the "title" profile | //catalog01/en_US/$s=ring;t=title |
| Get all products that match on "ring" with "literal" search pass | //catalog01/en_US/$s=ring;p=literal |
| Get all products that match on "ring" using the "title" profile with literal search pass | //catalog01/en_US/$s=ring;p=literal;t=title |
| Category queries | |
| Fredhopper can express only Contains and Contains not for hierarchical attributes but a clearer wording would be Under. The query /cat<{A} means "give me the items that are under category A" which includes the items in all subcategories of A. Note that for hierarchical attributes you can't specify "I want the items from exactly this category". | |
| Contains A and B will give you all items that are under both A and B | /cat<{A}/cat<{B} |
| Contains A or B will give you all items that are under A or under B (note that here , means OR) | /cat<{A,B} |
| Contains not A and B will give you all items that not under both A and B | /!cat<{A}/!cat<{B} |
| Contains not A or B will give you all items that are not under A or under B. This syntax is valid but produces the same result as the one above | /!cat<{A,B} |
| Item queries | |
| Get only items x,y,z (be sure to include the "|" character) (product_id's, not variant id's) | //catalog01/en_US/|secondid<{x,y,z} |
| Get only items x,y,z and from which that are cheaper than 50 EUR | //catalog01/en_US/price<50|secondid<{x,y,z} |
| See Guildeline for using filter in Fredhopper Query Language for more information about the filter operator '|'. |
| To exclude items based on their ID create a new attribute (e.g. hide=1 or hide=0), and extend the selection in fh_location (e.g. //catalog01/en_US/hide=0). Consider to not load items into Fredhopper that should be removed from every request. |
EBNF
The location syntax is provided using EBNF
Location
location = "//", universe, "/", locale, {criterion} universe = universe-id; locale = language, "_", country; language = lcletter, lcletter; country = ucletter, ucletter; criterion = range-separator, range | filter-separator, filter | target-separator, target; range-separator = "/"; filter-separator = "|"; target-separator = ":"; range = search-range | navigation-range;
Navigation step
navigation-range = [negation], [[value], operator] attribute [operator, [value]]; value = single-value | multi-value; operator = element-operator | set-operator; element-operator = below | equals | above set-operator = contains | is-contained below = "<"; equals = "="; above = ">"; contains = "<"; is-contained = ">"; negation = "!"; attribute = attribute-id | attribute-function; attribute-function = [ "$" ], attribute-id, "(", function-arguments, ")"; function-arguments = [ function-argument [{",", function-argument}]]; single-value = value-id | number; multi-value = "{", single-value, {value-operator, single-value} "}"; value-operator = and-value-operator | or-value-operator; and-value-operator = ","; or-value-operator = ";";
Search step
search-range = "$s=", search-phrase, {search-predicate}; search-phrase = { unescaped-char | unicode-escaped-sequence }; unescaped-char = letter; unicode-escaped-sequence = "\u", hex-letter, hex-letter, hex-letter, hex-letter; search-predicate = search-profile-predicate | search-pass-predicate; search-profile-predicate = ";t=", identifier; search-pass-predicate = ";p=", identifier;
Relational item selection
target = special-attribute, order-operator, value [weight-operator, target-weight]; order-operator = closest-order-operator | farthest-order-operator; closest-order-operator = "˜"; farthest-order-operator = "%"; weight-operator = "!"; target-weight = signed-float;
Hand picked item selection
filter = [negation] secondid-filter | itemid-filter; secondid-filter = "secondid", contains, "{", item-id, {",", item-id}, "}"; itemid-filter = "itemid", contains, "{", nat-number, {",", nat-number}, "}";
Identifier and base values
item-id = { url-valid-char }
function-argument = { location-valid-char }
location-valid-char = letter | digit | location-valid-special-char;
location-valid-special-char = "!" | "#" | "$" | "*" | "+" | "-" | "." | ";" | "@" | "[" | "]" | "^" | "_" | "{" | "}" | "~";
url-valid-char = location-valid-char | "/" | ":" | "|" | "<" | ">" | "=" | "(" | ")" | ",";
universe-id = identifier
attribute-id = identifier
identifier = first-char-identifier, { nonfirst-char-identifier }
first-char-identifier = "_" | lcletter;
nonfirst-char-identifier = first-char-identifier | digit;
value-id = nonfirst-char-identifier, { nonfirst-char-identifier }
letter = lcletter | ucletter;
lcletter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" |
"m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
ucletter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" |
"M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
hex-letter = digit | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f";
number = nat-number | unsigned-float
integer = [sign], nat-number;
nat-number = digit, { digit };
float = signed-float;
signed-float = [sign], unsigned-float;
sign = "+" | "-";
unsigned-float = digit, {digit}, [".", {digit}];
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
Encoding
The Fredhopper Query Language library automatically encodes Fredhopper request in the right way.
To build manually the Fredhopper request:
- Encode the searchterm with the criterion encoding (see sample queries above - or Java source code in reference implementation)
- Combine it with other filters, e.g. brand selection to form the fh_location parameter value
- Encode each parameter value using URL encoding (using UTF-8 as charset)
- Join each parameter=encodedValue pair using &
For example to search for red products matching on "adidas shoes":
- Encode search term: adidas\u0020shoes
- Combine: //root/en_GB/$s=adidas\u0020shoes/color=red
- Encode: //root/en_GB/$s=adidas\u0020shoes/color=red (which is equivalent to %2f%2froot%2fen_GB%2f$s%2dadidas%5cu0020shoes%2fcolor%3dred)
- Join: fh_location=//root/en_GB/$s=adidas\u0020shoes/color=red&fh_view=lister (which is equivalent to fh_location=%2f%2froot%2fen_GB%2f$s%2dadidas%5cu0020shoes%2fcolor%3dred&fh_view=lister)
The Fredhopper output is always UTF-8 plain encoded.
FAQ
This section provides solutions to common integration questions related to the integration of Fredhopper.
Q: How do I implement search redirects?
A: The search redirect functionality can redirect the user to a catalogue location, or to a non-Fredhopper URL, triggered by a search query. When Fredhopper executes a search re-direct, please refer to the <redirect> element to integrate the result.
<page>
...
<redirect>
<redirect-host>server-name</redirect-host>
<redirect-port>port-number</redirect-port>
<redirect-url>http://www.example.com</redirect-url>
</redirect>
...
</page>
| Note that the <redirect> element is only returned for queries using the SOAP web service. For REST requests the response will use HTTP status code the request must include the 'User-Agent' HTTP request header field with exactly the value 'XML only client', otherwise the REST response will be a temporary redirect (HTTP response status code 302, redirect URL in the Location response header field.) |
Q: How do I remove a search from the breadcrumb?
A: In order to remove a search from the breadcrumb, remove the search parameter from the location string.
Comments
0 comments
Please sign in to leave a comment.