SharePoint Search 2013 - Changing the default search operator from AND to OR - Part 2
Hi
Back on that investigation on how to change the default AND operator (free text search) to OR.
We saw in Part 1 that we could wrap the {searchboxQuery} with the ANY() operator in the Search Results WP. This presented a strong restriction in terms of supporting more complex queries in the search box.
In SharePoint 2013, Federated Locations have been replaced by Result Sources. By using the QueryRestriction tag in a Federated Location, it was possible to refine search results on a location basis.
The most common example was the Local People Search Results location using a scope called People to filter out non People search results.
<QueryRestriction xmlns="https://schemas.microsoft.com/Search/2007/location">scope:"People" </QueryRestriction>
So what about Result Sources in 2013 ?
Result Sources uses a Query Transformation to filter out search results. The Query transformation can be seen as a Query Rule linked to your Result Source.
To view your Result Sources, open your Search Service Application, click on the left side Result Sources below the Queries and Results section.
Some out of the box Result Sources:
The Query Transformation associated with the Local SharePoint Results, is seen as follows:
All Result Sources defined in the Provided by SharePoint cannot be modified (marked as System). You must create a copy and edit that new copy.
Back to our problematic of changing the default AND to OR, it is easily seen that we can duplicate the default Local SharePoint Results, adapt the Query Transform and use that in our Search center.
Step by Step
- Go to the SSA Result Sources page
- Select the "Local SharePoint Results"
- Copy it
- Rename your Result Source
- Edit the Query Transform textbox
- Change the query to
{?ANY({searchTerms}) -ContentClass=urn:content-class:SPSPeople}
(note the exclusion of the People type of results using the minus operator)
- Save your new Result Source
- Check that your new Result Source is listed.
- Select it to make it the default Result Source (Set as Default)
Now that we have established our new Result Source, we now need to review the Search Results Web Part.
Edit your Search Center page
Edit your Search Results Web Part and hit the Change Query button
In The build Your Query, select your newly created result source
- Leave the Query Text with {searchboxquery} .
- Save the Web Part properties and your page.
- Time to test our result source.
Let's try to use a more complex KQL query:
The ULS log shows the same syntax failure:
ExecuteFlowInternal Flow:Microsoft.SharePointSearchProviderFlow Exception: Microsoft.Office.Server.Search.Query.QueryMalformedException: Query 'ANY(ALL(assets Collection) title:Site) -ContentClass=urn:content-class:SPSPeople' failed
Conclusion
We can achieve the same results as modifying the searchboxQuery but still we can't really get a proper OR behavior when dealing with multiple scopes query.
In Part 3 of our quest to change the default search operator from AND to OR, I will explore the use of Query Rules and Result Block.
Stay tuned.