How to Improve Search Results for Multiple Strings
Problem
By default, Scroll Viewport uses the standard Confluence search functionality. Therefore, if you search with multiple strings, Confluence will do an OR-Search by default. For example, if you search for 'Scroll Viewport' the search will find results for 'Scroll' 'Viewport' and 'Scroll Viewport'. As a result, this search process might include some results that you are not looking for.
However, to perform an AND-Search in Confluence, you can simply wrap your string in double quotation marks, like this "Scroll Viewport". Using this process, means you will only get results which contain 'Scroll Viewport'.
This article will explain how you can setup AND-search in your Viewport without having to add double quotation marks to your search term(s). This article is using the Scroll Web Help Theme as a base.
What You Need
Some basic knowledge in JavaScript
Changing the Search from OR-Search to AND-Search
Open your Theme in the Theme Editor
Navigate to assets > js > scroll-search.js
Change the following on line 34:
var url = 'q="' + encodeURIComponent(query) + '"';
After the q=
and before the &s
we need to add double quotation marks. This will wrap the given query and the Confluence Search will perform an AND-Search.
Since these changes will affect the displayed search terms on your results page, we also need to remove the double quotation marks from the velocity template. To do this:
Navigate to include > include-search.vm
Implement the following change on line 30:
<h1 class="search-header">Search for <em>$searchRequest.queryString</em>
The placeholder $searchRequest.queryString
is wrapped in double quotation marks which needs to be removed.
Your Confluence search is now performing an AND-Search by default in your Viewport.