Monday, April 22, 2013

Limiting search results in SharePoint 2013 (aka scopes in 2010)

A typical scenario in SharePoint is to limit the results on a search page to specific content. In SharePoint 2010 this was achieved by creating Search Scopes, and then adding include and exclude rules to the scope. Then you could configure the Core Results Web Part to display results from that scope only.

SharePoint 2013 however introduces the concept of Result Sources instead of scopes. As a sample I will limit results to show items from one particular site.

You can create Result Sources on three different levels: Search Service Application, Site collection and Site. This means you can define Result Sources in a very granular way, depending on where you want to use them. But bear in mind that having configurations spread all across your sites increases complexity of maintenance. In this sample I will create my Result Source at the SSA level.

Steps

Navigate to your SSA on Central Admin and click Result Sources in the left hand menu.
image

Next click “New Result Source”. This would be equal to a new search scope. Give the result source a name, leave the radio button on “Local SharePoint” as we’re searching local content. The limiting rule is then added in the Query Transform box. You can either launch the Query Builder or manually append your limiting query to the user query.

In this sample you will end up with the query:

{searchTerms} path:http://intranet.contoso.com/sales

{searchTerms} is a placeholder for the user query, and the last bit will make sure only items starting with http://intranet.contoso.com/sales are included.

image

Finally you will save the newly created Result Source.

Now that you have create the Result Source (or scope) you need to configure your search page to use it. Navigate to your search result page and enter edit mode. Next edit the Search Results Web Part and click the Change query button.
image

In the query builder dialog you can now choose your new result source in the top dropdown.

image

Click OK, save your page, wait a few seconds for the change to be picked up and results should be limited to http://intranet.contoso.com/sales.

Not too hard, just a bit different from what you were used to in SharePoint 2010.

