Try our conversational search powered by Generative AI!

Rewriting a query from GetContentResult() to GetSearch()

EVT
EVT
Vote:
 

I had the following query 

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) --no longer need here
    .FirstOrDefault(); --no longer need here

Now I need to rewrite it to use .GetResult() to get the ContentLink.ID. I do not seem to find a way to combine all of the following

  • to filter out deleted and expired items,
  • to search only in a particular folder,
  • to match an email
  • and then return the ContentLink.ID

Anyone able to assist with this? = )

#311024
Oct 17, 2023 14:24
Vote:
 

You can use all of the filters except the one with IsExpired before the .Select projection. 

return _client.Search<AuthorPage>()

    .Filter(x => x.IsDeleted.Match(false))

    .Filter(x => x.SearchSubsection().Match("Authors"))

    .Filter(x => x.Email.MatchCaseInsensitive(email))

    .Select(x=> new { x.ContentLink } )

.GetResults();

i am on phone now so can't verify but it should just work

#311026
Oct 17, 2023 18:03
EVT
Vote:
 

I am not getting any results your way. Three ways I tried it, the results are below. The first (anotherTrial)  tried without the Take(1000) first, did not work either

#311065
Oct 18, 2023 6:35
Vote:
 

The test is not equipvalent as far as I can tell because the resultId is without the subsection matching for "Author"? 

#311066
Oct 18, 2023 7:09
EVT
Vote:
 

You are right, missed that.

Another question - previously with one query I was getting and returning a page. 

Now first I get content link. Then I have to use contentVersionRepository to get a version. And then I still need to get an actual page. 

Isn't there a shorter way to accomplish this?

#311072
Oct 18, 2023 10:56
Vote:
 

no shorter way that I know of to achieve what you want. GetContentResult only gets the content behind the scene, but you can't control which version you want to get.

I'd reckon what you are doing is the right way - it gives you total control of what you get 

#311073
Oct 18, 2023 10:59
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.