Separate results page’s settings

You can adjust Separate results page’s functionality with a global JavaScript variable called “addsearch_settings”. The variable must be defined above the script tag, that loads AddSearch with your SITEKEY.

General installation instructions can be found from this page.

Example

Here’s an example of search results with the number of results, visible URLs, publishing dates and a possibility to sort by date or relevance.

The setup shown above can be defined with the following settings.

<!-- AddSearch settings -->
<script>
window.addsearch_settings = {
  display_url: true,
  display_resultscount: true,
  display_date: true,
  display_sortby: true
}
</script>


Settings

Currently addsearch_settings supports following settings:

SettingValuesDescription
display_urltrue
false (default)
Display the target page’s URLs in search results
display_categorytrue (default)
false
Display the category texts in search results. Not shown if display_date is enabled
display_resultscounttrue
false (default)
Display the number of results found (result count)
display_datetrue
false (default)
Display the publishing date of search results instead of category
date_format_functionJavaScript functionCustom JavaScript function to format publishing dates in search results. The function is called with Date object as a parameter
display_sortbytrue
false (default)
Let the user sort search results by Date or by Relevance. See example
default_sortbydate
relevance (default)
Default order of results
number_of_resultsinteger
(default: 10)
Number of results to show (1-30)
ga_tracking_idUA-xxxxxx-xGoogle Analytics tracking ID. Needed if Global site tag (gtag) in use
link_target_blank, _self, _top, _parentWindow or a frame where the clicked results link should open. E.g. _blank to open links in a new tab.
filtersSee Range filtersPre-defined search filters (beta)

Available JavaScript functions

Submit the search field

To submit the search field on search results page, call the following function.

addsearch.submit();

Example of the implementation:

<input type="text" class="addsearch" placeholder="Search.." />
<button onclick="addsearch.submit()">Search</button>
<div id="addsearch-results"></div>

Dynamic category filters

With dynamic category filters, aka faceted search, you can let your users filter search results in real-time. In the example website you can filter our search to /blog or /support paths.

Category filters can be added and removed with a JavaScript function call:

addsearch.category(category, filterEnabled, [submitAutomatically]);
AttributeDescription
categoryCategory to apply. E.g. 0xsub.domain.com returns results from http://sub.domain.com/* and 1xnews returns results from /news/*
filterEnabledFilter enabled (true) or not (false)
submitAutomaticallyBy default, search results are refreshed automatically when the category function is called. If submitAutomatically is set to false, you need to call addsearch.submit(); function manually to refresh search results with new filters.

One way to use dynamic category filters is to add a checkbox to the Search results page:

<input type="checkbox" 
  onchange="addsearch.category('1xnews', this.checked)" />

When the checkbox above is checked, search results are limited to /news/* path. When the checkbox is unchecked, all results are returned.

See the full documentation of Category filters.

Range filters

With range filters you can let your users filter search results in real-time to meet a range criteria.

Range filters can be added and removed with a JavaScript function call:

addsearch.range(field, start, end);
AttributeDescription
fieldAccepted values: date
startStart value (inclusive). E.g. 2018-10-12
endEnd value (inclusive). E.g. 2018-12-24

For example, to let users filter search results to a specific date range, the function could be called with following parameters:

// Return docs published on January 1st, 2015 and later
addsearch.range('date', '2015-01-01', null); 

// Return docs published on May 30th, 2018 or before that
addsearch.range('date', null, '2018-05-30'); 

// Return docs published in 2018
addsearch.range('date', '2018-01-01', '2018-12-31'); 

// Return all docs
addsearch.range('date', null, null); 

Pre-defining range filter values

To pre-defined the selected range when search results are loaded, use the following setup:

window.addsearch_settings = {
  filters: {
    date: {
      start: '2018-01-01',
      end: '2018-12-31'
    }
  }
}