Forum Discussion

mattchowell's avatar
mattchowell
Iron Contributor
Aug 10, 2022
Solved

Restrict kql search query to specific div in a page

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

 

  • Hello mattchowell 

     

    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:

     

    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

     

2 Replies

  • Hello mattchowell 

     

    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:

     

    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

     

    • mattchowell's avatar
      mattchowell
      Iron Contributor

      DaveMehr365 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