Skip to content

Commit

Permalink
feat(fhir): apply boosted name filters when filtering resources by title
Browse files Browse the repository at this point in the history
  • Loading branch information
cmark committed Jun 17, 2023
1 parent fb6f2c0 commit 5880ea5
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2021-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -100,7 +100,18 @@ protected final Bundle doExecute(RepositoryContext context) throws IOException {
addFilter(resourcesQuery, OptionKey.VERSION, String.class, VersionDocument.Expressions::versions);

if (containsKey(OptionKey.TITLE)) {
resourcesQuery.must(TermFilter.match().term(getString(OptionKey.TITLE)).build().toExpression(ResourceDocument.Fields.TITLE));
final String titleFilterValue = getString(OptionKey.TITLE);
if (containsKey(OptionKey.NAME)) {
// if there is a name filter as well, just add the title filter as is
resourcesQuery.must(TermFilter.match().term(titleFilterValue).build().toExpression(ResourceDocument.Fields.TITLE));
} else {
// if there is no name filter
resourcesQuery.must(Expressions.bool()
.should(TermFilter.match().term(titleFilterValue).build().toExpression(ResourceDocument.Fields.TITLE))
// apply the title filter value in both as is an full UPPERCASE form as an exact name filter with a boost of 1000 score
.should(Expressions.boost(Expressions.matchAny(ResourceDocument.Fields.ID, List.of(titleFilterValue, titleFilterValue.toUpperCase())), 100f))
.build());
}
}

Hits<ResourceFragment> internalResources = context.service(RevisionSearcher.class)
Expand Down

0 comments on commit 5880ea5

Please sign in to comment.