Skip to content

Commit

Permalink
Merge pull request #447 from medizininformatik-initiative/feature/446…
Browse files Browse the repository at this point in the history
…-search-in-original-entry-of-display-if-no-translations-are-available

#446 - Search in original entry of display if no translations are available
  • Loading branch information
michael-82 authored Feb 12, 2025
2 parents 68ef498 + 7ec2e73 commit 7ec6ecc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
needs: tests
runs-on: ubuntu-latest
env:
ONTOLOGY_GIT_TAG: v3.0.2-alpha.2
ONTOLOGY_GIT_TAG: v3.0.2-alpha.5
ELASTIC_HOST: http://localhost:9200
ELASTIC_FILEPATH: https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/TAGPLACEHOLDER/
ELASTIC_FILENAME: elastic.zip
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<java.version>17</java.version>
<mockwebserver.version>4.12.0</mockwebserver.version>
<okhttp3.version>4.10.0</okhttp3.version>
<ontology-tag>v3.0.2-alpha.2</ontology-tag>
<ontology-tag>v3.0.2-alpha.5</ontology-tag>
</properties>

<dependencies>
Expand Down Expand Up @@ -423,7 +423,7 @@
<goal>download-single</goal>
</goals>
<configuration>
<url>https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/${ontology-tag}/</url>
<url>https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/${ontology-tag}</url>
<fromFile>backend.zip</fromFile>
<toDir>${ontoDirectory.download}</toDir>
</configuration>
Expand All @@ -435,7 +435,7 @@
<goal>download-single</goal>
</goals>
<configuration>
<url>https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/${ontology-tag}/</url>
<url>https://github.com/medizininformatik-initiative/fhir-ontology-generator/releases/download/${ontology-tag}</url>
<fromFile>mapping.zip</fromFile>
<toDir>${ontoDirectory.download}</toDir>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,51 @@ private SearchHits<CodeableConceptDocument> findByCodeOrDisplay(String keyword,
});
}

BoolQuery boolQuery;
BoolQuery outerBoolQuery;

if (keyword.isEmpty()) {
boolQuery = new BoolQuery.Builder()
outerBoolQuery = new BoolQuery.Builder()
.filter(filterTerms.isEmpty() ? List.of() : filterTerms)
.build();

} else {
var mmQuery = new MultiMatchQuery.Builder()
// First the "upper" part of the query, when translations are present
var mustMultiMatchQueryWithTranslations = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("display.de", "display.en", "termcode.code^2"))
.build();

boolQuery = new BoolQuery.Builder()
.must(List.of(mmQuery._toQuery()))
var innerBoolQueryMatchTranslations = new BoolQuery.Builder()
.must(List.of(mustMultiMatchQueryWithTranslations._toQuery()))
.filter(filterTerms.isEmpty() ? List.of() : filterTerms)
.build();


// The "lower" part that will only be considered when the translations are empty
var mustMultiMatchQueryWithOriginal = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("display.original", "termcode.code^2"))
.build();

var innerBoolQueryMatchOriginal = new BoolQuery.Builder()
.must(List.of(mustMultiMatchQueryWithOriginal._toQuery()))
.filter(filterTerms.isEmpty() ? List.of() : filterTerms)
.build();

// Combine both parts in the top level bool query
outerBoolQuery = new BoolQuery.Builder()
.should(List.of(innerBoolQueryMatchTranslations._toQuery(), innerBoolQueryMatchOriginal._toQuery()))
.minimumShouldMatch("1")
.build();
}

var query = new NativeQueryBuilder()
.withQuery(boolQuery._toQuery())
.withQuery(outerBoolQuery._toQuery())
.withPageable(pageRequest)
.build();

log.info(query.getQuery().toString());

return operations.search(query, CodeableConceptDocument.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,19 @@ private SearchHits<OntologyListItemDocument> findByNameOrTermcode(String keyword
.filter(filterTerms.isEmpty() ? List.of() : filterTerms)
.build();
} else {
var mmQuery = new MultiMatchQuery.Builder()
var mmQueryWithTranslations = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("display.de", "display.en", "termcode^2"))
.build();

var mmQueryWithOriginal = new MultiMatchQuery.Builder()
.query(keyword)
.fields(List.of("display.original", "termcode^2"))
.build();

boolQuery = new BoolQuery.Builder()
.must(List.of(mmQuery._toQuery()))
.should(List.of(mmQueryWithTranslations._toQuery(), mmQueryWithOriginal._toQuery()))
.minimumShouldMatch("1")
.filter(filterTerms.isEmpty() ? List.of() : filterTerms)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"properties": {
"original": {
"type": "text",
"index": false
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"de": {
"type": "text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"properties": {
"original": {
"type": "text",
"index": false
"analyzer": "edge_ngram_analyzer_include_punctuation",
"search_analyzer": "lowercase_analyzer"
},
"de": {
"type": "text",
Expand Down

0 comments on commit 7ec6ecc

Please sign in to comment.