Correctly reindex string indexes

This commit is contained in:
James Agnew 2018-12-06 14:43:14 -05:00
parent a5b1f684f7
commit 5a80e70d93
8 changed files with 79 additions and 0 deletions

View File

@ -625,6 +625,69 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
@Test
public void testReindexingSingleStringHashValueIsDeleted() {
Patient p = new Patient();
p.addName().setFamily("family1");
final IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap searchParamMap = new SearchParameterMap();
searchParamMap.setLoadSynchronous(true);
searchParamMap.add(Patient.SP_FAMILY, new StringParam("family1"));
assertEquals(1, myPatientDao.search(searchParamMap).size().intValue());
runInTransaction(()->{
myEntityManager
.createQuery("UPDATE ResourceIndexedSearchParamString s SET s.myHashNormalizedPrefix = null")
.executeUpdate();
});
assertEquals(0, myPatientDao.search(searchParamMap).size().intValue());
myResourceReindexingSvc.markAllResourcesForReindexing();
myResourceReindexingSvc.forceReindexingPass();
assertEquals(1, myPatientDao.search(searchParamMap).size().intValue());
}
@Test
public void testReindexingSingleStringHashIdentityValueIsDeleted() {
Patient p = new Patient();
p.addName().setFamily("family1");
final IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless();
SearchParameterMap searchParamMap = new SearchParameterMap();
searchParamMap.setLoadSynchronous(true);
searchParamMap.add(Patient.SP_FAMILY, new StringParam("family1"));
assertEquals(1, myPatientDao.search(searchParamMap).size().intValue());
runInTransaction(()->{
Long i = myEntityManager
.createQuery("SELECT count(s) FROM ResourceIndexedSearchParamString s WHERE s.myHashIdentity IS null", Long.class)
.getSingleResult();
assertEquals(0L, i.longValue());
myEntityManager
.createQuery("UPDATE ResourceIndexedSearchParamString s SET s.myHashIdentity = null")
.executeUpdate();
i = myEntityManager
.createQuery("SELECT count(s) FROM ResourceIndexedSearchParamString s WHERE s.myHashIdentity IS null", Long.class)
.getSingleResult();
assertThat(i, greaterThan(1L));
});
myResourceReindexingSvc.markAllResourcesForReindexing();
myResourceReindexingSvc.forceReindexingPass();
runInTransaction(()->{
Long i = myEntityManager
.createQuery("SELECT count(s) FROM ResourceIndexedSearchParamString s WHERE s.myHashIdentity IS null", Long.class)
.getSingleResult();
assertEquals(0L, i.longValue());
});
}
@Test
public void testSystemMetaOperation() {

View File

@ -104,6 +104,7 @@ public class ResourceIndexedSearchParamCoords extends BaseResourceIndexedSearchP
}
public Long getHashIdentity() {
calculateHashes();
return myHashIdentity;
}

View File

@ -122,6 +122,7 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
}
public Long getHashIdentity() {
calculateHashes();
return myHashIdentity;
}

View File

@ -106,6 +106,7 @@ public class ResourceIndexedSearchParamNumber extends BaseResourceIndexedSearchP
}
public Long getHashIdentity() {
calculateHashes();
return myHashIdentity;
}

View File

@ -158,6 +158,7 @@ public class ResourceIndexedSearchParamQuantity extends BaseResourceIndexedSearc
}
private Long getHashIdentitySystemAndUnits() {
calculateHashes();
return myHashIdentitySystemAndUnits;
}

View File

@ -163,6 +163,7 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
@Override
@PrePersist
@PreUpdate
public void calculateHashes() {
if ((myHashIdentity == null || myHashNormalizedPrefix == null || myHashExact == null) && myModelConfig != null) {
String resourceType = getResourceType();
@ -197,11 +198,17 @@ public class ResourceIndexedSearchParamString extends BaseResourceIndexedSearchP
b.append(getParamName(), obj.getParamName());
b.append(getResource(), obj.getResource());
b.append(getValueExact(), obj.getValueExact());
b.append(getHashIdentity(), obj.getHashIdentity());
b.append(getHashExact(), obj.getHashExact());
b.append(getHashNormalizedPrefix(), obj.getHashNormalizedPrefix());
return b.isEquals();
}
private Long getHashIdentity() {
calculateHashes();
return myHashIdentity;
}
public Long getHashExact() {
calculateHashes();
return myHashExact;

View File

@ -121,6 +121,7 @@ public class ResourceIndexedSearchParamUri extends BaseResourceIndexedSearchPara
}
private Long getHashIdentity() {
calculateHashes();
return myHashIdentity;
}

View File

@ -128,6 +128,10 @@
because a Patient's name is changing from "A" to "B"). This has the net effect
of reducing the number
</action>
<action type="fix">
An issue was corrected with the JPA reindexer, where String index columns do not always
get reindexed if they did not have an identity hash value in the HASH_IDENTITY column.
</action>
</release>
<release version="3.6.0" date="2018-11-12" description="Food">
<action type="add">