Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
Move filter to post filter
Browse files Browse the repository at this point in the history
Move nationtional provider flag filter to post filter as we require pre
filter numbers in the aggregation.
  • Loading branch information
Lee Wadhams committed Aug 21, 2019
1 parent d24b3ff commit b97b279
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,37 @@ private SearchDescriptor<T> CreateProviderQuery<T>(Expression<Func<T, object>> s
.Must(NestedLocationsQuery<T>(location))))
.Sort(SortByDistanceFromGivenLocation<T>(location))
.Aggregations(GetProviderSearchAggregationsSelector<T>())
.PostFilter(pf => FilterByDeliveryModes(pf, deliveryModes?.Select(x => x.GetMemberDescription() ?? string.Empty)));
.PostFilter(pf => GeneratePostFilter(pf, deliveryModes?.Select(x => x.GetMemberDescription() ?? string.Empty), showNationalOnly));

return descriptor;
}

private static QueryContainer FilterByDeliveryModes<T>(QueryContainerDescriptor<T> descriptor, IEnumerable<string> deliveryModes)
private static QueryContainer GeneratePostFilter<T>(QueryContainerDescriptor<T> descriptor, IEnumerable<string> deliveryModes, bool showNationalOnly)
where T : class, IApprenticeshipProviderSearchResultsItem
{
if (deliveryModes == null || !deliveryModes.Any())
{
return descriptor;
}

if (showNationalOnly)
{
return descriptor.Bool(b => b
.Filter(
f => f
.Terms(t => t
.Field(x => x.DeliveryModesKeywords)
.Terms(deliveryModes)),
f => f
.Term(t => t
.Field(x => x.NationalProvider)
.Value(showNationalOnly))));
}

return descriptor
.Terms(t => t
.Field(x => x.DeliveryModesKeywords)
.Terms(deliveryModes));
.Terms(t => t
.Field(x => x.DeliveryModesKeywords)
.Terms(deliveryModes));
}

private Func<AggregationContainerDescriptor<T>, IAggregationContainer> GetProviderSearchAggregationsSelector<T>()
Expand All @@ -122,11 +136,6 @@ private static QueryContainer FilterByDeliveryModes<T>(QueryContainerDescriptor<
yield return f => f.Term(t => t.Field(selector).Value(apprenticeshipIdentifier));

yield return f => f.Term(t => t.Field(fi => fi.HasNonLevyContract).Value(showForNonLevyOnly));

if (showNationalOnly)
{
yield return f => f.Term(t => t.Field(fi => fi.NationalProvider).Value(showNationalOnly));
}
}

private Func<QueryContainerDescriptor<T>, QueryContainer> NestedLocationsQuery<T>(Coordinate location)
Expand Down

0 comments on commit b97b279

Please sign in to comment.