microsoft-search / pnp-modern-search

Home of PnP Modern Search solutions, helping you move from classic to modern SharePoint and beyond
https://microsoft-search.github.io/pnp-modern-search
Other
376 stars 330 forks source link

Results shown when search box is empty #1721

Closed abhitalks closed 1 year ago

abhitalks commented 2 years ago

Version used 4.5.3

Describe the bug The search results should be empty with no results when no search term has been entered in the search box. E.g. an empty search box at page load. This is happening even when "Use a default value" is unchecked. According to documentation: "Optionaly, you can set a default query text when there is no value for the connected source (ex: an empty search box at page load)".

Still every time user goes to the search page, they are greeted with random search results.

To Reproduce Steps to reproduce the behavior:

  1. Go to search results web parts settings
  2. On connections tab connect to search box, and leave the "Use a default value" checkbox unchecked
  3. Publish the page
  4. Browse to the search page to see search results without entering anything in search box.

Expected behavior On page load when a user visits the search page, the search box is empty and so the search results should also be empty.

Screenshots pnp-srch-default

Desktop (please complete the following information):

Additional context Upgraded from v4.1 was the last change.

wobba commented 2 years ago

From the image above seems you have not picked a value in the "PnP - Search Box's properties"

Works as expected on my end. image

abhitalks commented 2 years ago

From the image above seems you have not picked a value in the "PnP - Search Box's properties"

Thanks @wobba, but I have selected "Search Query" option. I did try selecting it with mouse and keyboard both. It shows as selected when returning to it later. When I change the "Connect to Source" to something else like "Page Environment" and related properties, it works. But the moment I set source as "Search Box" and select "Search Query", it reverts back to showing results as shown in the screenshot above.

Do you need me to share a screen recording with you?

wobba commented 2 years ago

@abhitalks I cannot repro. Do you have {searchTerms} in the query template field?

till-llit commented 2 years ago

we have 2 tenants - i can reproduce this behaviour only in one of them

in our test tenant (targeted release) i get results with empty query from PNP Modern Search Result Webpart.

with 100% identical configuration i receive no results in our Productive Tenant (standard release).

@abhitalks : do you have targeted release (user or tenant) enabled in your setup?

abhitalks commented 2 years ago

@abhitalks I cannot repro. Do you have {searchTerms} in the query template field?

@wobba Yes. Here is the value that I have in my "query template" field: {searchTerms} -path:https://tenant-my.sharepoint.com.

It was working fine before, and sadly I really don't know when exactly it stopped working and what triggered it. I came to realize only after users started complaining earlier this month. I thought maybe v4.1 needed to be upgraded and so I did that and upgraded to v4.5.3. But, it still doesn't work.

abhitalks commented 2 years ago

@abhitalks : do you have targeted release (user or tenant) enabled in your setup?

Yes we have "targeted release" enabled at tenant level.

wobba commented 2 years ago

That helps and I can repro.. and it is correct. The correct query template should be:

