|
33 | 33 | public class CodeableConceptService {
|
34 | 34 | public static final String FIELD_NAME_DISPLAY_DE = "display.de";
|
35 | 35 | public static final String FIELD_NAME_DISPLAY_EN = "display.en";
|
36 |
| - public static final String FIELD_NAME_DISPLAY_ORIGINAL = "display.original"; |
| 36 | + public static final String FIELD_NAME_DISPLAY_ORIGINAL_WITH_BOOST = "display.original^0.5"; |
37 | 37 | public static final String FIELD_NAME_TERMCODE_WITH_BOOST = "termcode.code^2";
|
38 | 38 | private static final UUID NAMESPACE_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
39 | 39 | private ElasticsearchOperations operations;
|
@@ -101,55 +101,28 @@ private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
|
101 | 101 | });
|
102 | 102 | }
|
103 | 103 |
|
104 |
| - BoolQuery outerBoolQuery; |
| 104 | + BoolQuery boolQuery; |
105 | 105 |
|
106 | 106 | if (keyword.isEmpty()) {
|
107 |
| - outerBoolQuery = new BoolQuery.Builder() |
| 107 | + boolQuery = new BoolQuery.Builder() |
108 | 108 | .filter(filterTerms.isEmpty() ? List.of() : filterTerms)
|
109 | 109 | .build();
|
110 | 110 |
|
111 | 111 | } else {
|
112 |
| - var translationDeExistsQuery = new ExistsQuery.Builder() |
113 |
| - .field(FIELD_NAME_DISPLAY_DE) |
114 |
| - .build(); |
115 |
| - |
116 |
| - var translationEnExistsQuery = new ExistsQuery.Builder() |
117 |
| - .field(FIELD_NAME_DISPLAY_EN) |
118 |
| - .build(); |
119 |
| - |
120 |
| - var mmQueryWithTranslations = new MultiMatchQuery.Builder() |
121 |
| - .query(keyword) |
122 |
| - .fields(List.of(FIELD_NAME_DISPLAY_DE, FIELD_NAME_DISPLAY_EN, FIELD_NAME_TERMCODE_WITH_BOOST)) |
123 |
| - .build(); |
124 |
| - |
125 |
| - var boolQueryWithTranslations = new BoolQuery.Builder() |
126 |
| - .should(List.of(translationDeExistsQuery._toQuery(), translationEnExistsQuery._toQuery())) |
127 |
| - .must(List.of(mmQueryWithTranslations._toQuery())) |
128 |
| - .filter(filterTerms.isEmpty() ? List.of() : filterTerms) |
129 |
| - .build(); |
130 |
| - |
131 |
| - |
132 |
| - // The "lower" part that will only be considered when the translations are empty |
133 |
| - var mmQueryWithOriginal = new MultiMatchQuery.Builder() |
| 112 | + var multiMatchQuery = new MultiMatchQuery.Builder() |
134 | 113 | .query(keyword)
|
135 |
| - .fields(List.of(FIELD_NAME_DISPLAY_ORIGINAL, FIELD_NAME_TERMCODE_WITH_BOOST)) |
| 114 | + .fields(List.of(FIELD_NAME_DISPLAY_DE, FIELD_NAME_DISPLAY_EN, FIELD_NAME_TERMCODE_WITH_BOOST, FIELD_NAME_DISPLAY_ORIGINAL_WITH_BOOST)) |
136 | 115 | .build();
|
137 | 116 |
|
138 |
| - var boolQueryWithOriginal = new BoolQuery.Builder() |
139 |
| - .mustNot(List.of(translationDeExistsQuery._toQuery(), translationEnExistsQuery._toQuery())) |
140 |
| - .must(List.of(mmQueryWithOriginal._toQuery())) |
| 117 | + boolQuery = new BoolQuery.Builder() |
| 118 | + .must(List.of(multiMatchQuery._toQuery())) |
141 | 119 | .filter(filterTerms.isEmpty() ? List.of() : filterTerms)
|
142 |
| - .minimumShouldMatch("1") |
143 | 120 | .build();
|
144 | 121 |
|
145 |
| - // Combine both parts in the top level bool query |
146 |
| - outerBoolQuery = new BoolQuery.Builder() |
147 |
| - .should(List.of(boolQueryWithTranslations._toQuery(), boolQueryWithOriginal._toQuery())) |
148 |
| - .build(); |
149 | 122 | }
|
150 | 123 |
|
151 | 124 | var query = new NativeQueryBuilder()
|
152 |
| - .withQuery(outerBoolQuery._toQuery()) |
| 125 | + .withQuery(boolQuery._toQuery()) |
153 | 126 | .withPageable(pageRequest)
|
154 | 127 | .build();
|
155 | 128 |
|
|
0 commit comments