Try our conversational search powered by Generative AI!

Was there a change in what client.Search() returns?


We have a job that finds a particular type of pages, updates and publishes them. If publishing fails a draft is saved.

This is our code to retrieve a page that needs to be updated

return _client.Search<AuthorPage>()
    .Filter(x => x.IsDeleted.Match(false))
    .Filter(x => x.SearchSubsection().Match("Authors"))
    .Filter(x => x.Email.MatchCaseInsensitive(email))
    .Where(x => !x.IsExpired())
    .OrderByDescending(x => x.Status)

We were Ordering by status because we were getting both a published version and a draft; but if there was a draft we wanted to update this version and to try publish it.

And no matter how many times a job would fail to publish a page, it should try to update the same draft. That is how it worked in CMS 11.

Now in CMS 12 under some Author pages we are seeing a lot of drafts and have noticed that the same query even before the FirstOrDefault() already returns only one result - the published version (unless there is no published version and only a draft, then this one is returned). Then the job tries to update it but if it fails it creates a new draft, and the next time it fails it creates yet another draft and so on. Eventually when a page is published we end up with a lot of drafts. 

Was there some kind of change in what Search method returns? 

Is there an overload? Another method? How do we get the same result as before?

Oct 17, 2023 8:23

GetContentResult will simply load the content using GetItems, and I don't see any changes related to that in Find 14

How is IsExpired implemented?

Published is 4, CheckedIn = 3 and CheckedOut = 2 so if you order by Descending, I would say Published version will always be returned. You might want to sort by Ascending instead?

Oct 17, 2023 9:49

Even you simplify to this

                .Where(x => x.ContentLink.ID == 123)

it returns only one result - the published version - even if there is a published version and a draft.

Oct 17, 2023 10:27

was the draft version indexed? can you see it in the index ? 

Oct 17, 2023 10:28

No it does not seem to be added to the index. 

But as it used to be previously, there has been a change somewhere. 

Is accesing the database directly the only way to go around this now?

Edited, Oct 17, 2023 10:52

No you don't have to use database directly. You either can include the draft in your index, or instead of GetContentResult, you call GetResult to get the content link only. then use IContentVersionRepository to load the versions of that content and pick the version you want to edit instead. 

Oct 17, 2023 11:12

What do you mean by " include the draft in your index"?

Oct 17, 2023 11:13

IIRC by default only the published versions are indexed. You can change your convention to include draft versions, but I don't think that is recommended. 

Oct 17, 2023 11:19

But where does one change that?

Oct 17, 2023 11:21

This does not seam to be working : D

var tryingNew = _client.Search<Core.Models.Pages.AuthorPage>()
    .FirstOrDefault(x => x.ContentLink.ID == 117718);

var secondStep = _contentVersionRepository.List(tryingNew?.ContentLink);

BUT GetPagesResult() seems to be working. Any drawbacks that I should be aware of?

Edited, Oct 17, 2023 11:52

For GetResult you have to project your search, something like

_client.Search<AuthorPage>().Select(a => new { a.ContentLink }) .GetResult();

Oct 17, 2023 12:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.