Note: When implementing search using REST API, you need to report clicks made by users to the following endpoint. Information about users’ clicks is required for detailed analytics reports. It also allows AddSearch to apply progressive ranking which improves the search results relevancy.
GET /v1/search/{index public key}
Retrieve search results from the index.
Parameter | Description | Type |
---|---|---|
term | Search term, also known as the keyword. Use * to get all search results instead | string |
Parameter | Description | Type | Notes |
---|---|---|---|
limit | The number of results to return per page | int | Must be between 1 and 300. The default is 10. |
page | The number of the paginated result page to return | int | The default is 1. |
jsonp | JavaScript function call wrapped around the response JSON | string | JSONP (JSON with Padding) is used for sending JSON data which helps to resolve cross-domain issues. By default, all results are returned. |
lang | Limit results to a specific language | string | Should be in two-letter language format, e.g. “en”, “de”, “es”. For more information, visit the documentation. By default, all results are returned. |
categories | Limit results to a domain, URL path, or filetype | string | For more information, visit the documentation on the categories. Example of categories parameter. By default, all results are returned. |
sort | Return results sorted by relevance, date, or custom field names | string | Valid values: “relevance”, “date” or a name of a custom field e.g. custom_fields.average_rating. The default is “relevance”. |
order | Return results sorted by date or custom fields in ascending or descending order | string | Valid values: “desc” or “asc”. Applicable if “sort=date” or "sort=customField". The default is “desc”. |
fuzzy | Matches words that are close to the search terms | string | Valid values: “false” (disabled), “true” (enabled), or “auto” (automatic). The suggested value is “auto.” The default is “false”. |
postfixWildcard | Adds a wildcard at the end of the search term and is ideal for the search-as-you-type feature | boolean | Set it to false if you want to emphasise exact matches (you will get less results and better highlights). The default is true. |
dateFrom | Return only results that are newer than the specified date | string | The format is yyyy-mm-dd (example: 2020-11-01). By default, all results are returned. |
dateTo | Return only results older than the specified date | string | The format is yyyy-mm-dd (example: 2020-11-01). By default, all results are returned. |
customField | Return only results containing the specified custom field and value pair | string | The format is “key=value” and the format in query parameter needs to be URL encoded e.g. key%3Dvalue. If the same custom field name is given with different values, results with any value will be returned (i.e. OR match). If multiple custom field names are defined, results must match each criterion. For more information, visit the documentation. Example of customField parameter. By default, all results are returned. |
resultType | Return only results with- or without Pinned results and Promotions | string | Valid values: “all” and “organic” (results without Pinned results or Promotions). The default is “all”. |
userToken | User token for search personalization | string | By default, all results are returned. |
facet | Return categories where the search results belong to | string | Pass one or more custom fields to receive facets from specified fields. Example of facet parameter. By default, no facets are returned. |
numFacets | Limit the maximum number of aggregations returned for each field defined with facet parameter | int | The maximum value is 1000. The default is 10. |
rangeFacets | Group numerical custom fields into ranges | object | Example of rangeFacets parameter. By default, no facets are returned. |
collectAnalytics | Specifies if the search event is added to the statistics shown in the Dashboard | boolean | The default is true. |
analyticsTag | A tag that can be used to filter analytics in the dashboard. For more information read the article. | string | The maximum length of a tag is 50 characters. |
filter | Filter object that uses custom_fields values for filtering search results. | object | Supports nested and, or, not, and range filters. Examples of filter parameters. |
defaultOperator | When a user searches with multiple keywords, we return only documents that contain all the terms which means applying the logical operator AND for the query. It is possible to choose which logical operator to use for fuzzy results when the fuzzy parameter is set to auto. | string | There are two options: "or": makes fuzzy results broader and includes partial matches of a few search terms "and": makes fuzzy results stricter and includes only mistyped search terms |
The URL www.example.com/news/article.pdf has category properties 0=www.example.com, 1=some, and doctype_pdf.
&categories=0xwww.example.com
returns results from www.example.com, &categories=1xnews
returns results from /news/ and &categories=doctype_pdf
returns results with filetype pdf.
The custom fields “city=London” AND “genre=rock” OR “genre=pop” with URL encoding:
&customField=city%3Dlondon&customField=genre%3Drock&customField=genre%3Dpop
&facet=custom_fields.genre&facet=custom_fields.artist
returns search result aggregations by genre and artist custom fields.
&facet=categorys&categories=1xblog
returns search result aggregations by blog category.
[ { "field": "custom_fields.price", "ranges": [ { "to": 10 }, { "from": 10, "to": 20 }, { "from": 20 } ] } ]
The parameter needs to be URL-encoded:
rangeFacets=%5B%7B%22field%3A%20%22custom_fields.price%22%2C%22ranges%22%3A%20%5B%7B%20%22to%22%3A%2010%20%7D%2C%7B%20%22from%22%3A%2010%2C%20%22to%22%3A%2020%20%7D%2C%7B%20%22from%22%3A%2020%20%7D%5D%7D%5D
Return results with custom_fields.price between the values 10000 and 20000:
{ "range": { "custom_fields.price": { "gt": "10000", "lt": "20000" } } }
The parameter needs to be URL-encoded:
filter%3D%7B%0A%20%20%20%20%22range%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22custom_fields.price%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22gt%22%3A%20%2210000%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22lt%22%3A%20%2220000%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A
Return results where brand is apple, color is not white, and price is between 200 and 500:
{ 'and': [ { 'custom_fields.brand': 'apple' }, { 'not': { 'custom_fields.color': 'white' } }, { 'range': { 'custom_fields.price': { 'gt': 200, 'lt': 500 } } } ] };
The parameter needs to be URL-encoded:
filter%3D%7B%0A%20%20%20%20%27and%27%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%20%27custom_fields.brand%27%3A%20%27apple%27%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20%27not%27%3A%20%7B%20%27custom_fields.color%27%3A%20%27white%27%20%7D%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20%27range%27%3A%20%7B%20%27custom_fields.price%27%3A%20%7B%20%27gt%27%3A%20200%2C%20%27lt%27%3A%20500%20%7D%20%7D%20%7D%0A%20%20%20%20%5D%0A%7D%3B
Return results from example.com and /blog/:
{ "and": [ {"category":"0xexample.com"}, {"category":"1xblog"} ] }
The parameter needs to be URL-encoded:
%7B%0A%20%22and%22%3A%20%5B%0A%20%20%20%7B%22category%22%3A%220xexample.com%22%7D%2C%0A%20%20%20%7B%22category%22%3A%221xblog%22%7D%0A%20%5D%0A%7D%0A
Return results against custom fields manufacturer values nokia, or Nokia, or NOKIA:
{ "and": [ { "or": [ { "custom_fields.manufacturer": "nokia" }, { "custom_fields.manufacturer": "Nokia" }, { "custom_fields.manufacturer": "NOKIA" } ] } ] }
The parameter needs to be URL-encoded:
%7B%22and%22%3A%5B%7B%22or%22%3A%5B%7B%22custom_fields.manufacturer%22%3A%20%22nokia%22%7D%2C%7B%22custom_fields.manufacturer%22%3A%20%22Nokia%22%7D%2C%7B%22custom_fields.manufacturer%22%3A%20%22NOKIA%22%7D%5D%7D%5D%7D
https://api.addsearch.com/v1/search/cfa10522e4ae6987c390ab72e9393908?term=rest+api
{ "page": 1, "total_hits": 1, "processing_time_ms": 21, "hits": [ { "id": "54f5b92d4e4766f4bc0ce2b05f80f58d", "url": "https://www.addsearch.com/developers/api/", "title": "AddSearch REST API", "meta_description": "Documentation of our REST API", "meta_categories": ["features", "api"], // <meta name="addsearch-category" content="features/api" /> "custom_fields": { "location": "London", "genre": ["Rock", "Pop"] } "highlight": "AddSearch’s <em>REST API</em> provides programmatic access to your search index", "ts": "2015-01-22T11:56:10", "categories": [ "0xwww.addsearch.com", "1xdevelopers", "2xapi" ], "document_type": "html", "images": { "main": "https://d20vwa69zln1wj.cloudfront.net/1bed1ffde465fddba...", "main_b64": "/9j/4AAQSkZJRgABAQIAHAAcAAD/2wBDACgcHiMeGSgjISMtKygwPG...", "capture": "https://d20vwa69zln1wj.cloudfront.net/1bed1ffde465fddba..." }, "score": 0.790107 } ], facets: null, rangeFacets: null }
Fields in the returned JSON:
Fields in the hits array documents:
Field | Description | Type | Notes |
---|---|---|---|
id | Document's ID | string | |
url | Document's URL | string | |
title | Document's title | string | |
meta_description | Document's meta description | string | Null if missing. |
meta_categories | Document's meta categories | string, array of meta categories | Null if missing. |
custom_fields | Document's custom fields | string, object containing custom fields | Each value is either a string or a string array (if multiple values are defined). |
highlight | Passage of the document's content | string | |
ts | Document's publishing date | string | If the date is not specified, the time when the document was initially indexed is used. |
categories | Automatically collected domain, URL path, or filetype | string, array of categories | Categories can be used as search filters. |
document_type | Hit type: html, pdf, doc, docx, ppt, pptx | string | |
images | Top level of the images object | string, object containing image string and URLs | |
images.main | URL of the thumbnail (e.g. og:image) | string | Null if missing. |
images.main_b64 | Low-resolution version of the thumbnail as a base64 encoded string | string | Null if missing. |
images.capture | URL of the screen capture | string | Null if missing. |
score | How well the document matches the search term | double | |
facets | The categories with the count of records where search results belong to | string, object containing a custom field or an array of custom fields | Null if missing. |
rangeFacets | The minimum and maximum value numerical value of the specified range | Null if missing. |
Please note that the Search API endpoint does not require authentication.
The term parameter value has the following limits that cover most of the search queries:
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.