November Happy Hour will be moved to Thursday December 5th.

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

EVT
EVT
Vote:
 

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))
    .GetContentResult()
    .Where(x => !x.IsExpired())
    .OrderByDescending(x => x.Status)
    .FirstOrDefault()

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?

#311005
Oct 17, 2023 8:23
Vote:
 

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?

#311007
Oct 17, 2023 9:49
EVT
Vote:
 

Even you simplify to this

_client.Search<Core.Models.Pages.AuthorPage>()
                .Take(1000)
                .GetContentResult()
                .Where(x => x.ContentLink.ID == 123)

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

#311008
Oct 17, 2023 10:27
Vote:
 

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

#311009
Oct 17, 2023 10:28
EVT
Vote:
 

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?

#311010
Edited, Oct 17, 2023 10:52
Vote:
 

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. 

#311011
Oct 17, 2023 11:12
EVT
Vote:
 

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

#311012
Oct 17, 2023 11:13
Vote:
 

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. 

#311017
Oct 17, 2023 11:19
EVT
Vote:
 

But where does one change that?

#311018
Oct 17, 2023 11:21
EVT
Vote:
 

This does not seam to be working : D

var tryingNew = _client.Search<Core.Models.Pages.AuthorPage>()
    .Take(1000)
    .GetResult()
    .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?

#311020
Edited, Oct 17, 2023 11:52
Vote:
 

For GetResult you have to project your search, something like

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

#311023
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.