Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Umbraco 9.4.3 search issue #12551

Closed
pramodbhagat opened this issue Jun 8, 2022 · 6 comments · Fixed by #12612
Closed

Umbraco 9.4.3 search issue #12551

pramodbhagat opened this issue Jun 8, 2022 · 6 comments · Fixed by #12612

Comments

@pramodbhagat
Copy link

pramodbhagat commented Jun 8, 2022

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.4.3

Bug summary

The Search function doesn't work as it always returns 0

Specifics

Hello,

We're building a new site using Umbraco 9.4.3 and we have identified a bug with below Search function doesn't work.

IEnumerable<PublishedSearchResult> Search(IQueryExecutor query, int skip, int take, out long totalRecords);

totalRecords gives the correct count but it always return 0 records where as I would have expected IEnumerable<PublishedSearchResult>

We have tested a fresh DB with Umbraco 9.4.3 and 9.5 and this doesn't work however when I downgrade Umbraco it to 9.3.1 then it works.

Would be good to have a fix or a workaround until we have a fix.

Thanks,
Pramod

Steps to reproduce

With a fresh install of Umbraco 9.4.3 or 9.5 when you call Search function this always returns 0 items where as the out parameter totalItems does returns the total item count.
image

Expected result / actual result

I would have expected an IEnumerable list of PublishedSearchResult as a return type.

@matthewcare
Copy link
Contributor

Hi @pramodbhagat, I hope you're doing well :)

I've opened up a PR to fix your issue. In the meantime a workaround would be to not use IPublishedContentQuery
Since you're already using an IQueryExecutor, you can instead also inject IPublishedSnapshotAccessor

With your variable name searchQuery you will be able to do

_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot);
var queryResults = searchQuery.Execute(new QueryOptions(0, 12));
var totalResults = queryResults.TotalItemCount;
var publishedContentResults = queryResults.ToPublishedSearchResults(publishedSnapshot);

I hope this still helps, even if it is a little late

@martin-rhodes
Copy link

I hope this still helps, even if it is a little late

Not too late for me, who also just stumbled across this nasty little bug! This workaround has helped get the site search back up and running without too much fuss though, so thanks for sharing!

@craigs100
Copy link
Contributor

Have also run into this on V10.0.1. TotalCount correct but records always 0.

Ref: https://our.umbraco.com/forum/using-umbraco-and-getting-started/109441-paged-search-with-iqueryexecutor-problem

@mathewcare 's workaround worked for me.

@pramodbhagat
Copy link
Author

Hi @pramodbhagat, I hope you're doing well :)

I've opened up a PR to fix your issue. In the meantime a workaround would be to not use IPublishedContentQuery Since you're already using an IQueryExecutor, you can instead also inject IPublishedSnapshotAccessor

With your variable name searchQuery you will be able to do

_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot);
var queryResults = searchQuery.Execute(new QueryOptions(0, 12));
var totalResults = queryResults.TotalItemCount;
var publishedContentResults = queryResults.ToPublishedSearchResults(publishedSnapshot);

I hope this still helps, even if it is a little late

Hi @matthewcare,
Good to hear back from you. Hope you're well.

Thanks for responding and this does work for me.

Thanks,
Pramod

@nul800sebastiaan
Copy link
Member

FYI: This is on the list for HQ to review and merge, thanks @matthewcare for the PR!

@nul800sebastiaan nul800sebastiaan added this to the sprint193 milestone Jul 12, 2022
@Zeegaan
Copy link
Member

Zeegaan commented Jul 13, 2022

Fixed in #12612

@Zeegaan Zeegaan closed this as completed Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants