Introduction
This is a quick one which caused me some problems on a project I have been working on.
So a quick introduction to SharePoint 2013 Search. SharePoint 2010 had a feature in search called “Search Scopes” this provided a way to select the content that you wanted to return results from based on certain criteria. For example if it had a certain Content Type or was found in a particular location.
In SharePoint 2013 Scopes have been replaced by Result Sources which provide the same feature plus some much more powerful selection criteria using tokens. For example you can retrieve the user performing the search and return content where the user is the author.
Problem
The problem is that I have a search page which has both the search query web part and a search results web part.
After setting up a custom Result Source query to refine the results down I would always get results displaying, even before a query had been submitted search.
The Result Source is configured by:-
- Browsing to the Site Collection
- Click on the Site Settings Icon
- Choose Site Settings->Site Collection Administration->Search Result Sources
- Create a New Result Source
- Part of the setup is to create the Query Transform, this brings up the window below
The query always returns search results. Normally results only appear when you click on the Test tab, providing the search query and click Test Query.
This is a problem as because the search will always execute as the user goes on the page and is just plain messy.
So I spent sometime trying to work out what was going on.
Solution
I have to say the solution took sometime and it was only after re-reading the following Technet article http://technet.microsoft.com/en-us/library/dn186229.aspx#BKMK_How_does_query_transform_affect_query the section at the bottom “Narrowing search results by using a Query Transform” gave me the answer.
The key to all of this is that my query is not waiting for the search term before executing the search, it just always executes the search.
The example that the article provides is this:-
{?{searchTerms} ContentClass=urn:content-class:SPSPeople}
So that gave me the solution, the important thing is that if you want the query to wait for search terms to be filled in then wrap your query with curly brackets.
So the problem query goes from this:-
{searchTerms} (IsDocument=True AND (ContentTypeId:0x0101009CA89B0104F04692A106A1F88E847F7D*))
to this:-
{?{searchTerms} (IsDocument=True AND (ContentTypeId:0x0101009CA89B0104F04692A106A1F88E847F7D*))}
When I use the query above with the Query Transform this is the result, note the query returns no results.
The query that I have will take any query and ensure that only search results that are documents that have a ContentTypeId which starts with a particular value.
I hope that helps someone!
That someone was me!
Thank you very much!
Paul.
No problem Paul – glad I am not the only one 😉
Regards
Simon
What about if I choose (Restrict by app) for (Specify a URL) how to fix that please?
Hi Mahmood,
Can you give me an example of what you are using and we can take a look.
Cheers
Simon
Thanks a lot! After searching a solution more than 1 day I found you and the answer.
Great!
Cheers,
Pavol
i want to restrict the search results coming from a specific site collection
can you pls provide whats the query transform i need to use
Rather than a Query Transform you will need to modify your Query for your search result web part so that you have something like Path:{Site.URL}*. If you have a specific site collection in mind you can replace with Path:http://sharepoint/mysitecollection/*
Suggest you do some reading of http://msdn.microsoft.com/en-us/library/office/jj163973(v=office.15).aspx
Cheers
Simon
I looked everywhere for this. Thanks!
Bill – Glad it helped!
Cheers
Simon
Dude, you saved me life 🙂 Thanks for this awesome post!
No problem fella – always glad to help 😉
Thanks for letting us know!
S
Helpful article, thanks! Q – So if I wanted to see all the results how would I get that? The wildcard * does not seem to be working. Any thoughts?
Hi,
So there are some limits on the number of results that you can have on one page, so generally you cannot see ‘all’ the results on one page without some custom development.
However, you can increase the number of results displayed by the web part by editing the page.
Choose the Core Results Search Web part and choose Edit Web Part. The section, Search Results, on the right hand side will be displayed to allow you to change the web part settings. Expand the Settings section and there is an option to set the number of items to display. This has a maximum of 50 on my environment.
HTH