SOLVED

exclude from site search but allow library search

MVP

I have a site with several libraries. One has legacy content, a few others have current content.

 

I want the "Search this site" search to exclude the legacy library, but I also need to be able to navigate to the legacy library and use the "search this library".

 

How do I configure this? When I exclude the legacy library from the search results via "Library Settings > Advanced Settings > Allow items from this document library to appear in search results > No" -- then I don't get any results when I search inside the library.

 

Any ideas? This is for the MODERN experience. Please no suggestions about classic pages.

 

4 Replies

@Ingeborg Hawighorst 

 

The scenario that you are talking about isn't possible with the settings that you have mentioned as you have found out. 

 

You want to be able to search the content in the library from the library which means the content has to be indexed. The setting you mention excludes the content from the index. 

 

Result sources can be modified to exclude content but I haven't found a way to exclude a library only a site.  The only thing I could think of is moving the content to a new site, create a new result source, exclude the new site and make that the default for all sites. 

@Andrew Hodges Yes, that's my workaround right now.  Thanks for confirming.

@Andrew Hodges You say "Result sources can be modified to exclude content". Can you explain how?

 

I moved the legacy library to a sub site, but now the search results contain documents from the sub site. What do I need to do to remove the sub site results from the "Search this site" results???

 

 

best response confirmed by Ingeborg Hawighorst (MVP)
Solution

Found it. It's a bit fiddly to set up. I configured the Result Sources for the site ( not the site collection or the tenant) this way:

 

  • Site Settings > Search > Result Sources (don't use Search Result Sources under Site Collection Administration!)
  • New Result Source
  • Query transform uses 
    {searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/thelibrary"
    The crucial bit here is that the URL needs to be in double quotes. The search builder is very unhelpful, because it doesn't indicate that and doesn't put the quotes in. 
  • Save and in the list of result sources, select the dropdown of the new source and set it as the default.

According to the KQL syntax reference, it is possible to add multiple conditions for the same property, so I can include several libraries -- and by including only some, at the same time exclude others like this

 

{searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryA" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryB" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryC"

1 best response

Accepted Solutions
best response confirmed by Ingeborg Hawighorst (MVP)
Solution

Found it. It's a bit fiddly to set up. I configured the Result Sources for the site ( not the site collection or the tenant) this way:

 

  • Site Settings > Search > Result Sources (don't use Search Result Sources under Site Collection Administration!)
  • New Result Source
  • Query transform uses 
    {searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/thelibrary"
    The crucial bit here is that the URL needs to be in double quotes. The search builder is very unhelpful, because it doesn't indicate that and doesn't put the quotes in. 
  • Save and in the list of result sources, select the dropdown of the new source and set it as the default.

According to the KQL syntax reference, it is possible to add multiple conditions for the same property, so I can include several libraries -- and by including only some, at the same time exclude others like this

 

{searchTerms} Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryA" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryB" OR Path:"https://thetenant.sharepoint.com/sites/thesite/LibraryC"

View solution in original post