question

CaMeL-1223 avatar image
0 Votes"
CaMeL-1223 asked CaMeL-1223 commented

Limit Search Results (SP Online)

Hello,

I have a issue with limiting search results using PnP Modern Search.

In addition to pulling all *.docx documents from the document library, I would like to skip those that have the name "Attachments" in the path.

I have a KQL query:
{searchTerm} path:http://sp.online/Documents fileextension:docx

How can I exclude those files which have the word Attachments in the path (this is the name of the folder)?

Thank you!

office-sharepoint-online
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Since the issue is more related to SharePoint Online, I have changed the most appropriate tag for you, this will help to make the thread in specific technology is really associated with this tag.

0 Votes 0 ·
JoyZ avatar image
0 Votes"
JoyZ answered CaMeL-1223 commented

@CaMeL-1223,

Per my test, if the "Attachments" is the folder name, and we could use KQL to exclude all documents in this folder:

 {searchTerms}
    
 fileextension:docx
    
 path:https://tenant.sharepoint.com/sites/Team1/lib76/
    
 -path:https://tenant.sharepoint.com/sites/Team1/lib76/*/Attachments/*

Before:

121479-image.png

After:

121542-image.png


If an Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (75.3 KiB)
image.png (50.6 KiB)
image.png (75.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@JulieWang-MSFT it works!

0 Votes 0 ·
AdnanDedic avatar image
0 Votes"
AdnanDedic answered JoyZ commented

Hi,


You can use NOT or - exclusion operator:

title:Advanced title:Search title:Query NOT title:"Advanced Search Query"
title:((Advanced OR Search OR Query) -"Advanced Search Query")

Just replace property names and keywords.
Source: keyword-query-language-kql-syntax-reference

BR,
Adnan


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Thanks.

What about Path parameter as I have already used this one to limit the scope of the search (document library only).

Query like this does not work - meaning I see all docx files within Document library but also those one with Attachments word in the path:
{searchTerm} path:http://sp.online/Documents fileextension:docx -path:Attachments

0 Votes 0 ·

Hi,

You are welcome.

If you want to use path then it should be something like:

 path:"http://sp.online/Documents/*" -path:"http://sp.online/Documents/Attachments/*"  fileextension:docx

BR,
Adnan

0 Votes 0 ·

Hi,

Thanks.

What if between Documents there is a folder that name is different for each item, e.g.:
1. https://sp.online/sites/DEV/Documents/Test1/Attachments
2. https://sp.online/sites/DEV/Documents/Test2/Attachments
3. https://sp.online/sites/DEV/Documents/Test3/Attachments
4. https://sp.online/sites/DEV/Documents/Test4/Attachments

So I would like to skip those entries that contains Attachments in the path.

I tried like this but does not work:

 {searchTerms} path:https://sp.online/sites/DEV/Documents -path:https://sp.online/sites/DEV/Documents/*/Attachments/* fileextension:docx


0 Votes 0 ·

Hi,

You are welcome.
The wildcard operator is supported only at the end of the phrase.
This can easily be done with CAML query but it's little bit tricky with KQL and exclusions, because you must know the first part of the URL's (before /Attachments).

BR,
Adnan

0 Votes 0 ·

In order to get a better forum experience, please use Comment instead of Write an Answer section to post the reply unless when you provide a valid solution to the question. We will be converting this reply for you.

0 Votes 0 ·