As explained in the topic on filtering by authoring template, the query generated by the search component is a "best fit" search. This also applies to site areas.
We can use the same technique to filter on site area as used for authoring template - generate the query ourselves rather than use the default query generation.
Site areas are a little different as the information sent to the search index is actually a path, which the search engine will break up into a list of values. You can then perform a search on any of the "pieces" in the path, or on the whole path.
To only include content that is on a specific path, you would append this to the end of the user's query:
^contentPath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name/etc."
To extend this to multiple templates, you can simply append more site area restrictions.
Similarly to only include content that is NOT on a specific path, you would append this to the user's query:
-contentPath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name/etc."
And for multiple you list multiple paths.
Note that the search engine will actually parse the path you send in by breaking it up into multiple values, and then search for ALL of these in the contentPath field. This means you can search for a partial path. e.g. you could leave out the library and search the same path across multiple libraries.
As with the authoring template example, using javascript to add the filter is very simple. First a function:
<script language="Javascript">
function addFilter(queryIn)
{
return queryIn + ' -contentPath::"/LibraryName/SiteName/SiteArea1Name/SiteArea1.1Name/etc."';
}
</script>
Then 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>
This allows you to hide content from certain paths (e.g. don't show my "tools" section in the results) or to restrict to a certain path (e.g. provide a search scoped to the current area).