Skip to content

Commit

Permalink
fix: change to bool query + should
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreiffers committed Dec 20, 2023
1 parent 807c5ca commit d8259c6
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.springframework.stereotype.Service
class ConceptSearchService(
private val elasticsearchOperations: ElasticsearchOperations
) {

fun searchCurrentConcepts(orgNumber: String, search: SearchOperation): SearchHits<CurrentConcept> =
elasticsearchOperations.search(
search.toElasticQuery(orgNumber),
Expand Down Expand Up @@ -44,18 +43,31 @@ class ConceptSearchService(
}
if (!query.isNullOrBlank()) builder.addFieldsQuery(fields, query)
builder.withPageable(Pageable.ofSize(pagination.getSize()).withPage(pagination.getPage()))

return builder.build()
}


private fun NativeQueryBuilder.addFieldsQuery(queryFields: QueryFields, queryValue: String) {
withQuery { queryBuilder ->
queryBuilder.multiMatch { matchBuilder ->
matchBuilder.fields(queryFields.boostedPaths())
.query(queryValue)
.type(TextQueryType.Phrase)
matchBuilder.fields(queryFields.paths())
.query(queryValue)
.type(TextQueryType.BoolPrefix)
queryBuilder.bool { boolBuilder ->
boolBuilder.should {
it.multiMatch { matchBuilder ->
matchBuilder.fields(queryFields.boostedPaths())
.query(queryValue)
.type(TextQueryType.Phrase)
}
}

boolBuilder.should {
it.multiMatch { matchBuilder ->
matchBuilder.fields(queryFields.paths())
.query(queryValue)
.type(TextQueryType.BoolPrefix)
}
}

boolBuilder.minimumShouldMatch("1")
}
}
}
Expand Down

0 comments on commit d8259c6

Please sign in to comment.