Skip to main content
Skip table of contents

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

  1. Open your Theme in the Theme Editor

  2. Navigate to assets > js > scroll-search.js

  3. Change the following on line 34:

JS
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:

  1. Navigate to include > include-search.vm

  2. Implement the following change on line 30:

XML
<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.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.