+

Search Tips   |   Advanced Search

Filter search results

Often we want certain types of content to not be shown in the search results. We can do this by filtering the search results to ensure that certain types of content is not displayed. A search component uses a set of fields, such as "search_query", "search_categories" and "search_authoringtemplate", to construct a single query to send to the search engine. This constructed search does not explicitly perform a filter. Does not mark any of the criteria as required and therefore the search performed is a "best fit" search where the results can match any of the criteria mentioned, but is ordered so the best fitting results are displayed first. To force the results to be filtered, we have to construct the query yourself. This allows us to force either the results must use a specified parameter, or they must not use a specified parameter. We can then send the constructed query to the search component using the "search_query" field, which is passed on to the search engine.


Filter by authoring template

To only include content using a specific authoring template, append this string to the end of the search query. For example:

To specify multiple authoring templates, append the appropriate string to the end of the search query:

  • For query results that match either template:

      ^(AuthoringTemplate::"Template Title 1" AuthoringTemplate::"Template Title 2")

  • For query results that match all templates:

      ^(+AuthoringTemplate::"Template Title 1" +AuthoringTemplate::"Template Title 2")

To only include content that does not use a specific authoring template, append this string to the search query:

    -AuthoringTemplate::"Template Title"

To exclude multiple authoring templates, append this string to the end of the search query:

    -AuthoringTemplate::"Template Title 1" -AuthoringTemplate::"Template Title 2"

We can also construct the query using some JavaScript. For example:

    <script language="Javascript">
     function addFilter(queryIn)
     {
     return queryIn + ' -AuthoringTemplate::"Template Title";
     }
     </script> 

    In the search form, hide the "search_query" query field and compute it during the submit using what the user typed in plus the template filter:

      <form onSubmit="this.search_query.value=addFilter(this.query.value)">
       Query: <input name="query"/>
       <input type=hidden name="search_query"/>
       </form> 


Filter by content path

To only include content that is on a specific path, append this string to the end of the search query:

    ^ContentPath::"/LibraryName/FolderName/SiteArea1Name/SiteArea1.1Name"

To only include content that is not on a specific path, append this string to the search query:

    -ContentPath::"/LibraryName/FolderName/SiteArea1Name/SiteArea1.1Name"

We can also construct the query using some JavaScript. For example:

    <script language="Javascript">
     function addFilter(queryIn)
     {
     return queryIn + ' -ContentPath::"/LibraryName/FolderName/SiteArea1Name/SiteArea1.1Name";
     }
     </script> 

In the search form, hide the "search_query" query field and compute it during the submit using what the user typed in plus the path filter:

    <form onSubmit="this.search_query.value=addFilter(this.query.value)">
     Query: <input name="query"/>
     <input type=hidden name="search_query"/>
     </form> 


Parent Create a search query