>, Tutorials>Overriding the quick search or advanced search function

Overriding the quick search or advanced search function

This article explains how you can override the Infradox search functions with Javascript (version 31.2 or later).

Recommended reading

Overriding the quick search function

The Infradox script library reads takes the value from the quick search input box, and then it creates a search URL using selected options in the user interface and the settings that you have configured in Backoffice.
By adding the onquicksearch method to the client object in the code editor, you can work with the created URL and parameters to create your own search URL instead.
If you have not added the client object to the script template, then do this first. For example:

Now you can the onquicksearch method to the client object, for example:

Note that once you have added the onquicksearch method, the search url will not be executed. You’ll have to do this in the method yourself.
The parameter that is received by the onquicksearch function is a JSON object with the following parameters:

  • q – the search value as parsed and created by the Infradox script
  • s – the search value that the user entered and not changed in any way by the Infradox script
  • d – the default text for the quick search box (usually e.g. enter keywords)
  • u – the base url without the search value, the url is exlained below
  • f – f has the filter parameters string (which is written to the cookies)
  • r – r is a number not equal to 0 if refining within a contributor browse search (r is the contributor id)
  • w – this indicates whether or not the search within parameter was used to refine a normal search (value 1 if refining)
  • e – has value 1 if set/gallery searching is active

You can use the properties of the JSON object to execute a search URL, or to manipulate the search URL first. Executing the URL is simply done by adding location.host=url; to your script.

The example below shows the results when searching for Blue roses without changing anything

The example below shows the results when searching for Blue roses without changing anything

The URL (object property u) may be any of the following:

  • /search?s= for a normal new search
  • /refine?s= searching within results
  • /contributor/browse/[id]/refine searching within results of contributor browse request
  • /sets?s= searching for sets

The parsed search value (object property q) has the search value that results from running it through the Infradox script. This is a normalised string with e.g. spaces replaced by pluses (+), noise and illegal characters removed and finally encoded to be used as part of a URL. If you want to create your own URL then you can use the object property s instead and you’ll have to encode it yourself. You can find an example in the code editor (click on the Load example button for a list).

Overriding the advanced search function

If you want to override the advanced search function (i.e. searches from the search side bar) then you can add the method onadvancedsearch to the client object. You can override both or either methods if you want. Overriding the advanced search function works the same as described above. For example:

2018-10-09T17:35:54+02:00 October 9th, 2018|Categories: Customisation, Tutorials|Tags: , , , , , , , , |