diff --git a/Dfe.Data.SearchPrototype/Infrastructure/Builders/SearchOptionsBuilder.cs b/Dfe.Data.SearchPrototype/Infrastructure/Builders/SearchOptionsBuilder.cs
index 980d74b..05b64ad 100644
--- a/Dfe.Data.SearchPrototype/Infrastructure/Builders/SearchOptionsBuilder.cs
+++ b/Dfe.Data.SearchPrototype/Infrastructure/Builders/SearchOptionsBuilder.cs
@@ -12,7 +12,7 @@ namespace Dfe.Data.SearchPrototype.Infrastructure.Builders
public sealed class SearchOptionsBuilder : ISearchOptionsBuilder
{
private readonly SearchOptions _searchOptions;
- private readonly ISearchFilterExpressionsBuilder _searchFilterExpressionsBuilder;
+ private readonly ISearchFilterExpressionsBuilder? _searchFilterExpressionsBuilder;
private SearchMode? _searchMode;
private int? _size;
@@ -29,9 +29,12 @@ public sealed class SearchOptionsBuilder : ISearchOptionsBuilder
///
/// Builds the search filter expression required by Azure AI Search
///
- public SearchOptionsBuilder(ISearchFilterExpressionsBuilder searchFilterExpressionsBuilder)
+ public SearchOptionsBuilder(ISearchFilterExpressionsBuilder? searchFilterExpressionsBuilder = null)
{
- _searchFilterExpressionsBuilder = searchFilterExpressionsBuilder;
+ if (searchFilterExpressionsBuilder != null){
+ _searchFilterExpressionsBuilder = searchFilterExpressionsBuilder;
+ }
+
_searchOptions = new SearchOptions();
}
@@ -140,7 +143,7 @@ public SearchOptions Build()
_searchFields?.ToList().ForEach(_searchOptions.SearchFields.Add);
_facets?.ToList().ForEach(_searchOptions.Facets.Add);
- if (_filters?.Count > 0)
+ if (_filters?.Count > 0 && _searchFilterExpressionsBuilder != null)
{
_searchOptions.Filter =
_searchFilterExpressionsBuilder.BuildSearchFilterExpressions(
diff --git a/Dfe.Data.SearchPrototype/Infrastructure/Tests/Builders/SearchOptionsBuilderTests.cs b/Dfe.Data.SearchPrototype/Infrastructure/Tests/Builders/SearchOptionsBuilderTests.cs
index 141efa6..b94a5b0 100644
--- a/Dfe.Data.SearchPrototype/Infrastructure/Tests/Builders/SearchOptionsBuilderTests.cs
+++ b/Dfe.Data.SearchPrototype/Infrastructure/Tests/Builders/SearchOptionsBuilderTests.cs
@@ -131,5 +131,23 @@ public void Build_WithFilters_CallsFilterBuilder_WithComposedFilterRequests()
matchingFilterRequest.FilterValues.Should().BeEquivalentTo(filterRequest.FilterValues);
}
}
+
+ [Fact]
+ public void Build_WithFiltersNullSearchFilterExpressionsBuilder_ByPassesFilterBuilderCall()
+ {
+ // arrange
+ var serviceAdapterInputFilterRequest =
+ new List() { FilterRequestFake.Create(), FilterRequestFake.Create() };
+
+ ISearchOptionsBuilder searchOptionsBuilder =
+ new SearchOptionsBuilder(searchFilterExpressionsBuilder: null);
+
+ // act
+ SearchOptions searchOptions =
+ searchOptionsBuilder.WithFilters(serviceAdapterInputFilterRequest).Build();
+
+ // assert
+ searchOptions.Filter.Should().BeNull();
+ }
}
}