mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +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;
|
package com.sismics.docs.core.model.context;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.eventbus.AsyncEventBus;
|
import com.google.common.eventbus.AsyncEventBus;
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.sismics.docs.core.constant.Constants;
|
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.service.InboxService;
|
||||||
import com.sismics.docs.core.util.PdfUtil;
|
import com.sismics.docs.core.util.PdfUtil;
|
||||||
import com.sismics.docs.core.util.indexing.IndexingHandler;
|
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 com.sismics.util.EnvironmentUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -76,8 +77,16 @@ public class AppContext {
|
|||||||
resetEventBus();
|
resetEventBus();
|
||||||
|
|
||||||
// Start indexing handler
|
// Start indexing handler
|
||||||
indexingHandler = new LuceneIndexingHandler();
|
|
||||||
try {
|
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();
|
indexingHandler.startUp();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Error starting the indexing handler, rebuilding the index: " + e.getMessage());
|
log.error("Error starting the indexing handler, rebuilding the index: " + e.getMessage());
|
||||||
|
@ -16,6 +16,13 @@ import java.util.List;
|
|||||||
* @author bgamard
|
* @author bgamard
|
||||||
*/
|
*/
|
||||||
public interface IndexingHandler {
|
public interface IndexingHandler {
|
||||||
|
/**
|
||||||
|
* Return true if this indexing handler can start.
|
||||||
|
*
|
||||||
|
* @return True if able to start
|
||||||
|
*/
|
||||||
|
boolean accept();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the indexing handler.
|
* 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.PaginatedLists;
|
||||||
import com.sismics.docs.core.util.jpa.QueryParam;
|
import com.sismics.docs.core.util.jpa.QueryParam;
|
||||||
import com.sismics.docs.core.util.jpa.SortCriteria;
|
import com.sismics.docs.core.util.jpa.SortCriteria;
|
||||||
|
import com.sismics.util.ClasspathScanner;
|
||||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
@ -44,6 +45,7 @@ import java.util.*;
|
|||||||
*
|
*
|
||||||
* @author bgamard
|
* @author bgamard
|
||||||
*/
|
*/
|
||||||
|
@ClasspathScanner.Priority(100)
|
||||||
public class LuceneIndexingHandler implements IndexingHandler {
|
public class LuceneIndexingHandler implements IndexingHandler {
|
||||||
/**
|
/**
|
||||||
* Logger.
|
* Logger.
|
||||||
@ -60,6 +62,12 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
|||||||
*/
|
*/
|
||||||
private DirectoryReader directoryReader;
|
private DirectoryReader directoryReader;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept() {
|
||||||
|
// Embedded Lucene can always start
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startUp() throws Exception {
|
public void startUp() throws Exception {
|
||||||
ConfigDao configDao = new ConfigDao();
|
ConfigDao configDao = new ConfigDao();
|
||||||
|
Loading…
Reference in New Issue
Block a user