You can define fields with custom names and values using meta tags on your web pages. The search API returns the names and values of the custom fields in search results, and you can filter the search results using them.
The maximum length of the custom field name is 256 characters. Please note that custom fields’ names may contain only the following characters:
[a-zA-Z0-9_-]
Additionally, the URL-encoded values of custom fields may only contain US ASCII characters (octets 0 – 127) except control characters or delimiters: ( "(" | ")" | "<" |
">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{" | "}"
| SPACE | TAB ).
Custom fields support the following data types:
For a specific custom field name, the data type will be locked after the first time the field is encountered by our crawler. Because of this, the data type of a custom field can not be changed at a later date. If you need to do this, change the name of the field as well. A custom field meta tag with an unrecognized data type value will be ignored.
To define custom fields on a web page, use addsearch-custom-field
meta tag as follows:
<html> <head> <meta name="description" content="This is a test page"/> <meta name="addsearch-custom-field" content="city=London"/> <meta name="addsearch-custom-field" content="genre=rock;genre=pop"/> <meta name="addsearch-custom-field" content="genre=hiphop"/> <meta name="addsearch-custom-field" data-type="text" content="description=This is a rock/pop event taking place in London"/> <meta name="addsearch-custom-field" data-type="date" content="event_date=2019-11-19"/> <meta name="addsearch-custom-field" data-type="integer" content="price_cents=599"/> <meta name="addsearch-custom-field" data-type="double" content="average_review=4.3"/> </head> <body> Lorem ipsum </body> </html>
You can assign multiple values to a single custom field name. Add multiple values to separate meta tags or combine multiple values by separating them with a semicolon.
Search results can be filtered against custom fields in the Search API and Separate results page.
In addition to meta tags, custom fields can be defined with HTTP headers. To define a custom field with an HTTP header, use the header Addsearch-Custom-Field
.
For example:
Addsearch-Custom-Field: genre:keyword=Rock%20%26%20Roll Addsearch-Custom-Field: genre=Rock%20%26%20Roll
Custom fields can also be combined in the same header:
Addsearch-Custom-Field: genre=Rock%20%26%20Roll, genre=Pop, band:keyword=Wham%21
Or in multiple headers:
Addsearch-Custom-Field: genre=Rock%20%26%20Roll, genre=Pop Addsearch-Custom-Field: band:keyword=Wham%21
We’re always happy to help with code or other questions you might have. Search our documentation, contact support, or connect with our sales team.