138 comments:

  1. This is exactly what I want to do but I want the path to be dynamic based on the site they're on. Is that possible? I tried {searchTerms}{Site} but that didn't work...any ideas?

    ReplyDelete
    Replies
    1. Hi,
      Did you try:

      {searchTerms} path:{Site}

      Thanks,

      Delete
  2. Hello Mikael,
    how long does it take, after you created a Result Source, unless it shows up in the list of Result Sources of the Content Search Web Part ?
    I created one but don't see it in the list.

    ReplyDelete
    Replies
    1. Hi,
      In my experince a result source usually appears withing 5-10 seconds of creating it.

      Which level did you create the result source on? Site, Site Collection, SSA?

      Delete
    2. Hello Mikael,
      I created it in the SSA. Checked ... Seems that I can use the Result Source only on the Enterprise Search Page but now on a Content Search Web Part in Site Collection ABC. Is that correct ?

      Delete
    3. Hi,
      When I click "Change Query" I get all my result sources listed, also the ones created by me when using the CBS webpart.

      Thanks,
      -mikael

      Delete
  3. Hi Mikael,

    Can i specify more than one site n Path? where can i look for the syntax for specifying multiple site collections in path.

    Thanks,
    SH

    ReplyDelete
    Replies
    1. Hi,
      Check out the KQL reference at: http://msdn.microsoft.com/en-us/library/ee558911.aspx

      You can do:

      term path:http://intranet.contoso.com/sales path:http://intranet.contoso.com/finance

      Two property queries on the same property will default to an OR statement. You may also write more explicit queries like below:

      term (path:"http://intranet.contoso.com/sales" OR path:"http://intranet.contoso.com/finance")

      alternativly you can do:

      term ANY(path:"http://intranet.contoso.com/sales" path:"http://intranet.contoso.com/finance")

      Delete
  4. Thanks for your response Mikael, i am stuck in a situation. Have around 160 site collections which will be divided into bunch of result sources. we are customizing the advanced search webpart to provide user with the ability to handpick the site collections n which he wants to search. So i have to dynamically create a query transform( ANY(Path:"http:sitecoll1" Path:"http:sitecoll1") and then redirect to results page with parameters. I am not able to find a way how i can redirect KQL search results to a result page, can you please help. The other way is to dynamically apply query transformation to the search result webpart on the results page but i don't know how to do that.

    ReplyDelete
    Replies
    1. Hi,
      You probably want to create a custom web part which does something similar to the code I have at http://spsearchparts.codeplex.com/SourceControl/latest#2013/SearchExtension/CustomSearchWebPart/CustomSearchWebPart.cs

      But most likely you want to hook on the QueryIssuing event instead of the BeforeSerializeToClient event.

      Unfortunately there is not much documentation around this yet so you have to test it a bit.

      Delete
  5. Hi Mike,

    I want to exclude/block results coming from Column content type like 'modified by' for Page Libraries. Any help is greatly appriciated

    ReplyDelete
    Replies
    1. Hi,
      Have you tried: -ModifiedBy:"Your Name"

      Thanks,
      Mikael

      Delete
  6. Hi Mikael,

    In Sharepoint 2013 refinement panel, is there a way i can multiselect the refiners, also i want to add my own refiners and allow the users to select multiple values.

    Thanks,
    Sharada

    ReplyDelete
    Replies
    1. Hi take a look at my recent post: http://techmikael.blogspot.no/2013/07/enabling-multi-select-refiners-in.html :)

      Delete
  7. Hi Mikael,
    I have a site with internal url http:// and the same site is published in internet with the url of http://abc.de.com, I configured the search as your post, but its working fine for intranet i mean for http:// ,
    but for http://abc.de.com this url its returning result from all the site collections. Any clue for this

    Thanks,
    -Sendil

    ReplyDelete
    Replies
    1. Hi,
      Queries should work if you use AAM for the different domains. I have verified this at a recent installation I did.

      Thanks,
      Mikael Svenson

      Delete
  8. Hi Mikael,

    Is it possible to limit the search results where a custom user profile property is not empty? What will the query be? Any help is appreciated.

    Thanks,
    Wen

    ReplyDelete
    Replies
    1. Hi,
      You may want to add a managed property called IsSet which includes all props which have values. However doing this requires development of a content enrichment web service. Then you could query:

      IsSet:name IsSet:phone...

      Out of the box you have a property called IsDocument which does something similar.

      Another option is to query the property with:

      prop:a* prop:b* prop:c prop:d etc..

      That will ensure it has a value of some kind. Not ideal, but should work.

      Thanks,
      Mikael

      Delete
    2. How about a way to exclude results where a user profile property is set to a particular value, say an extension attribute set to '1' or something? I have added the property and mapping but can't figure out how to add the exclusion?

      Any help would be greatly appreciated :)

      Delete
    3. Hi,
      It's quite easy. The crux in your case is to make sure the managed property is mapped to the PeopleIdx full-text index, as you are doing people search. Default a managed property is mapped to the default full-text index.

      You do this via the Advanced Searchable Settings page from the managed property settings.

      Once you do this (and re-crawl) you can merely use:

      -propertyname:1

      as part of your query to exclude it.

      Thanks,
      Mikael

      Delete
  9. Hi Mike,

    Great Article! I have an environment where i have multiple host header site collections. like http://site, http://site/site1, http://site/site2.
    I want the query to return results only from http://site.

    Tried SPSiteUrl = http://site. That did not work.
    Path=http://site will return just the homepage.

    Please help

    S

    ReplyDelete
    Replies
    1. Hi,
      Try:
      path:"http://site/path"

      or

      path:"http://site/path/*"

      Using quotes and try with a wildcard at the end.

      Thanks,
      Mikael

      Delete
    2. Many thanks Mike!
      I think path:"http://site/path/*" will return everything that starts with "site" which would include results from site1 and site2 as well.
      Anyway I will give that a try.

      Thanks
      S

      Delete
    3. Hi,
      I was a bit quick.

      path:"http://site" -path:"http://site/site*"

      should do it. Just add parts with a - in front to exclude them.

      Thanks,
      Mikael

      Delete
  10. Is there any way that a non-administrator can invoke advanced search an limit it to a specific site?
    I can't even figure out how to limit it to my company's sharepoint (and not duplicate the search on Bing)

    ReplyDelete
    Replies
    1. Hi,
      any user can type:

      path:"http://contoso.com/site"

      in their query. What do you mean by limiting on Bing? How does that play into your search scenario?

      Thanks,
      -m

      Delete
  11. Hi, I want to display results only if the searchquerybox isnt empty and I only want to search on the current sitecollection...

    what the hack is the right query for that?

    ReplyDelete
    Replies
    1. First off, an empty search box should not kick off a search query. When you say "current site collection". Is the search site on the same site collection as the content or a separate one?

      And you can always append the u= query parameter which is still there in 2013 to limit on the site/path if you want. This is what the search box in the ribbon adds.

      Maybe you can expand some more on your exact requirements and what you want to achieve and I'll try to formulate a more precise answer.

      Thanks,
      -m

      Delete
    2. Hi Mikael,
      I am also facing similar issue. When the page loads search results webpart showing the results. Search results and search box or on the same page.

      Delete
    3. I figured it out. In the result source give the Querytransform as

      {SearchBoxQuery} {?{searchTerms} Path:{SiteCollection.URL}}

      Delete
  12. Hi Mikael,
    Thanks for the post. I have a query. I have 2 content sources in my search application. My search results are coming from one of them. How and where to change the content source of search results?
    Thanks
    Garima

    ReplyDelete
  13. Hi Mikael,

    Great post.. I am trying to get this working in a SharePoint 2013 environment with content upgraded from SP2010 environment. My sites now run in SP2010-mode of SP2013 and I have setup search successfully. My SP2010-mode site is hosted on http://sp2013.myOldSite.com/en/us and I have created a new SP2013 native site at http://sp2013.myNewSite.com/en/us.
    The query {searchterms} Path:http://sp2013.myOldSite.com/en/us* returns results on the SearchCenter created in SP2013 native site but not in the SearchCenter created in SP2010-mode site. If I just search for {searchterms} without passing the "Path" filter, I get results on both the SP2010-mode and SP2013 SearchCenter sites.
    Is there a way to get the "Path" filter working in SP2010-mode SearchCenter site?

    Thanks!

    ReplyDelete
    Replies
    1. Hi,
      Query rules apply does not apply to 2010 mode, as queries are executed a bit different. Your 2010 site will still be able to use scopes which you had before the upgrade. But you cannot edit or create new ones.

      I would recommend moving to a 2013 search center, and brand it as much as you can to look like 2010 if necessary. If you are to run 2010 mode for a long time, why upgrade in the first place? ;)

      For a 2010 site you should still be able to pass in &a=path:http://site/ as a query parameter to limit results, or the &u= parameter used for contextual scopes.

      To sum it up, search in 2010 mode on 2013 gives some hurt, and the quickest solution is to use a 2013 mode site for search... at least in my opinion.

      Thanks,
      Mikael

      Delete
    2. Thanks Mikael. We have numerous Search sites in SP2010 environment which are created out of a custom site template and hosted under each subsite which makes it harder to create a replacement of these sites in SP2013 native mode. I agree that it could have been an option if we had decided to host the SearchCenter at a global location outside of our current hierarchy. But for now, we like to retain the same site hierarchy until we decide that we want to switch over to the SP2013 native mode.

      Whats surprising is that other managed properties such as "author" work fine in the SP2010-based site. For example, if I use a query {searchterms} author:System Account, then it does return valid results based on the contextual search query.

      Delete
    3. Hi,
      Result Sources do work for 2010 mode sites, so this is probably your approach.But "path:" should work in 2010 as well, as it did in native 2010. Try to put quotes around it and skip the *.

      Thanks,
      Mikael

      Delete
  14. Is it possible to use FQL in the result sources Query builder ? the documentation is confusing @ http://msdn.microsoft.com/en-us/library/jj163973.aspx
    It says change the query to an FQL format & that how you enable FQL. But this did not work for me.
    i wanted to write a property restriction query like author:OR(Ashwani, Mike) where Ashwani & mike would come form a User profile field value "Ashwani,Mike".
    Any thoughts ?

    ReplyDelete
    Replies
    1. I haven't tried or had use for fql in the query rules yet. And your case can in KQL be written as:

      Author:(ashwani OR mike)

      Remember that KQL support parentheses, also in a nested fashion.

      Thanks,
      Mikael

      Delete
    2. I can, but the problem is my user profile has information as Ashwani, Mike... i cannot transform it to Ashwani OR mike in the query transformation option. or can I ?
      I am just trying to re-use the input as is from the user profile store to add condition to the query.

      My understanding is that we cannot write code to set the Query transformations for Result Sources. They have to be pre-configured & will just follow the inputs.
      Or is there a way to achieve that via some code that i can plug -in to the Query transformation pipeline ?

      Thanks,
      Ashwani

      Delete
    3. Hi,
      My previous sample with property:() doesn't actually work either. And yes, you can do custom code to use in query rules. Take a look at my code at http://spsearchparts.codeplex.com/SourceControl/latest#2013/SearchExtension/CustomSearchWebPart/CustomSearchWebPart.cs which creates a variable "FollowedUsers" which can be used like this in a query rule for OR expansion:

      {|ManagedProperty:{FollowedUsers}}

      If you create a custom webpart to drop on the page which splits the userprofile property to a multivalue property you should be good to go.

      Thanks,
      Mikael

      Delete
  15. Mikael, I am trying to only show results of webs created with a custom site template (template created in UI .vs wsp).

    So far only the web template of the original OOB template name is hitting results, but not my custom template name (i.e webtemplate:*projectsites* yield results, but not webtemplate:mycustom-template-name.

    Any ideas?

    ReplyDelete
    Replies
    1. sorry, the correct syntax for the hit is webtemplate:projectsite

      Where the project site template was the basis for my custom template...but my custom template name does not yield results.

      Thank you.

      Delete
  16. Hi Mikael,

    Thanks for the Post. i have few doubts about it. Is it possible to pass the resultsource in query itself while searching on Serachcenter as we used to pass in Sharepoint 2010. (Scope:test, something like that). I tried to create a result source which should fetch value from URL at runtime. I tried to use Querystring.Myparameter1 in the resultsource query and the query is working fine. but when i am trying to use the same with URL, the querystring parameters is not refelecting. Not sure how to take it further. It will be of great help if u can give an example regarding this option too..
    Thanks in Advance

    ReplyDelete
  17. Hi Mikael,
    At the moment this is my query
    (path:"http://staging.teams.alkane.com.au/sites/TGO-Environment-and-Community" ) (contentclass:STS_Web ) ( contentclass:STS_List_DocumentLibrary) (contentclass:STS_Site) -ContentClass=urn:content-class:SPSPeople

    I want to get rid of document library created by some feature or default site libraries like Documents, site Collection Documents, Site Assets, Form Templates

    Do you know how can i achieve it. Thanks

    ReplyDelete
    Replies
    1. Hi,
      If you check some of my newer posts on query variables, you should be able to exclude those libraries based on paths. Or create crawl rules to omit indexing of them. Or set the libraries not to be index in the web templates.

      Delete
  18. Hi Mikel,

    For query do we have any restriction on No.of characters (In SharePoint 2010 for FullTextsqlQuery QueryText cannot exceed 4096 characters).

    ReplyDelete
    Replies
    1. By default it is 4kb, but can be increased to 20kb. You do this using PowerShell on the SSA (http://msdn.microsoft.com/en-us/library/office/ee558911(v=office.15).aspx)

      Delete
    2. This comment has been removed by the author.

      Delete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Hi Mikel,
    I am using on-premise SP server 2013. Created a custom result source by limiting results to particular contenttype. Its working well and getting all the items created using that ct.However, property filtering is not working on my custom result source meaning i am getting always full results regardless of property filter added ex:Title:Technology giving me all results from custom resultsource but same query is working well with local sharepoint result source. Is it a bug is SP or we cannot filter custom resultsource?

    ReplyDelete
    Replies
    1. Did you remember to include {subjectTerms} in your result source query? It's needed in order to pick up user queries.

      Delete
  21. how to configure in sharepoint 2013?

    ReplyDelete
    Replies
    1. Take a look at http://technet.microsoft.com/en-us/library/dn186229(v=office.15).aspx

      Delete
  22. Hi Mikael,
    I have Host name site collection http://www.abc.com and http://www.bcd.com I would like to configure the result source for each site collection to search only that site what would the query be? Please help

    ReplyDelete
    Replies
    1. spsiteurl:http://a spsiteurl:http://b
      or use path instead of spsiteurl

      Delete
  23. How to filter data in the custom list using ResultSource

    ReplyDelete
  24. Hi Mikel,

    My client hosts pdf and dwg files in remote server, and they want to use SharePoint search to show search results with preview. As I know, SharePoint can crawl File share. So does SharePoint 2013 support to show search results from file share with Preview? Thank you.

    ReplyDelete
    Replies
    1. You can managed to create previews for PDF using office web apps, but not dwg. Then you need a third party product.

      Delete
  25. Hello :-),
    I need to search in two different managed properties, but it doesn't seem to work... is this supposed to work or what can I do? Do I need to run full crawl if I change it?

    (MyTitle:{SearchBoxQuery}) OR (MyDescription:{SearchBoxQuery})

    Thanks in advance!

    ReplyDelete
    Replies
    1. This should work just fine. If you just mapped a managed property you must recrawl data first to get a value in the index.

      Delete
  26. How do you make a Property Filter for "non-empty" matches? property<>"" doesn't work.

    ReplyDelete
  27. Hi Mikael,

    In 2013 advanced search page the new datatype "URL" introduced. Because of this only equal and "does not equal" and "Equals" operator exist in property restriction drop down.


    When I am going to change "URL" with "text". The result page the query become like this spsiteurl:"xyz.com" rather than path:"xyz.com". Have you ever encounter such type of issue?

    In 2010 advanced page property def in case of path property.

    I have no idea about this hack.

    ReplyDelete
    Replies
    1. * Edit Page
      * Edit Advanced search box web part
      * Expand Properties
      * Copy the XML for Properties
      * In the PropertyDefs node, change Path to DocAddress which is an alias for Path, and it won't be magically rewritten to SPSiteUrl - which I have no idea why they d

      Delete
  28. Hi,
    If I select a query Local People Results (System) and Query text is contentclass:spspeople then its showing People results but also Service Accounts, So can you tell that how could we segregate between these.

    ReplyDelete
    Replies
    1. You need to find something which identifies a service account and exclude on that. Naming convention of account name, special property...you figure out what you need :)

      Delete
  29. Hi Mikael,
    I want to have your suggestion regarding cross tab in SharePoint, I have a list and I want to convert column data to rows and rows data to columns. So how is it going to be done in SharePoint?
    Thanks!

    ReplyDelete
    Replies
    1. Odd comment for this post, and try a forum instead where you explain a bit more in detail what you want to achieve.

      Delete
  30. I have a situation where I need to exclude a specific library from search results. I want the library indexed so that users in the library can still use the search from within the library, but I don't want those documents showing when performing a search. I have experimented with trying to exclude a ListURL, or even experimented with not showing a particular content type and nothing seems to work at all. Is it not possible with search query to exclude results from a specific library?
    Again - I do not have an account that relates to any of the choices
    My email is dmcmahon@iv4.com

    ReplyDelete
    Replies
    1. You can exclude on contenttype (-spcontenttype=foo), by the path of the list (-path:https://server/sites/site/lists/barlist), or other unique filter which works for you.

      Delete
  31. Thank you for the very rapid response, it was simply a syntax issue

    ReplyDelete
  32. Mikael,
    Am I correct in seeing that tokens i.e. {Site} do not work in free text KQL and only in Query builder?

    Also, Can I use KQL to select a content source dynamically?

    I'm trying to filter multiple custom fields by the current user: field1:{User} OR field2:{User} OR ...

    ReplyDelete
  33. Query variables are tokens in the query template, not as part of the users search query terms. So you would use the variables in the web parts query template, or in the query template of a result source....what you refer to as the query builder :)

    ReplyDelete
    Replies
    1. Yea I'm a dev so I hate these wizards :)

      Can I select a custom result source with free text KQL? Or do I need a separate landing page for each?

      Delete
    2. Not directly with kql, but you could add a query rule to trigger on something which changed the result source used. That or some fun JavaScript to change the result source on the page :)

      Delete
  34. Hi Mikael, I am on my first journey into configuring custom searches in SharePoint 2013 onsite. I been deep at it for a few days. I have two issues that have been brushed on but I have not been able to find anything that gets me unstuck~!

    I have a file share that is setup as a content source. I have a result source based on that content source. I am getting good results on my searches. The two things I am trying to fix are that I am getting all 56K records returned when I open the search page. I also want to find out how to show the filename instead of title in the results. Please help!

    ~B~

    ReplyDelete
    Replies
    1. In your query template do something like {?{searchterms} contentsource:file} the {?} construct will remove all other parts within if the query variables are empty, like an empty search. Take a look at http://www.techmikael.com/2014/05/s15e03-query-variables-constant-trouble.html

      As for filename, you need to either change the order of crawled properties mapped to the Title managed property so that filename comes first, or use a custom display template where you use the filename managed property instead.

      Delete
  35. Hi Mikael,

    I am wondering how I can search for the term "SharePoint" without it returning results for the sites URL (since the word SharePoint is in the URL (mysite.sharepoint.com)). If I search for the term SharePoint - I get a ton of results because of the URL. I don't want to use queries because I don't want anything to be excluded from the search - I want to be able to search everything that holds the term SP, but I don't want it to return URL's.

    What would be the best way to achieve this using SharePoint Online 2013? Do you have any advice that could help me out?

    ReplyDelete
    Replies
    1. Short answer is to make sure the url is not in the full text index, take a look at http://www.techmikael.com/2014/07/what-makes-sharepoint-column-searchable.html

      Or target a specific property like: body:sharepoint OR title:sharepoint

      But using property queries have issues as well....but you can xrank title/body above others.

      Delete
    2. Ok, I was pretty sure that assigning a low ranking to the URL results would be the only way to achieve what I am trying to do. I really want to be able to search EVERYTHING on the site with the term SharePoint and do whatever I can to prevent a ton of URL's being returned.

      Thank you for your quick response!

      Delete
  36. Hello All, thank you, for this post! I want to know if there is an easy way to exclude items from displaying - for example; by default everything displays in the asset library - I do not want anything to display until after the end-user inputs a search term into the search box.

    ReplyDelete
    Replies
    1. {?{searchTerms} path:http://server/site/assetlib} <- this will omit everything between {?} if the variable is empty. See http://www.techmikael.com/2014/05/s15e03-query-variables-constant-trouble.html for more information

      Delete
  37. Hi,

    This has worked perfect for what I needed. But I have run into one slight problem.

    Is there a way have the result only part match a word? at the moment if I type 'Printing Duplex' I get a result
    but if I I type 'Print Duplex' I don't get a result and there is nothing that matches, same if I search 'print'.
    But if I put in a wild card eg 'Print* Duplex' I get a result.

    I don't want users to have to think about how to search and what words to type, I need the search be happy with part matches. Is this possible?

    Thanks

    ReplyDelete
    Replies
    1. Take a look at https://github.com/SPCSR/HelperFunctions/tree/master/SPO-Search-Improvements and you can either add synonyms or modify the script to automatically append * to all terms.

      So nothing out of the box in 2013. With FAST for 2010 you could accomplish this using n-grams, but this has been deprecated in 2013+.

      Delete
  38. Hi Mikael

    I want to limit the search to only external content type, how can I achieve it using result source.

    Thanks

    ReplyDelete
    Replies
    1. Limit on the content source name for your external source (which you named in the SSA), or use any other managed property you have set up for the data you index from it.

      Delete
  39. Hi, I´m using refiners and Result Source to show documents and want to only show doc from one out of two document libraries (show for "Global docs" and hide for "Archive"). This exclusion works on the Result Source (-Path:Archive) but the refiners does´t seem to adapt this. Where can I configure the refiners to exclude docs the same way? I don´t want to exclude archived docs entirely from the global search because I want the "Search in this list" to work in the Archive library... Any suggestions?

    ReplyDelete
    Replies
    1. If the refinement webpart is hooked to the search result webpart, then the filters added there should be reflected in the refiners. If you click the refiners, are you then getting empty result sets if the refiner is for Archive only... as it seems you are stating?

      Delete
  40. Hi Mikael
    I have noticed that when a search initiated from document library the {searchBoxTerm} variable is expanded while applying the result source it appends a PATH:{DocumentLibraryPath} element along with the search term. This causes the query rule to fail especially when used in context of a property filter like Title:{searchBoxTerm}. Can you advise if there is a way to work around this problem.

    ReplyDelete
    Replies
    1. Hi, is it the triggering which fail, or what is the issue?

      Delete
    2. The issue is search does not return any item when initiated within the document library. But if search is initiated from the site home page it does return results. The default result source uses this rule.
      {?{searchBoxQuery}* (IsDocument:1) title:{searchBoxQuery}* }

      Delete
    3. Does this post help? http://www.techmikael.com/2015/03/how-to-unexpectedly-block-usage-of.html As messing with the default result source hinders library searches.

      Delete
    4. If we do not change the default option then how do we ensure consistency in the site and library search. This would lead to an inconsistent experience.

      Delete
    5. You want to limit all site search to two libraries, and also keep the lib search working. What if you spin up a custom search page for the site, instead of using the osssearchresults?, or customize osssearchresults with a script to change how it queries. See my posts on this: http://www.techmikael.com/2015/07/how-to-do-light-weight-search-center.html http://www.techmikael.com/2015/07/how-to-do-light-weight-search-center_21.html http://www.techmikael.com/2015/07/how-to-do-light-weight-search-center_29.html

      Delete
  41. Hello Mike
    I am new to sharepoint and i need to limit the search within a specific subsite.
    eg. we have 3 subsites a,b,c - if a users searches on a subsite a then the results should be limited to subsite a and same applies to all.
    please advice

    ReplyDelete
    Replies
    1. If you search using the default search box in the site, then you will by default be scoped to that site site only. Either way, if you append: &u=http://server/site/subsite to the URL, it will be scoped to the path of the u parameter :) That's also what SP does when searching in "this location".

      Delete
  42. Hello Mikael,

    thank you for your great post.
    I have to following topic: external lists, containing confidential information needs to be available via Search to certain amount of people. I have create a separate content source and after I read you post I'll exclude them from the search results (what is the best option to implement this one: using "{searchTerms} -ContentSource:ExternalDBName" in search result or using anything else)? And the second question is how to display search results of external list to only specific group of people? At the end normal users should be able to use search normally and the certain amount of people (specific group) should be able to search only external lists.

    Thanks in advance.

    ReplyDelete
    Replies
    1. Excluding with content source is probably easiest and works well. As for excluding based on user, it's doable, but a bit complex. The easier approach is two result web parts, and use audiences to hide/show the right one. Does that work?

      Delete
  43. Hi, Mikael:

    I have a BCS connection and a File Share connection that each have their own content source. I've created a Result Source to use with the search center that was created for the site utilizing this data, but it does not return any results at all. I only want it to show results from these two content sources and a site (https://domain.com/invoices) but I'm starting with the content sources. I can't get anything to work.

    The query I've created is:
    {searchTerms} ContentSource:ECT-InvoicePROD ContentSource:Invoice Shared Drives

    Can you tell me what I'm doing wrong here and how I would add the site to the query?

    ReplyDelete
    Replies
    1. We got it figured out. We needed OR statements. Our final query was:
      {searchTerms} (Path:url) OR (ContentSource:ECT-InvoicePROD) OR (ContentSource:Invoice Shared Drives)

      Delete
    2. Hi,
      happy you solved it. You should also put quotes around multi term names, contentsource="invoice shared drives". And use = instead of : if you have exact matching :) But it should be an implicit OR on properties of the same time. Might be the missig quotes which is the real issue.

      Delete
    3. Thanks so much, Mikael. I had noticed that, too :-) I have another question for you. My developer added a new table to the database that I already have as a BDC (the one used above). She created an ECT to pull information from these new tables, but I cannot find the table columns when I try to map to created a managed property. I've verified permissions on the ECT. I've tried running a full crawl on that LOB, deleting the content source and then adding a new one, deleting the etc and adding a new (recrawling after each item) and I still can't pull in the columns. Can you guide me toward the right direction?

      Delete
    4. Hmm.. you might want to try to set up the bcs crawl on the entity again, and crawled properties should appear. You can also use powershell to see if the crawled property group has automatic creation of crawled properties.. it should but perhaps it's been changed?

      Delete
  44. I have a list that has a bunch of columns. Only if there is a value in a particular column in these list I want the list items to be displayed in the result this value is not a set of values and can keep changing. can you help with the result source

    ReplyDelete
    Replies
    1. You're a bit vague, but something like: mp1=foo OR mp2=foo OR mp3=foo

      Delete
  45. Hi Mikael
    I want to exclude results from a specific managed property but I cannot make that property nonsearchable as I need to search it in other scenarios.
    I've tried 'queryterm -managedpropertyname:queryterm' but this also excludes results where the queryterm is found in the managed property and somewhere else and those results I don't want to exclude. I only want to exclude the results where the querystring is only found in the managed property.
    Is it possible to construct a query which ignores a managed property without excluding the result if the queryterm is found somewhere else on the item?

    ReplyDelete
    Replies
    1. If you have a managed property searchable, the terms are also copied to the full-text index. This means that regardless if those terms were in some other property/document body, the result would be the same.

      But... if you have a document with the term FOO somewhere in text, and BAR in the managed property. Doing -managedproperty:FOO should still show you the document with FOO in the text.

      Could you outline a concrete example where it's not working like you want it to?

      Delete
    2. Sure. It is in people search where I amongst others have the managed properties Department and Memberships. Department is the users department and Memberships are the groups which the user is member of. I want to exclude results from Membership but not if there's a result from Departments (or other fields). So if I'm excluding Memberships with -Memberships:Querystring I'm excluding results from Department also. Department is just an example. The same goes for the rest of the managed properties.

      Delete
    3. To ensure full-text search of user profiles properties, take a look at: http://www.techmikael.com/2014/11/how-to-make-sure-user-profile.html Does this solve your scenario?

      Delete
    4. No, not really - unless you want me to store the membership property in a different full-text index than PeopleIdx. I have no problems with properties not getting indexed.

      Let me try to clarify my example:

      Case 1: Andy has Department=Finance and Membership=[None containing Finance] - Desired result when searching for Finance*: Andy should be in the results.

      Case 2: Billy has Department=Sales and Memberships=FinanceMembershipGroup. Desired result when searcing for Finance*: Billy should not be in the results.

      Case 3: Charlie has Department=Finance and Memberships=FinanceMembershipGroup. Desired result when searcing for Finance*: Charlie should be in the results.

      Delete
    5. Department mp by default is not marked as searchable, so the value in the UPA Department prop will not be full-text. The value in SPS-Department however is not default mapped, and will be searchable.

      I did the following. In two profiles I added "Foo" to ask me about which is in the fti. For one I set Department to "Foo" as well. Searching for Foo* yields both as it's matching ask me about, searching for -department:Foo* Foo* yields only one. So working as expected.

      Values from SPS-Department is not searchable either way, regardless of the cp being marked as included in the fti. And this is the crux. This means it's added to the default fti, not the PeopleIdx. If you want it in the PeopleIdx you have to map it to a searchable mp which is in the PeopleIdx. For user profile properties the common way is to map to the mp named ContentsHidden.

      Hope this explains and solves your issue.

      Delete
  46. **Warning this question isnt related to result sources but moreso query rules**

    Is it possible to exclude any unmatched terms from your query. For example, user issues following query: "massive email mishap"

    I have a query rule already, Query Contains Action Term. Action term is "email," query is changed to "{subject Terms}=email."

    Issuing above query breaks the query, resulting in "nothing here matches your search.

    Is it possible to create a rule that will drop any unmatched term?

    ReplyDelete
    Replies
    1. That rewrite rule looks completely bonkers :) Why do you have =email in there? What's your intent on triggering on "email", and what do you want to do with the remainding terms?

      Delete
  47. Dear all, I would like to exclude a site collection from search results page and also keep this site collection indexed because sites from this site collection must appear in another page. So I followed this procedure : http://sharepoint.stackexchange.com/questions/83994/how-to-exclude-web-application-and-site-collections-from-certain-query-or-search

    I just would like to know whether I only need to follow this procedure to do what I want?

    Sorry I cannot test for the moment because when I click on change query in the Search result webpart, a message appears in the dialog window: an expected error has occurred...

    Do you know where it could come from as well ?

    Thank you for your replies

    Catherine

    ReplyDelete
    Replies
    1. Hi,
      If you either in the search center webpart modify the query template, or create a new result source with the same query template as below you should be ok.

      {searchTerms} -path:https://tenant.sharepoint.com/sites/excludethissitecol

      This will include everything except items below the path excluded.

      As for the error that could be anything I guess, so hard to say something intelligent about it.

      Delete
    2. Hi Mikael, thanks for your quick reply. Have a nice day.

      Kate

      Delete
  48. Hi Mikael, we're trying to apply a result source to our default search center via a URL parameter (this is akin to the 's' parameter from FAST Search which we had in 2010). All of the documentation we found indicates that to use a result source we'd have to create a separate search center and apply the result source to the query (as you demonstrate in this article), but we'd like to have a single results page and apply the result sources based purely on the url param so we can offer our users different curated views of the index.

    ReplyDelete
    Replies
    1. This is probably whay you are looking for: http://www.techmikael.com/2016/05/appending-query-terms-to-search-url.html Which means you send the KQL instead of a scope name. There are other ways using query rules to switch result source as well, but passing as a query param might be easiest.

      Delete
  49. Hi Mikael, Many thanks for this (and many other articles). I have a question that's in the same area as Donna Simpson's above:
    I've defined a Content Source for file shares around a knowledge domain, so that I can add file shares from that section of the company (in this case ICT).
    The crawl works great but I want to make a new result source from that Content Source (not to an individual file share), and I can't get that to work. What I've got is: {searchTerms}(ContentSource="File Shares Informatie Communicatie Technologie"), but it doesn't return any results. I'm a newbie to learning to query.
    Can you help me out?

    ReplyDelete
    Replies
    1. Make sure you have a space between }(. and the text you have is the exact spelling of the content source? If you use the sp query tool, you could inspect the value to make sure as well.

      Delete
    2. Content source being the name given in the SSA.

      Delete
    3. Hmmm,
      I've tried what you suggested above, but still don't get any results. The name of the contentsource is exactly the name I gave it in the SSA, and the crawl returns more than 200,000 items which I can find via search. But adding the content source within a result source isn't working yet.
      Any ideas?

      Delete
    4. Use the SP2013 Query Tool and retrieve the ContentSource managed property as part of the result and see what value the items have.

      Delete
  50. Hello Mike,
    I searched on the blog but did not find a solution, in the search the term "Path" does not work, in an environment works in another no, I never have results:

    {Searchboxquery} (contentclass: STS_ListItem OR IsDocument: True) Path:http://Mysite/Lists/MyList

    I have to take all MyList list items

    ReplyDelete
    Replies
    1. I also created a new managed property equal to "Path", with the "Complete Matching" option not selected, but I have the same problem ... zero results

      Delete
    2. If path:http://server/site/list is not working, then something is weird in that one environment. Have you tried to restart it, or re-index the items? Or have someone modified the path mp?

      Delete
  51. thanks for your reply Mike,

    The only strange thing that is in that environment is that it can be reached with two different addresses, this to allow Windows authentication (http://mysite.com) and siteminder authentication (http://siteminder.mysite.com)

    I tried to index both the first and the second site, but I never find the results through the keyword "path"

    ReplyDelete
    Replies
    1. Can you use the SharePoint Query Tool, and see what the path is for those items you cannot limit to directly?

      Delete
    2. Hi Mike, I answered you a few days ago.
      Using a query tool I control the document path, but using the PATH property I do not find any results. The only thing I could use to find items in a single folder is the CONTENTTYPEID property of the single folder, for example:

      {Searchboxquery} (contentclass: STS_ListItem OR IsDocument: True) contenttypeid: "ǂǂ3078303130303542334130383432383344374541343338354534313533424536303133333543"

      The only drawback is that I do not look for subfolders and I should list them all...

      Delete
    3. My question would be to see which domain was returned on the items, and to ensure your PATH query goes against the primary domain being used when indexing.

      Delete
  52. Hi Mike, the problem is just that, from the query tool I see the documents come back with the following url: http://win.mydomain.com/mydocumentlibraries/document.docx
    And if I go write in the Path query: http: //win.mydomain.com/mydocumentlibraries
    I can not find any documents!
    Even if I insert Path: {Site.URL} I can not find any documents :-(

    The site configuration is the following: the site collection with windows authentication (http://win.mydomain.com), and this runs indexing, then an extension is made for SiteMinder and this extension has another url Of access (http://mydomain.com).

    ReplyDelete
    Replies
    1. Hi... not sure what causes this, and if you do path: http://mydomain.com then still nothing? Could it be an auth issue with the extension auth? What kind of auth is this, and you say it's working with the same setup in another environment? You should check the ULS on the query server on verbose as well when searching for any errors.

      Delete
    2. also with http://mydomain.com still nothing :(

      Thanks, I have to get better with the system engineers

      Delete
  53. Hello Mike,
    Thanks you for your great article.

    I want to know if it's possible to focus the research only in the content (especialy the string) of my document (word, pdf, excel or text).

    When I make a research I get results from Title, path and content but I want just want to analyse the content of my docs.

    I have tried this queryl : {?Content:{SearchBoxQueryl}} but it's not working...

    For example, I get results from document empty which has just the good title or the good path.

    How can I focus my research only on content (string) ?

    Thanks you for your help !!

    ReplyDelete
    Replies
    1. With FS4SP you could do this by having custom full text index fields, which is not really doable in SP2013/2016. You have little control of what goes into the Contents field, so it's not easily solved unfortunately.

      Delete
  54. Hi Mikael,

    Great article! I wish to exclude a single user from the people results in SharePoint Online. I am using the following search string in the query rule-

    Change ranked results by changing the query

    {searchTerms} -UserName:name.surname@company.com {subjectTerms}

    This does not give the desired results. I simply want to exclude the "people search results" for this single user from appearing in the search results. Any suggestions?

    ReplyDelete
    Replies
    1. {searchTerms} -accountname:domain\user

      should do it...replace account name with whatever is in the index in case of claims. You can see this my searching up the person and looking at the value in the accountname managed property.

      And I would rather create a custom result source than using a query rule for this, unless you want to exclude by some trigger.

      Delete
  55. Thank you for sharing this Mikael. Our team will follow carefully as advise here and by mail.

    ReplyDelete