Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
#162: added property that allows to enable/disable a full index rebui…
Browse files Browse the repository at this point in the history
…ld on startup.
  • Loading branch information
westei committed Dec 7, 2017
1 parent beb2dd3 commit 5c6921e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions application/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ endpoints.metrics.enabled=false
#deactivate the interesting terms from previous conversations
smarti.analysis.optional=*,!keyword.interestingterms.conversation

#enable/disable full rebuild of indexes on startup (default: true)
#smarti.indexing.rebuildOnStartup=true

#rocketchat.proxy.hostname=127.0.0.1
#rocketchat.proxy.port=8181
#rocketchat.proxy.scheme=http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public class ConversationIndexer implements ConversytionSyncCallback {

private final ExecutorService indexerPool;

@Value("${smarti.indexing.rebuildOnStartup:true}")
private boolean rebuildOnStartup = true;

@Autowired
public ConversationIndexer(SolrCoreContainer solrServer, StoreService storeService){
this.solrServer = solrServer;
Expand All @@ -161,21 +164,23 @@ protected void startup() {
if(indexTask != null){
log.info("initialize ConversationIndex after startup ...");
Date syncDate = null;
try (SolrClient solr = solrServer.getSolrClient(conversationCore)){
//read (1) FIELD_SYNC_DATE from index
SolrQuery query = new SolrQuery("*:*");
query.addSort(FIELD_SYNC_DATE, ORDER.desc);
query.setFields(FIELD_SYNC_DATE);
query.setRows(1);
query.setStart(0);
QueryResponse result = solr.query(query);
if(result.getResults() != null && result.getResults().getNumFound() > 0){
syncDate = (Date)result.getResults().get(0).getFieldValue(FIELD_SYNC_DATE);
log.debug("set lastSync date to {}", syncDate);
if(!rebuildOnStartup){
try (SolrClient solr = solrServer.getSolrClient(conversationCore)){
//read (1) FIELD_SYNC_DATE from index
SolrQuery query = new SolrQuery("*:*");
query.addSort(FIELD_SYNC_DATE, ORDER.desc);
query.setFields(FIELD_SYNC_DATE);
query.setRows(1);
query.setStart(0);
QueryResponse result = solr.query(query);
if(result.getResults() != null && result.getResults().getNumFound() > 0){
syncDate = (Date)result.getResults().get(0).getFieldValue(FIELD_SYNC_DATE);
log.debug("set lastSync date to {}", syncDate);
}
} catch (IOException | SolrServerException e) {
log.warn("Updating Conversation index on startup failed ({} - {})", e.getClass().getSimpleName(), e.getMessage());
log.debug("STACKTRACE:",e);
}
} catch (IOException | SolrServerException e) {
log.warn("Updating Conversation index on startup failed ({} - {})", e.getClass().getSimpleName(), e.getMessage());
log.debug("STACKTRACE:",e);
}
indexTask.setLastSync(syncDate);
indexerPool.execute(indexTask);
Expand Down

0 comments on commit 5c6921e

Please sign in to comment.