SOLVED

Restrict kql search query to specific div in a page

Iron Contributor

I'm using PnP modern search web parts but the question applies to Sharepoint search in general. I'm restricting my search to published news posts but on the new post pages, there's a "recent posts" news web part so search includes content from that web part. As an example I have posts titled "post a" and "post b". If I search for "a"  I get both posts returned because search find the "b" in the news web part.   Is there a way to refine the search query to only look at the "canvascontent" field ie the body  of the post, excluding other web parts on the page? Something like:

{searchTerms} Path: "https://xxx.sharepoint.com/sites/xxx/SitePages" RefinableString01:xxx PromotedState:2 FIELD:CANVASCONTENT

 

2 Replies
best response confirmed by matt howell (Iron Contributor)
Solution

Hello @matt howell 

 

to restrict the query for a specific field only, you can use {searchTerms} in your query.

 

Here is an example:

contentclass:STS_ListItem_WebPageLibrary IsContainer<>true RefinableString101:{searchTerms}

 

I have mapped the crawled property ows_CanvasContent1 to a managed property RefinableString101:

DavidMehr_1-1660202074435.png

 

contentclass and iscontainer are only additional parameter to specific search for pages, without template folder. You can define them according to your choice.

 

Hope this helps.

 

Regards, Dave

 

@David Mehr Thanks, this worked great!

Path: https://xxx.sharepoint.com/sites/xxx/SitePages PromotedState:2 contentclass:STS_ListItem_WebPageLibrary IsContainer<>true RefinableString09:{searchTerms} -ContentClass=urn:content-class:SPSPeople

 

1 best response

Accepted Solutions
best response confirmed by matt howell (Iron Contributor)
Solution

Hello @matt howell 

 

to restrict the query for a specific field only, you can use {searchTerms} in your query.

 

Here is an example:

contentclass:STS_ListItem_WebPageLibrary IsContainer<>true RefinableString101:{searchTerms}

 

I have mapped the crawled property ows_CanvasContent1 to a managed property RefinableString101:

DavidMehr_1-1660202074435.png

 

contentclass and iscontainer are only additional parameter to specific search for pages, without template folder. You can define them according to your choice.

 

Hope this helps.

 

Regards, Dave

 

View solution in original post