Forum Discussion
exclude from site search but allow library search
- Oct 09, 2020Found 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 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???
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"