mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-09 14:33:32 +00:00
Ensure HS before attempting fulltext reindex. (#3995)
* Do not attempt fulltext reindex if disabled. Validate enabled before using any operation * attribute
This commit is contained in:
parent
c647154777
commit
cc183c7079
@ -0,0 +1,4 @@
|
||||
---
|
||||
type: fix
|
||||
issue: 3987
|
||||
title: "Previously, if a FullTextSearchSvcImpl was defined, but was disabled via configuration, there could be data loss when reindexing due to transaction rollbacks. This has been corrected. Thanks to @dyoung-work for the fix!"
|
@ -129,6 +129,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
|
||||
@Override
|
||||
public boolean supportsSomeOf(SearchParameterMap myParams) {
|
||||
|
||||
// keep this in sync with the guts of doSearch
|
||||
boolean requiresHibernateSearchAccess = myParams.containsKey(Constants.PARAM_CONTENT) || myParams.containsKey(Constants.PARAM_TEXT) || myParams.isLastN();
|
||||
|
||||
@ -139,12 +140,16 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
|
||||
@Override
|
||||
public void reindex(ResourceTable theEntity) {
|
||||
validateHibernateSearchIsEnabled();
|
||||
|
||||
SearchIndexingPlan plan = getSearchSession().indexingPlan();
|
||||
plan.addOrUpdate(theEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISearchQueryExecutor searchNotScrolled(String theResourceName, SearchParameterMap theParams, Integer theMaxResultsToFetch) {
|
||||
validateHibernateSearchIsEnabled();
|
||||
|
||||
return doSearch(theResourceName, theParams, null, theMaxResultsToFetch);
|
||||
}
|
||||
|
||||
@ -264,6 +269,8 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
|
||||
@Override
|
||||
public List<ResourcePersistentId> everything(String theResourceName, SearchParameterMap theParams, ResourcePersistentId theReferencingPid) {
|
||||
validateHibernateSearchIsEnabled();
|
||||
|
||||
// wipmb what about max results here?
|
||||
List<ResourcePersistentId> retVal = toList(doSearch(null, theParams, theReferencingPid, 10_000), 10_000);
|
||||
if (theReferencingPid != null) {
|
||||
@ -272,6 +279,12 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private void validateHibernateSearchIsEnabled() {
|
||||
if (isDisabled()) {
|
||||
throw new UnsupportedOperationException(Msg.code(2137) + "Hibernate search is not enabled!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled() {
|
||||
Boolean retVal = ourDisabled;
|
||||
@ -298,6 +311,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
@Transactional()
|
||||
@Override
|
||||
public List<ResourcePersistentId> search(String theResourceName, SearchParameterMap theParams) {
|
||||
validateHibernateSearchIsEnabled();
|
||||
return toList(doSearch(theResourceName, theParams, null, DEFAULT_MAX_NON_PAGED_SIZE), DEFAULT_MAX_NON_PAGED_SIZE);
|
||||
}
|
||||
|
||||
@ -314,6 +328,7 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
@Transactional()
|
||||
@Override
|
||||
public IBaseResource tokenAutocompleteValueSetSearch(ValueSetAutocompleteOptions theOptions) {
|
||||
validateHibernateSearchIsEnabled();
|
||||
ensureElastic();
|
||||
|
||||
ValueSetAutocompleteSearch autocomplete = new ValueSetAutocompleteSearch(myFhirContext, myModelConfig, getSearchSession());
|
||||
@ -329,7 +344,6 @@ public class FulltextSearchSvcImpl implements IFulltextSearchSvc {
|
||||
* Lastn and the autocomplete search use nested aggregations which are Elasticsearch-only
|
||||
*/
|
||||
private void ensureElastic() {
|
||||
//String hibernateSearchBackend = (String) myEntityManager.g.getJpaPropertyMap().get(BackendSettings.backendKey(BackendSettings.TYPE));
|
||||
try {
|
||||
getSearchSession().scope( ResourceTable.class )
|
||||
.aggregation()
|
||||
|
@ -105,7 +105,7 @@ public class ResourceReindexer {
|
||||
Class<T> resourceClass = (Class<T>) resourceDefinition.getImplementingClass();
|
||||
final IFhirResourceDao<T> dao = myDaoRegistry.getResourceDao(resourceClass);
|
||||
dao.reindex(theResource, theResourceTable);
|
||||
if (myFulltextSearchSvc != null) {
|
||||
if (myFulltextSearchSvc != null && !myFulltextSearchSvc.isDisabled()) {
|
||||
// update the full-text index, if active.
|
||||
myFulltextSearchSvc.reindex(theResourceTable);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user