CSWP ignores path for some search terms

Fredrik Gustafsson 1 Reputation point
2020-10-06T17:17:33.917+00:00

Our setup:
On prem Sharepoint 2016.
We have a Content By Search Webpart on a search page in a site collection. On the same page is also a search box webpart. There are also many other site collections with the same kind of search page with the same CSWP and the same settings. You can say that each site collections represents a project site.
The query text in the CSWP is as follows:

{SearchBoxQuery}* path:"{\Site}/mydocliburl"

The result source is specified as Local Sharepoint Results

Our problem:
In one of our site collections, if I search for "myspecificterm" on this page, I will get results from other document libraries than specified in the path parameter. Even document libraries in OTHER site collections!
This happens when I search on the test tab in CSWP query settings too, even though I can see the generated query text to the left containing my very specific path parameter.

  • The settings for the CSWP are identical with the settings in the other CSWPs on the other
    site collections where it works. Only the generated final query text path url differs slightly as expected.
  • The rogue search results only appear if we specify "myspecificterm" precisely, if instead we search for
    "myspecific" there will be less but correct results.
  • Using {\SiteCollection.URL} to build the path instead of {\Site} makes no difference
  • No refiners on refiners tab
  • Settings tab settings are: use query rules, use url settings from catalog, regular priority and no caching
  • The only thing specified on the sort tab is sort by Rank
SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,190 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,565 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Itch Sun-MSFT 2,556 Reputation points
    2020-10-07T09:15:22.707+00:00

    Hi @Fredrik Gustafsson

    Please try the following query text:

    {{searchTerms} Path:”https://siteUrl/SearchDocumentsLibrary/” }  
    

    In addition, please click the test query button to check the result.

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

    0 comments No comments

  2. Fredrik Gustafsson 1 Reputation point
    2020-10-08T15:00:57.297+00:00

    Hi @Itch Sun-MSFT , thank you for your answer.

    Unfortunately it does not make any real difference. The addition of curly brackets around the entire statement does exclude some results for some searches. The default search with no search parameter input returns zero results with curly brackets instead of all documents of the document library when not using curly brackets.

    But when I do a search with some input, i.e. "myspecificterm" as mentioned in the original post, I still get the results from other document libraries in the same site collection and also the results from other site collections. I can see that only one result is missing from the original setup, and that result actually WAS in the correct document library.

    One peculiar observation:
    I happened to mistype {SearchBoxQuery} as {SearchBoxScript} when trying different things. Obviously {SearchBoxScript} is not a valid query variable, however, I can still give it a value on the test tab and run test query. And then...it works!?. I can use any word within curly brackets EXCEPT for {searchTerms} or {SearchBoxQuery} in my query and assign a value in the test tab with correct results. This won't work on the page itself of course since there is no input to my made up variables.

    0 comments No comments

  3. sadomovalex 3,626 Reputation points
    2020-10-09T15:33:29.917+00:00

    try first with just:

    Path:{SiteCollection.URL}
    

    (without /mydoclib part). Will it limit results to the current site collection only in this case?

    0 comments No comments

  4. Fredrik Gustafsson 1 Reputation point
    2020-10-12T15:28:34.82+00:00
    {SearchBoxQuery}* Path:{SiteCollection.URL}
    

    yields results from another Site Collection when I test it with "myspecificterm"

    If I don't use a search term at all when testing or if I remove {SearchBoxQuery} it yields to many results (240 000, it's a large project site, many documents) so I can't really tell.


  5. Cantrell, Eric 1 Reputation point
    2021-09-03T17:42:29.203+00:00

    Were you able to fix this issue? I just ran into the same thing and despite many remediation options I'm still going in circles.

    0 comments No comments