Filtering search results
Often you want certain types of content to not be shown in your search results. By filtering your search results to ensure that certain types of content are 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 that is performed is a "best fit" search where the results can match any of the criteria that are mentioned, but is ordered so that the best fitting results are displayed first.
If you want to force the results to be filtered, you must 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 by using the "search_query" field, which is passed on to the search engine.
Filtering by authoring template
^authoringtemplate::"Template Title"
- 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")
-authoringtemplate::"Template Title"
-authoringtemplate::"Template Title 1" -authoringtemplate::"Template Title 2"
<script language="Javascript">
function addFilter(queryIn)
{
return queryIn + ' -authoringtemplate::"Template Title";
}
</script>
<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
^contentpath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name"
-contentpath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name"
<script language="Javascript">
function addFilter(queryIn)
{
return queryIn + ' -contentpath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name";
}
</script>
<form onSubmit="this.search_query.value=addFilter(this.query.value)">
Query: <input name="query"/>
<input type=hidden name="search_query"/>
</form>