Try our conversational search powered by Generative AI!

Filtering specific page type result on number of items in content area

Vote:
 

Hi,
I have an article page type with a content area (CrossPublishing) that has only two other object types allowed to be created in it. Both of those two types have been decorated with the [IndexInContentAreas] attribute and in the Search and Navigation dashboard under the Overview I can see that the content of given content area gets indexed properly.

I want to filter on article pages with more than two items in that content area and with this piece of code 

var res = _searchClient
                .Search<ArticlePage>(lang)
                .For(query)
                .UsingSynonyms()
                .WithAndAsDefaultOperator()
                .InField(x => x.Name, 2)
                //........ left out for clarity
                .AndInField(x => x.CrossPublishing)
                .AndInField(x => x.SearchText(), 1)
                .Filter(x => x.VisibleInMenu.Match(true))
                .Filter(x => !x.Ancestors().In(_pagesNotVisibleInMenu))
                .Filter(x => x.CrossPublishing.FilteredItems.Count().GreaterThan(1))  // <= this line is only one of the tried possibilities
                .OrderBy(x => x.Created, null, SortOrder.Descending, false)
                .Take(take)
                .Skip(skip)
                .FilterForVisitor()
                .Track()
                .GetContentResult();

I always get 0 in Items and TotalMatching on the res object. 

Is it even possible to use filtering on number of content area items or filtered items with use of .Count() and .GreaterThan(x) or .Match(x)?

#277549
Edited, Mar 31, 2022 10:05
Vote:
 

Hi,

Assuming you're just interested in filtering by the number of items in the contentarea (rather than the number of filtered items), there's a Count property on the ContentArea which should be indexed so you can filter using that property like this:

.Filter(x => x.CrossPublishing.Count.GreaterThan(1))

Normally I'd encourage the use of FilteredItems when dealing with a ContentArea however, in this instance we're dealing with data in the search index so, even if you index the value of FilteredItems.Count(), it won't return a meaningful value (i.e. one which takes visitor groups and permissions of the current user into account).

#277601
Apr 01, 2022 12:00
* 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.