Hi,
I have a Find query where I search for a specific page type and I want to filter that query on items in the page's ContentArea. I´ll try to explain:
There is a page type called PartnerPage and on that page there is a ContentArea property called ProductAreas where editors can drag and drop pages of page type SystemTagPage. I need to filter on the SystemTagPage's Name property against a product area (string) which is selected from a list in the view.
This is the Find query:
var result = SearchClient.Instance.Search<PartnerPage>() .Filter(x => x.Ancestors().Match(ContentReference.StartPage.ID.ToString())) .Filter(filterBuilder) .FilterForVisitor() .OrderByDescending(x => x.StartPublish) .GetPagesResult(LanguageSelector.AutoDetect());
And the filter (the filterBuilder variable in the query) is created like this:
var filterBuilder = SearchClient.Instance.BuildFilter<PartnerPage>(); if (!string.IsNullOrWhiteSpace(country)) { filterBuilder = filterBuilder.And(x => x.Country.Match(country)); } if (!string.IsNullOrWhiteSpace(productArea)) { filterBuilder = filterBuilder.And(x => x.ProductAreas.Items.Select(c => c.GetContent().Name).Match(productArea)); } return filterBuilder;
I can´t get the filter to work, when debugging I see that the Field of the filter is called "GetContent.Name.ProductAreas.Items.Select$$string" and I guess that´s why I don´t get any hits, there is no property with that name. But I´m not sure how the filter should be written to accomplish this, any ideas? Might not even be possible since a ContentArea and its items are a bit different from "normal" properties.
My solution right now is to skip the filter for product area and do a Linq query on the finished result from Find instead but that doesn´t feel like a good solution, like this:
items.AddRange(from page in result from item in page.ProductAreas.Items where item.GetContent().Name == productArea select page);
Any ideas and information is welcome! Thanks!
BR, Petra