mirror of
https://github.com/sismics/docs.git
synced 2024-11-15 18:57:56 +01:00
Closes #224: scan for indexing handler
This commit is contained in:
parent
c0678e9a90
commit
6798e01f49
@ -1,5 +1,6 @@
|
||||
package com.sismics.docs.core.model.context;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.eventbus.AsyncEventBus;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.sismics.docs.core.constant.Constants;
|
||||
@ -11,7 +12,7 @@ import com.sismics.docs.core.service.FileService;
|
||||
import com.sismics.docs.core.service.InboxService;
|
||||
import com.sismics.docs.core.util.PdfUtil;
|
||||
import com.sismics.docs.core.util.indexing.IndexingHandler;
|
||||
import com.sismics.docs.core.util.indexing.LuceneIndexingHandler;
|
||||
import com.sismics.util.ClasspathScanner;
|
||||
import com.sismics.util.EnvironmentUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -76,8 +77,16 @@ public class AppContext {
|
||||
resetEventBus();
|
||||
|
||||
// Start indexing handler
|
||||
indexingHandler = new LuceneIndexingHandler();
|
||||
try {
|
||||
List<Class<? extends IndexingHandler>> indexingHandlerList = Lists.newArrayList(
|
||||
new ClasspathScanner<IndexingHandler>().findClasses(IndexingHandler.class, "com.sismics.docs.core.util.indexing"));
|
||||
for (Class<? extends IndexingHandler> handlerClass : indexingHandlerList) {
|
||||
IndexingHandler handler = handlerClass.newInstance();
|
||||
if (handler.accept()) {
|
||||
indexingHandler = handler;
|
||||
break;
|
||||
}
|
||||
}
|
||||
indexingHandler.startUp();
|
||||
} catch (Exception e) {
|
||||
log.error("Error starting the indexing handler, rebuilding the index: " + e.getMessage());
|
||||
|
@ -16,6 +16,13 @@ import java.util.List;
|
||||
* @author bgamard
|
||||
*/
|
||||
public interface IndexingHandler {
|
||||
/**
|
||||
* Return true if this indexing handler can start.
|
||||
*
|
||||
* @return True if able to start
|
||||
*/
|
||||
boolean accept();
|
||||
|
||||
/**
|
||||
* Start the indexing handler.
|
||||
*
|
||||
|
@ -16,6 +16,7 @@ import com.sismics.docs.core.util.jpa.PaginatedList;
|
||||
import com.sismics.docs.core.util.jpa.PaginatedLists;
|
||||
import com.sismics.docs.core.util.jpa.QueryParam;
|
||||
import com.sismics.docs.core.util.jpa.SortCriteria;
|
||||
import com.sismics.util.ClasspathScanner;
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
@ -44,6 +45,7 @@ import java.util.*;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
@ClasspathScanner.Priority(100)
|
||||
public class LuceneIndexingHandler implements IndexingHandler {
|
||||
/**
|
||||
* Logger.
|
||||
@ -60,6 +62,12 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
*/
|
||||
private DirectoryReader directoryReader;
|
||||
|
||||
@Override
|
||||
public boolean accept() {
|
||||
// Embedded Lucene can always start
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startUp() throws Exception {
|
||||
ConfigDao configDao = new ConfigDao();
|
||||
|
Loading…
Reference in New Issue
Block a user