private CrescentCollectionHandler collectionHandler;
@Override
public CrescentCollection updateCollectionInfo(HttpServletRequest request) {
CrescentCollections crescentCollections = collectionHandler.getCrescentCollections();
String selectedCollectionName = request.getParameter("collectionName");
logger.debug("selectedCollectionName : " + selectedCollectionName);
String indexingModeAnalyzer = request.getParameter("indexingModeAnalyzer");
String searchModeAnalyzer = request.getParameter("searchModeAnalyzer");
String indexingModeAnalyzerType = request.getParameter("indexingModeAnalyzerType");
String searchModeAnalyzerType = request.getParameter("searchModeAnalyzerType");
String indexingModeAnalyzerConstArgs = request.getParameter("indexingModeAnalyzerConstArgs");
String searchModeAnalyzerConstArgs = request.getParameter("searchModeAnalyzerConstArgs");
CrescentCollection selectedCollection = crescentCollections.getCrescentCollection(selectedCollectionName);
List<CrescentAnalyzerHolder> analyzerHolderList = new ArrayList<CrescentAnalyzerHolder>();
CrescentAnalyzerHolder indexingModeAnalyzerHolder = new CrescentAnalyzerHolder();
indexingModeAnalyzerHolder.setClassName(indexingModeAnalyzer);
indexingModeAnalyzerHolder.setConstructorArgs(indexingModeAnalyzerConstArgs);
indexingModeAnalyzerHolder.setType(indexingModeAnalyzerType);
analyzerHolderList.add(indexingModeAnalyzerHolder);
CrescentAnalyzerHolder searchModeAnalyzerHolder = new CrescentAnalyzerHolder();
searchModeAnalyzerHolder.setClassName(searchModeAnalyzer);
searchModeAnalyzerHolder.setConstructorArgs(searchModeAnalyzerConstArgs);
searchModeAnalyzerHolder.setType(searchModeAnalyzerType);
analyzerHolderList.add(searchModeAnalyzerHolder);
selectedCollection.setAnalyzers(analyzerHolderList);
selectedCollection.setSearcherReloadScheduleMin(StringUtils.defaultIfEmpty(request.getParameter("searcherReloadScheduleMin"), "10"));
if(logger.isDebugEnabled()) {
logger.debug("analyzer : {} ", request.getParameter("analyzer"));
logger.debug("collection Name : {} ", request.getParameter("collectionName"));
logger.debug("indexing Directory : {} ", request.getParameter("indexingDirectory"));
logger.debug("searcher reload schedule min : {} ", request.getParameter("searcherReloadScheduleMin"));
logger.debug("indexingModeAnalyzer : {} ", request.getParameter("indexingModeAnalyzer"));
logger.debug("searchModeAnalyzer : {} ", request.getParameter("searchModeAnalyzer"));
logger.debug("indexingModeAnalyzerType : {} ", request.getParameter("indexingModeAnalyzerType"));
logger.debug("searchModeAnalyzerType : {} ", request.getParameter("searchModeAnalyzerType"));
logger.debug("indexingModeAnalyzerConstArgs : {} ", request.getParameter("indexingModeAnalyzerConstArgs"));
logger.debug("searchModeAnalyzerConstArgs : {} ", request.getParameter("searchModeAnalyzerConstArgs"));
}
List<CrescentCollectionField> crescentCollectionFieldList = selectedCollection.getFields();
//추가되는 필드명을 모은다.
@SuppressWarnings("unchecked")
Enumeration<String> enumeration = request.getParameterNames();
List<String> addFieldNameList = new ArrayList<String>();
while(enumeration.hasMoreElements()) {
String paramValue = enumeration.nextElement();
if(paramValue.endsWith("fieldName")) {
addFieldNameList.add(paramValue.substring(0, paramValue.lastIndexOf("-")));
}
}
logger.debug("add field name list : {}", addFieldNameList);
for(String fieldName :addFieldNameList) {
CrescentCollectionField crescentField = new CrescentCollectionField();
crescentField.setName(fieldName);
if(!crescentCollectionFieldList.contains(crescentField)) {
crescentCollectionFieldList.add(crescentField);
}
}
for(CrescentCollectionField crescentField : crescentCollectionFieldList) {
crescentField.setAnalyze("on".equals(request.getParameter(crescentField.getName()+"-analyze")) ? true : false);
crescentField.setIndex("on".equals(request.getParameter(crescentField.getName()+"-index")) ? true : false);
crescentField.setMust("on".equals(request.getParameter(crescentField.getName()+"-must")) ? true : false);
crescentField.setStore("on".equals(request.getParameter(crescentField.getName()+"-store")) ? true : false);
crescentField.setTermoffset("on".equals(request.getParameter(crescentField.getName()+"-termoffset")) ? true : false);
crescentField.setTermposition("on".equals(request.getParameter(crescentField.getName()+"-termposition")) ? true : false);
crescentField.setTermvector("on".equals(request.getParameter(crescentField.getName()+"-termvector")) ? true : false);
crescentField.setRemoveHtmlTag("on".equals(request.getParameter(crescentField.getName()+"-removeHtmlTag")) ? true : false);
crescentField.setBoost(Float.parseFloat(StringUtils.defaultString(request.getParameter(crescentField.getName()+"-boost"), "0")));
crescentField.setType(StringUtils.defaultString(request.getParameter(crescentField.getName()+"-type"), "STRING"));
//sort field 처리
if("on".equals(request.getParameter(crescentField.getName()+"-sortField"))) {
CrescentSortField sortField = new CrescentSortField();
sortField.setSource(crescentField.getName());
sortField.setDest(crescentField.getName()+"_sort");
if(selectedCollection.getSortFields().contains(sortField)) {
//Nothing
} else {
selectedCollection.getSortFields().add(sortField);
}
}
//default search field 처리
if("on".equals(request.getParameter(crescentField.getName()+"-defaultSearchField"))) {
CrescentDefaultSearchField defaultSearchField = new CrescentDefaultSearchField();
defaultSearchField.setName(crescentField.getName());
if(selectedCollection.getDefaultSearchFields().contains(defaultSearchField)) {
//Nothing
} else {
selectedCollection.getDefaultSearchFields().add(defaultSearchField);
}
}
if(logger.isDebugEnabled()) {
logger.debug("crescentField Name {} = {}", crescentField.getName(), "sortField : " + request.getParameter(crescentField.getName()+"-sortField"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "defaultSearchField : "+ request.getParameter(crescentField.getName()+"-defaultSearchField"));
}
if(logger.isDebugEnabled()) {
logger.debug("crescentField Name {} = {}", crescentField.getName(), "analyze : " + request.getParameter(crescentField.getName()+"-analyze"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "index : " + request.getParameter(crescentField.getName()+"-index"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "must : " + request.getParameter(crescentField.getName()+"-must"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "store : " + request.getParameter(crescentField.getName()+"-store"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "termoffset : " + request.getParameter(crescentField.getName()+"-termoffset"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "termposition : " + request.getParameter(crescentField.getName()+"-termposition"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "termvector : " + request.getParameter(crescentField.getName()+"-termvector"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "boost : " + request.getParameter(crescentField.getName()+"-boost"));
logger.debug("crescentField Name {} = {}", crescentField.getName(), "type : " + request.getParameter(crescentField.getName()+"-type"));
}
}
collectionHandler.writeToXML();
collectionHandler.reloadCollectionsXML();
crescentCollections = collectionHandler.getCrescentCollections();
selectedCollection = crescentCollections.getCrescentCollection(selectedCollectionName);
return selectedCollection;
}