{?{searchTerms} -path:https://tenant-my.sharepoint.com}

except that fails as well. Agree that the above template should work @FranckyC? Similar to classic. If {searchTerms} is empty, then remove the full template.

FranckyC commented 2 years ago

Could be fixed by this PR https://github.com/microsoft-search/pnp-modern-search/pull/1692. Can you try with the current develop branch?

till-llit commented 2 years ago

is there a sppkg available for the develop branch? i do not have a build environment available

abhitalks commented 2 years ago

That helps and I can repro.. and it is correct. The correct query template should be:

{?{searchTerms} -path:https://tenant-my.sharepoint.com}

except that fails as well. Agree that the above template should work @FranckyC? Similar to classic. If {searchTerms} is empty, then remove the full template.

It doesn't work even if I remove the OneDrive exclusion and simply use {searchTerms} on its own.

BTW: How is {inputQueryText} token different from {searchTerms}?

wobba commented 2 years ago

if you have {searchTerms} only it should work - unless you have a result source with a filter as well. Your short term workaround is to keep {searchTerms} as the template in the web part and create a result source with {?{searchTerms} -path:https://tenant-my.sharepoint.com} in it, and reference that result source.

inputQueryText is a web part specific token, searchTerms can be evaluated on the server when using the SharePoint provider.

FranckyC commented 2 years ago

inputQueryText is a web part specific token, searchTerms can be evaluated on the server when using the SharePoint provider.

That's right and I changed to this behavior recently in the develop branch so you may not have the latest version here. That could explain.

wobba commented 2 years ago

@FranckyC I now see the full template {?{searchTerms} -path:https://tenant-my.sharepoint.com} is passed along the query 🙂 If you build the dev branch it should fix your issue @abhitalks.

FranckyC commented 2 years ago

Will be resolved in the upcoming 4.5.4 version.

fug4zi commented 2 years ago

Configured today and i have the same issue with version 4.5.4

Tried these

{?{searchTerms} -path:https://tenant-my.sharepoint.com}
{?{searchTerms} path:https://tenant-my.sharepoint.com}
{searchTerms}
abhitalks commented 2 years ago

@FranckyC and @wobba, the issue persists in v4.5.4 irrespective of {?{searchTerms} -path:https://tenant-my.sharepoint.com} or just {searchTerms}.

When the search box is empty, the results are still shown.

wobba commented 2 years ago

@abhitalks this is an internal Microsoft bug which I'm trying to track down if can be fixed. It does not affect all tenants and I do have repro.

Hickey77 commented 2 years ago

Any updates on this issue? Was able to work around with default value of ""

stevebeauge commented 2 years ago

Same root cause than #1535 ?

wobba commented 2 years ago

@stevebeauge they seem to be the same yes. And I don't have an update.

Hickey77 commented 2 years ago

Thanks guys. Trying to use this to solve a big problem with Viva Connections for a large customer (Lack of SPO search in some Viva C clients)

tmccart1 commented 1 year ago

Has this been fixed yet? I am also seeing search results on page load even though I have the correct syntax in the query template field.

{?{searchTerms} -path:https://tenant-my.sharepoint.com}

I am using version 4.7.0.

wobba commented 1 year ago

It's an API issue, not web part issue. Feel free to log a support case with Microsoft to push this.

heinrich-ulbricht commented 1 year ago

We are currently struggling with search results being shown for an empty search box when using the "Microsoft Search" source (not SharePoint Search). Which source is this issue about?

wobba commented 1 year ago

Change the query template to {?{searchTerms}}. Then you get 0 when the search term is empty. @abhitalks would this solve it for you as well?

wobba commented 1 year ago

@heinrich-ulbricht what does the query (JSON) look like with the Graph source? An empty query string? Could be that we need to add logic in the web part to not make an API query if it's empty.

heinrich-ulbricht commented 1 year ago

@wobba I currently don't have access to the affected site but will hopefully be able to check back when I do have it again. But that was my guess also; that the API handles an empty query like "*" and the web part would have to take care of this.

wobba commented 1 year ago

@FranckyC Seems like for an empty query and the use of template {?{searchTerms} -path:https://tenant-my.sharepoint.com} we pass down {? -path:https://tenant-my.sharepoint.com}.

Seem we should add a check in TokenService that if a token which works behind the scenes is empty, we should not remove it and pass it down to the service. That or add logic to honor {?..} notation.

Lisa-G531 commented 1 year ago

I'm having the same issue. Results are show on page load and while the Search Box is empty. PnP Search Version 4.2.3 Works fine in UAT and Test but not in Prod.

PnP Search V4 - Bug

wobba commented 1 year ago

This is actually an API issue where an empty query sent is now returned as a * query, and we will try to fix it in the web part itself when connected to a search box. And happens when extra parameters are in the query template.

silersbald commented 1 year ago

I was also having results show on page load in version 4.8. After reading this thread I was able to fix it by using {?{searchTerms} Path:{Site} } for the query template and checking the "Use a default value" box. I left the Default value field empty.

thatcow commented 1 year ago

I was also having results show on page load in version 4.8. After reading this thread I was able to fix it by using {?{searchTerms} Path:{Site} } for the query template and checking the "Use a default value" box. I left the Default value field empty.

Thanks for this. It works for me as well.

sharepointnewbie commented 1 year ago

I was also having results show on page load in version 4.8. After reading this thread I was able to fix it by using {?{searchTerms} Path:{Site} } for the query template and checking the "Use a default value" box. I left the Default value field empty.

I tried this, and whilst it initially appeared to work it was actually just ignoring the path that created the problem in the first place. In my cased I want to limit search to a particular document folder

{searchTerms} path: https://company.sharepoint.com/sites/Technical/shared%20documents/products

The following defaults to listing all documents within the folder, before a search is entered. This is with version 4.8.

If I revert to just {searchTerms}

Results are not shown until a search is entered, but of course the result include all sites, onedrive etc. Anyone found a working solution?

PS Be gentle with me, i'm no programmer, litterally just picked up sharepoint and finding my way through to get an operational site.

till-llit commented 1 year ago

@sharepointnewbie is there a space between "path:" and the url? it should read

path:https://company.sharepoint.com/sites/Technical/shared%20documents/products

without a searchterm this query will always return all results from the given site collection.

to avoid this i would advise to create a search result source with the path included in the query and use this result source for your search results webpart.

sharepointnewbie commented 1 year ago

@sharepointnewbie is there a space between "path:" and the url? it should read

path:https://company.sharepoint.com/sites/Technical/shared%20documents/products

without a searchterm this query will always return all results from the given site collection.

to avoid this i would advise to create a search result source with the path included in the query and use this result source for your search results webpart.

@till-llit thanks for the reply. Sorry no space, that was a typo

I would like to see result from ONLY the path mentioned, but see no results until a search term is entered (the same way it behaves with the default query of {searchTerms}

I cannot find how to create a search result source as you suggest.

till-llit commented 1 year ago

you can create a result source either tenant wide in the sharepoint admin or on a site collection level.

if you are site collection admin you can go to site settings -> search result source to create one:

https://company.sharepoint.com/sites/Technical/_layouts/15/manageresultsources.aspx?level=sitecol or whatever your Search Site Collection is where you use the pnp search webparts.

afterwards you need to scope the search result webpart to utilize this search result source in the webpart settings.

pquinn1212 commented 1 year ago

Hi All,

Just out of curiosity did this get fixed atall ? i am on version 4.8.0 and had this issue come up this morning. It was working fine yesterday then all off a sudden the search results has information in.

image

I am using the default Wikiscope which was fine last night. My query template is just {searchTerms} i have also tried {?{searchTerms}} but still the same, the only thing i did yesterday was reindex the database and also create a new query scope ?

Thanks

sam888k12 commented 1 year ago

For anyone still having trouble, double check your syntax. I was confused by this {?{searchTerms}} and put the path:tenantURL after the second } like this: {?{searchTerms}} path:https://company.sharepoint.com/sites/Technical/shared%20documents/products

When I fixed it to {?{searchTerms} path:https://company.sharepoint.com/sites/Technical/shared%20documents/products} it worked and the search results was empty if the search box has not been populated.

wobba commented 1 year ago

Made a fix for {?{searchTerms}} notation when searchTerms is empty in #3028