Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Hi,
you can use .OrFilter(...) to do that.
http://find.episerver.com/Documentation/dotnet-api-filtering
Hi Per,
Thanks for that, I can't believe I didn't spot that!
AlIhough it works it doesn't quite help with my scenario though. I'm building a query with section and sub section and then adding any selected filters afterwards. While this mostly works it's producing an OR where not quite needed when I have more than one filter, what it's doing is:
Section AND SubSection AND Filter1 OR Filter2
What I need is something like
Section AND SubSection AND (Filter1 OR Filter2)
My query is as follows:
var query =
SearchClient.Instance.UnifiedSearchFor(this.SearchTerm)
.TermsFacetFor(x => x.SearchSection)
.TermsFacetFor(x => x.SearchSubsection)
.Skip((PagingPage - 1) * CurrentPage.PageSize)
.Take(CurrentPage.PageSize);
if (!String.IsNullOrWhiteSpace(SearchSection))
{
query = query.Filter(x => x.SearchSection.Match(SearchSection));
}
if (!String.IsNullOrWhiteSpace(SearchSubSection))
{
query = query.Filter(x => x.SearchSubsection.MatchCaseInsensitive(SearchSubSection));
}
foreach (string filter in this.SelectedFilters)
{
if (this.SelectedFilters.First() == filter)
{
query = query.Filter(x => x.SearchCategories.MatchCaseInsensitive(filter));
}
else
{
query = query.OrFilter(x => x.SearchCategories.MatchCaseInsensitive(filter));
}
}
Check out the BuildFilter<T> method, it is documentet on the page I linked to earlier. Maybe it will solve your problem.
Hello,
Now here's one for you. I am applying filtering but want it to be OR so that if two filters are selected it resturns results that match both filters, if I turn one off it only shows results for the remaining.
I'm using the below where selected filters is a List<string>
foreach (string filter in this.SelectedFilters)
{
query = query.Filter(x => x.SearchCategories.MatchCaseInsensitive(filter));
}
Now where there is more than one filter this works using AND which is logical and what you would expect. I need this to work as OR but can't find any examples of how I might achieve this.
Sorry this is probably really obvious but some pointers would be good.
Thanks in advance,
Mark