Skip to content

Commit

Permalink
Merge branch 'develop' into caseyi-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzy11 authored Aug 13, 2024
2 parents d29c56a + f9bd77e commit 5a94082
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.openelisglobal.hibernate.search.massindexer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest")
public class MassIndexerRestController {

@Autowired
MassIndexerService massIndexerService;

@GetMapping("/reindex")
public ResponseEntity<String> reindex() {
try {
massIndexerService.reindex();
return ResponseEntity.ok("Reindexing completed successfully.");
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body("Error occurred during reindexing: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.openelisglobal.hibernate.search.massindexer;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import org.hibernate.search.mapper.orm.Search;
import org.hibernate.search.mapper.orm.massindexing.MassIndexer;
import org.hibernate.search.mapper.orm.session.SearchSession;
import org.springframework.stereotype.Service;

@Service
public class MassIndexerService {
@PersistenceContext
EntityManager entityManager;

// parameters to allow tuning the MassIndexer for optimal performance

private int idFetchSize = 100;

private int batchSizeToLoadObjects = 10;

private int threadsToLoadObjects = 6;

@Transactional
public void reindex() throws Exception {
SearchSession searchSession = Search.session(entityManager);
MassIndexer indexer = searchSession.massIndexer();
indexer.idFetchSize(idFetchSize).batchSizeToLoadObjects(batchSizeToLoadObjects)
.threadsToLoadObjects(threadsToLoadObjects).startAndWait();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ private List<TestReflex> getReflexTests(TestReflexBean reflexBean) {
if (reflexBean.getResult().getTestResult() == null) {
return new ArrayList<>();
}
List<TestReflex> reflexesForResult = reflexResolver.getTestReflexesForResult(reflexBean.getResult());
String resultType = testService.getResultType(reflexBean.getResult().getTestResult().getTest());
List<TestReflex> reflexesForResult;
if (resultType.equals("D")) {
reflexesForResult = reflexResolver.getTestReflexsByAnalyteAndTest(reflexBean.getResult());
} else {
reflexesForResult = reflexResolver.getTestReflexesForResult(reflexBean.getResult());
}
reflexesForResult = reflexesForResult.stream()
.filter(e -> isTestTriggeredByResult(e.getAddedTest(), reflexBean.getResult()))
.collect(Collectors.toList());
Expand Down Expand Up @@ -876,6 +882,7 @@ public boolean doesDictionaryRelationRulesForReflexApply(Test potentialReflexTes
}
}
}

return false;

});
Expand Down

0 comments on commit 5a94082

Please sign in to comment.