Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

join knn filter terms with AND #716

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
}
}
}
}
}