Forum Discussion
Oct 08, 2020
exclude from site search but allow library search
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 t...
- Oct 09, 2020
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"
Andrew Hodges
Oct 08, 2020Bronze Contributor
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.
- Oct 08, 2020
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???
- Oct 09, 2020
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"
- Oct 08, 2020
Andrew Hodges Yes, that's my workaround right now. Thanks for confirming.