SOLVED

exclude from site search but allow library search

%3CLINGO-SUB%20id%3D%22lingo-sub-1756785%22%20slang%3D%22en-US%22%3Eexclude%20from%20site%20search%20but%20allow%20library%20search%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1756785%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20site%20with%20several%20libraries.%20One%20has%20legacy%20content%2C%20a%20few%20others%20have%20current%20content.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20want%20the%20%22Search%20this%20site%22%20search%20to%20exclude%20the%20legacy%20library%2C%20but%20I%20also%20need%20to%20be%20able%20to%20navigate%20to%20the%20legacy%20library%20and%20use%20the%20%22search%20this%20library%22.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHow%20do%20I%20configure%20this%3F%20When%20I%20exclude%20the%20legacy%20library%20from%20the%20search%20results%20via%20%22Library%20Settings%20%26gt%3B%20Advanced%20Settings%20%26gt%3B%20Allow%20items%20from%20this%20document%20library%20to%20appear%20in%20search%20results%20%26gt%3B%20No%22%20--%20then%20I%20don't%20get%20any%20results%20when%20I%20search%20inside%20the%20library.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAny%20ideas%3F%20This%20is%20for%20the%20MODERN%20experience.%20Please%20no%20suggestions%20about%20classic%20pages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1756785%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESearch%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1757349%22%20slang%3D%22en-US%22%3ERe%3A%20exclude%20from%20site%20search%20but%20allow%20library%20search%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1757349%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F7724%22%20target%3D%22_blank%22%3E%40Ingeborg%20Hawighorst%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20scenario%20that%20you%20are%20talking%20about%20isn't%20possible%20with%20the%20settings%20that%20you%20have%20mentioned%20as%20you%20have%20found%20out.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20want%20to%20be%20able%20to%20search%20the%20content%20in%20the%20library%20from%20the%20library%20which%20means%20the%20content%20has%20to%20be%20indexed.%20The%20setting%20you%20mention%20excludes%20the%20content%20from%20the%20index.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EResult%20sources%20can%20be%20modified%20to%20exclude%20content%20but%20I%20haven't%20found%20a%20way%20to%20exclude%20a%20library%20only%20a%20site.%26nbsp%3B%20The%20only%20thing%20I%20could%20think%20of%20is%20moving%20the%20content%20to%20a%20new%20site%2C%20create%20a%20new%20result%20source%2C%20exclude%20the%20new%20site%20and%20make%20that%20the%20default%20for%20all%20sites.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1761731%22%20slang%3D%22en-US%22%3ERe%3A%20exclude%20from%20site%20search%20but%20allow%20library%20search%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1761731%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214649%22%20target%3D%22_blank%22%3E%40Andrew%20Hodges%3C%2FA%3E%26nbsp%3BYes%2C%20that's%20my%20workaround%20right%20now.%26nbsp%3B%20Thanks%20for%20confirming.%3C%2FP%3E%3C%2FLINGO-BODY%3E
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
Highlighted

@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. 

Highlighted

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

Highlighted

@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???

 

 

Highlighted
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"