String selectedCollectionName = request.getParameter("collectionName");
logger.debug("selectedCollectionName : " + selectedCollectionName);
CrescentCollection newCollection = new CrescentCollection();
newCollection.setName(selectedCollectionName);
newCollection.setIndexingDirectory(request.getParameter("indexingDirectory"));
newCollection.setSearcherReloadScheduleMin(StringUtils.defaultIfEmpty(request.getParameter("searcherReloadScheduleMin"), "10"));
String indexingModeAnalyzer = request.getParameter("indexingModeAnalyzer");
String searchModeAnalyzer = request.getParameter("searchModeAnalyzer");
String indexingModeAnalyzerType = request.getParameter("indexingModeAnalyzerType");
String searchModelAnalyzerType = request.getParameter("searchModeAnalyzerType");
String indexingModeAnalyzerConstArgs = request.getParameter("indexingModeAnalyzerConstArgs");
String searchModeAnalyzerConstArgs = request.getParameter("searchModeAnalyzerConstArgs");
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(searchModelAnalyzerType);
analyzerHolderList.add(searchModeAnalyzerHolder);
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("searchModelAnalyzerType : {} ", request.getParameter("searchModelAnalyzerType"));
logger.debug("indexingModeAnalyzerConstArgs : {} ", request.getParameter("indexingModeAnalyzerConstArgs"));
logger.debug("searchModeAnalyzerConstArgs : {} ", request.getParameter("searchModeAnalyzerConstArgs"));
}
//필드들을 걸러낸다.
@SuppressWarnings("unchecked")
Enumeration<String> enumeration = (Enumeration<String>)request.getParameterNames();
List<String> fieldNameList = new ArrayList<String>();
while(enumeration.hasMoreElements()) {
String paramName = enumeration.nextElement();
if(paramName.endsWith("-fieldName")) { //필수값
String fieldName = paramName.split("-")[0];
fieldNameList.add(fieldName);
}
}
List<CrescentCollectionField> newCollectionFieldList = new ArrayList<CrescentCollectionField>();
List<CrescentSortField> sortFieldList = new ArrayList<CrescentSortField>();
List<CrescentDefaultSearchField> defaultSearchFieldList = new ArrayList<CrescentDefaultSearchField>();
for(String fieldName : fieldNameList) {
CrescentCollectionField newCollectionField = new CrescentCollectionField();
newCollectionField.setName(fieldName);
newCollectionField.setAnalyze("on".equals(request.getParameter(fieldName+"-analyze")) ? true : false);
newCollectionField.setIndex("on".equals(request.getParameter(fieldName+"-index")) ? true : false);
newCollectionField.setMust("on".equals(request.getParameter(fieldName+"-must")) ? true : false);
newCollectionField.setStore("on".equals(request.getParameter(fieldName+"-store")) ? true : false);
newCollectionField.setTermoffset("on".equals(request.getParameter(fieldName+"-termoffset")) ? true : false);
newCollectionField.setTermposition("on".equals(request.getParameter(fieldName+"-termposition")) ? true : false);
newCollectionField.setTermvector("on".equals(request.getParameter(fieldName+"-termvector")) ? true : false);
//System.out.println("DDDDDDDDDDDDDD : " + request.getParameter(fieldName+"-boost"));
newCollectionField.setBoost(Float.parseFloat(StringUtils.defaultIfEmpty(request.getParameter(fieldName+"-boost"), "0")));
newCollectionField.setType(StringUtils.defaultString(request.getParameter(fieldName+"-type"), "STRING"));
newCollectionFieldList.add(newCollectionField);
//sort field 처리
if("on".equals(request.getParameter(fieldName+"-sortField"))) {
CrescentSortField sortField = new CrescentSortField();
sortField.setSource(fieldName);
sortField.setDest(fieldName+"_sort");
sortFieldList.add(sortField);
}
//default search field 처리
if("on".equals(request.getParameter(fieldName+"-defaultSearchField"))) {
CrescentDefaultSearchField defaultSearchField = new CrescentDefaultSearchField();
defaultSearchField.setName(fieldName);
defaultSearchFieldList.add(defaultSearchField);
}
if(logger.isDebugEnabled()) {
logger.debug("crescentField Name {} = {}", fieldName, "sortField : " + request.getParameter(fieldName+"-sortField"));
logger.debug("crescentField Name {} = {}", fieldName, "defaultSearchField : "+ request.getParameter(fieldName+"-defaultSearchField"));
}
if(logger.isDebugEnabled()) {
logger.debug("crescentField Name {} = {}", fieldName, "analyze : " + request.getParameter(fieldName+"-analyze"));
logger.debug("crescentField Name {} = {}", fieldName, "index : " + request.getParameter(fieldName+"-index"));
logger.debug("crescentField Name {} = {}", fieldName, "must : " + request.getParameter(fieldName+"-must"));
logger.debug("crescentField Name {} = {}", fieldName, "store : " + request.getParameter(fieldName+"-store"));
logger.debug("crescentField Name {} = {}", fieldName, "termoffset : " + request.getParameter(fieldName+"-termoffset"));
logger.debug("crescentField Name {} = {}", fieldName, "termposition : " + request.getParameter(fieldName+"-termposition"));
logger.debug("crescentField Name {} = {}", fieldName, "termvector : " + request.getParameter(fieldName+"-termvector"));
logger.debug("crescentField Name {} = {}", fieldName, "boost : " + request.getParameter(fieldName+"-boost"));
logger.debug("crescentField Name {} = {}", fieldName, "type : " + request.getParameter(fieldName+"-type"));
}
}
newCollection.setSortFields(sortFieldList);
newCollection.setDefaultSearchFields(defaultSearchFieldList);
newCollection.setFields(newCollectionFieldList);
newCollection.setAnalyzers(analyzerHolderList);
collectionHandler.getCrescentCollections().getCrescentCollections().add(newCollection);
collectionHandler.writeToXML();
collectionHandler.reloadCollectionsXML();