×

You're using an outdated browser

For a better experience, keep your browser up to date. Check here for the latest version.

Manual

Exclude specific attachment types in search results

Thomas Rough

Thomas Rough Last update: Aug 16, 2018

In some cases it may be desirable to hide specific attachments from appearing in Scroll Viewport search results. This can be achieved by following the steps in this documentation. 

Prerequisites 

In order to prevent attachments from appearing in Scroll Viewport search results, you must first ensure that you have:

Implementation

Firstly, you need to replace the code of the search.vm with the following code:

#foreach($result in $searchResults.items)
    #if($result.absoluteLink.contains("/files/"))
        #if($result.absoluteLink.endsWith(".jpg"))
          	<section class="search-result">
                <header>
                   <h2>
                      <a href="$result.link">$result.displayTitle</a>
                   </h2>
                </header>
                <div class="search-result-content">
                   <p class="search-result-link">$result.absoluteLink</p>
                   <p class="search-result-desc">$result.getDescription(280)</p>
                </div>
                <hr>
            </section>
        #end
    #else
        <section class="search-result">
            <header>
                <h2>
                   <a href="$result.link">$result.displayTitle</a>
                </h2>
            </header>
            <div class="search-result-content">
                <p class="search-result-link">$result.absoluteLink</p>
                <p class="search-result-desc">$result.getDescription(280)</p>
            </div>
            <hr>
        </section>
    #end	
#end

In the first #if-statement, the current search result is checked to see whether it is an attachment.

The second #if-statement then checks if the attachment ends with ".jpg" and gets displayed – all other attachments are ignored.

If you want to show all attachments except for ".jpg"-files, you just need to negate the #if-statement like this:

#foreach($result in $searchResults.items)
...
   #if(!$result.absoluteLink.endsWith(".jpg"))
...
#end

Info

Please note that the excluded attachments are still counted to the search results, which may affects the pager of Scroll Viewport.

2xlatest
We use cookies to create a secure and effective browsing experience for our website visitors and to understand how you use our site (i.e. Google Analytics). For more information: click here.
Ok