Merge branch 'rel_5_7'

This commit is contained in:
Tadgh 2022-02-10 08:44:07 -08:00
commit 43f570259e
4 changed files with 71 additions and 11 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 3371
title: "Enhanced Lucene Indexing failed when indexing contained resources.
Contained resources are not indexed in Lucene/Elasticsearch, but this no longer causes an exception."

View File

@ -60,7 +60,7 @@ public class ExtendedLuceneSearchBuilder {
// each and clause may have a different modifier, so split down to the ORs
.flatMap(andList -> andList.getValue().stream())
.flatMap(Collection::stream)
.anyMatch(this::isParamSupported);
.anyMatch(this::isParamTypeSupported);
}
/**
@ -68,7 +68,7 @@ public class ExtendedLuceneSearchBuilder {
* <p>
* NOTE - keep this in sync with addAndConsumeAdvancedQueryClauses() below.
*/
private boolean isParamSupported(IQueryParameterType param) {
private boolean isParamTypeSupported(IQueryParameterType param) {
String modifier = StringUtils.defaultString(param.getQueryParameterQualifier(), EMPTY_MODIFIER);
if (param instanceof TokenParam) {
switch (modifier) {

View File

@ -19,6 +19,7 @@ import ca.uhn.fhir.jpa.dao.data.IResourceTableDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.partition.SystemRequestDetails;
import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc;
@ -135,7 +136,6 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
@BeforeEach
public void beforePurgeDatabase() {
purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc);
myDaoConfig.setAdvancedLuceneIndexing(true);
}
@Override
@ -149,14 +149,16 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
}
@BeforeEach
public void enableContains() {
myContainsSettings = myDaoConfig.isAllowContainsSearches();
public void enableContainsAndLucene() {
myDaoConfig.setAllowContainsSearches(true);
myDaoConfig.setAdvancedLuceneIndexing(true);
}
@AfterEach
public void restoreContains() {
myDaoConfig.setAllowContainsSearches(myContainsSettings);
DaoConfig defaultConfig = new DaoConfig();
myDaoConfig.setAllowContainsSearches(defaultConfig.isAllowContainsSearches());
myDaoConfig.setAdvancedLuceneIndexing(defaultConfig.isAdvancedLuceneIndexing());
}
@Test
@ -513,6 +515,48 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
assertThat(message, toUnqualifiedVersionlessIdValues(myObservationDao.search(map)), containsInAnyOrder(toValues(iIdTypes)));
}
@Nested
public class WithContainedIndexing {
@BeforeEach
public void enableContains() {
// we don't support chained or contained yet, but turn it on to test we don't blow up.
myDaoConfig.getModelConfig().setIndexOnContainedResources(true);
myDaoConfig.getModelConfig().setIndexOnContainedResourcesRecursively(true);
}
@AfterEach
public void restoreContains() {
ModelConfig defaultModelConfig = new ModelConfig();
myDaoConfig.getModelConfig().setIndexOnContainedResources(defaultModelConfig.isIndexOnContainedResources());
myDaoConfig.getModelConfig().setIndexOnContainedResourcesRecursively(defaultModelConfig.isIndexOnContainedResourcesRecursively());
}
/**
* We were throwing when indexing contained.
* https://github.com/hapifhir/hapi-fhir/issues/3371
*/
@Test
public void ignoreContainedResources_noError() {
// given
String json =
"{" +
"\"resourceType\": \"Observation\"," +
"\"contained\": [{" +
"\"resourceType\": \"Patient\"," +
"\"id\": \"contained-patient\"," +
"\"name\": [{ \"family\": \"Smith\"}]" +
"}]," +
"\"subject\": { \"reference\": \"#contained-patient\" }" +
"}";
Observation o = myFhirCtx.newJsonParser().parseResource(Observation.class, json);
myObservationDao.create(o, mySrd).getId().toUnqualifiedVersionless();
// no error.
}
}
@Test
public void testExpandWithIsAInExternalValueSet() {
createExternalCsAndLocalVs();
@ -529,7 +573,6 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest {
assertThat(codes, containsInAnyOrder("childAAA", "childAAB"));
}
@Test
public void testExpandWithFilter() {
createExternalCsAndLocalVs();

View File

@ -28,6 +28,8 @@ import org.hibernate.search.engine.backend.document.DocumentElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.BiConsumer;
import java.util.Date;
/**
@ -47,14 +49,24 @@ public class ExtendedLuceneIndexData {
this.myFhirContext = theFhirContext;
}
private <V> BiConsumer<String, V> ifNotContained(BiConsumer<String, V> theIndexWriter) {
return (s,v) -> {
// Ignore contained resources for now.
if (!s.contains(".")) {
theIndexWriter.accept(s,v);
}
};
}
public void writeIndexElements(DocumentElement theDocument) {
HibernateSearchIndexWriter indexWriter = HibernateSearchIndexWriter.forRoot(myFhirContext, theDocument);
ourLog.debug("Writing JPA index to Hibernate Search");
mySearchParamStrings.forEach(ifNotContained(indexWriter::writeStringIndex));
mySearchParamTokens.forEach(ifNotContained(indexWriter::writeTokenIndex));
mySearchParamLinks.forEach(ifNotContained(indexWriter::writeReferenceIndex));
// TODO MB Use RestSearchParameterTypeEnum to define templates.
mySearchParamStrings.forEach(indexWriter::writeStringIndex);
mySearchParamTokens.forEach(indexWriter::writeTokenIndex);
mySearchParamLinks.forEach(indexWriter::writeReferenceIndex);
mySearchParamDates.forEach(indexWriter::writeDateIndex);
mySearchParamDates.forEach(ifNotContained(indexWriter::writeDateIndex));
}
public void addStringIndexData(String theSpName, String theText) {