Skip to content

Commit

Permalink
Fixed simple filter applies to facet filter
Browse files Browse the repository at this point in the history
Added a test when using a simple filter and a faceted filter at the same time
  • Loading branch information
a.usenko committed May 31, 2023
1 parent 97b5009 commit 4ee47ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ open class BaseFilterResult(
class PreparedSimpleFilter(
name: String,
paramName: String,
filterExpr: QueryExpression?,
) : PreparedFilter<BaseFilterResult>(name, paramName, filterExpr) {
private val filterExpression: QueryExpression?,
) : PreparedFilter<BaseFilterResult>(name, paramName, null) {
override fun apply(searchQuery: SearchQuery<*>, otherFacetFilterExpressions: List<QueryExpression>) {
if (facetFilterExpr != null) {
searchQuery.filter(facetFilterExpr)
if (filterExpression != null) {
searchQuery.filter(filterExpression)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class SimpleFilterTests : BaseCompilerTest<SearchQueryCompiler>(::SearchQueryCom


object BikeQueryFilters : QueryFilters() {
val manufacturer by FacetFilter(BikeDocument.manufacturer)
val price by SimpleFilter(BikeDocument.price, mode = FilterMode.INTERSECT)
val priceUnion by SimpleFilter(BikeDocument.price, mode = FilterMode.UNION)
}
Expand Down Expand Up @@ -51,6 +52,46 @@ class SimpleFilterTests : BaseCompilerTest<SearchQueryCompiler>(::SearchQueryCom
)
}

@Test
fun simpleFilterWithFacetFilter() = testWithCompiler {

val sq = SearchQuery()
BikeQueryFilters.apply(
sq,
mapOf(
listOf("price") to listOf("1.0", "3.0"),
listOf("manufacturer") to listOf("BMC", "Cube")
)
)

compile(sq).body shouldContainExactly mapOf(
"post_filter" to mapOf(
"terms" to mapOf(
"manufacturer" to listOf(
"BMC",
"Cube"
)
)
),
"query" to mapOf(
"bool" to mapOf(
"filter" to listOf(
mapOf(
"bool" to mapOf(
"filter" to listOf(
mapOf(
"term" to mapOf("price" to 1.0F)
), mapOf("term" to mapOf("price" to 3.0F))
)
)
)
)
)
),
"aggs" to mapOf("qf:manufacturer" to mapOf("terms" to mapOf("field" to "manufacturer")))
)
}

@Test
fun unionFilter() = testWithCompiler {

Expand Down

0 comments on commit 4ee47ce

Please sign in to comment.