Skip to content

Commit

Permalink
join knn filter terms with AND (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-butcher authored Sep 15, 2023
1 parent 513246a commit d7a705c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ trait TemplateSearchBuilder extends Encoders {
// on whether the document contains the term in any searchable field.
// If there are fields that should be ignored, then this default will
// be inappropriate, and can be overridden.
protected val knnFilter: String = """{
| "multi_match": { "query": "{{query}}" }
protected val knnFilter: String =
"""{
| "multi_match": { "query": "{{query}}", "operator": "AND", "type": "cross_fields"}
| }""".stripMargin

// Importantly, this is *not* JSON, due to the `{{#` sequences, so must be created and sent as a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class ImagesFiltersTest extends AnyFunSpec with ApiImagesTestBase {
imagesIndex,
"images.examples.color-filter-tests.even-less-blue-foot",
"images.examples.color-filter-tests.blue-foot",
"images.examples.color-filter-tests.blue",
"images.examples.color-filter-tests.orange-foot",
"images.examples.color-filter-tests.slightly-less-blue-foot"
)
Expand All @@ -374,5 +375,28 @@ class ImagesFiltersTest extends AnyFunSpec with ApiImagesTestBase {
}
}
}
it("combines multi-token query terms with AND") {
withImagesApi {
case (imagesIndex, routes) =>
indexTestDocuments(
imagesIndex,
"images.examples.color-filter-tests.blue", // Green + Dye (subjects)
"images.examples.color-filter-tests.blue-foot", // Dye but not Green
"images.examples.color-filter-tests.even-less-blue-foot" // Neither Dye nor Green
)

assertJsonResponse(
routes,
path = f"$rootPath/images?query=green+dye&color=22bbff"
) {
Status.OK -> imagesListResponse(
ids = Seq(
"images.examples.color-filter-tests.blue"
),
strictOrdering = true
)
}
}
}
}
}

0 comments on commit d7a705c

Please sign in to comment.