Filtering search results

Often you want certain types of content to not be shown in your search results. You can do this by filtering your 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. It 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 that the best fitting results are displayed first.

If you want to force the results to be filtered, you have to construct the query yourself. This allows you to force either that the results must use a specified parameter, or that they must not use a specified parameter. You can then send the constructed query to the search component using the "search_query" field, which is passed on to the search engine.

Filtering by authoring template

To only include content that is using a specific authoring template, append this string to the end of the search query:
+authoringtemplate::"Template Title" 
To specify multiple authoring templates, append this string to the end of the search query:
+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" 
You can also construct your query using some Javascript. For example:
<script language="Javascript">

function addFilter(queryIn)

{

return queryIn + ' -authoringtemplate::"Template Title";

}

</script> 
In your 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> 

Filtering 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"
You can also construct your query using some Javascript. For example:
<script language="Javascript">

function addFilter(queryIn)

{

return queryIn + ' -contentpath::"/LibraryName/FolderName/SiteArea1Name/SiteArea1.1Name";

}

</script>  
In your 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>