CrescentSearchRequestWrapper { public Sort getSort() { String sortQueryString = searchRequest.getSort(); logger.debug("소트 파라미터 : {}", sortQueryString); if(sortQueryString == null || "".equals(sortQueryString) || "null".equals(sortQueryString)) return null; String[] parts = sortQueryString.split(","); if(parts.length == 0) return null; SortField[] lst = new SortField[parts.length]; for(int i = 0; i < parts.length; i++) { String part = parts[i].trim(); logger.debug("part : {}", part); boolean descending = true; int idx = part.indexOf( ' ' ); if(idx > 0) { String order = part.substring( idx+1 ).trim(); if("desc".equals(order)) { descending = true; } else if("asc".equals(order)) { descending = false; } else { throw new IllegalStateException("알 수 없는 조건입니다. : " + order); } part = part.substring( 0, idx ).trim(); } else { throw new IllegalStateException("Order 조건이 없습니다."); } if(logger.isDebugEnabled()) logger.debug("part order 제거 후: " + part); if("score".equals(part)) { if(descending) { if(parts.length == 1) { return null; } lst[i] = SortField.FIELD_SCORE; } else { lst[i] = new SortField(null,SortField.Type.SCORE, true); } } else { CrescentCollectionField f = collectionFieldsMap.get(part); lst[i] = new SortField(f.getName(),f.getSortFieldType(),descending); } } if(logger.isDebugEnabled()) { for(int i=0; i < lst.length; i++) { logger.debug(lst[i].getField()); } } return new Sort(lst); } CrescentSearchRequestWrapper(SearchRequest searchRequest); String getKeyword(); String getCollectionName(); int getDefaultHitsPage(); int getPageNum(); int getStartOffSet(); int getHitsForPage(); Sort getSort(); Query getQuery(); Filter getFilter(); List<CrescentCollectionField> getTargetSearchFields(); List<CrescentCollectionField> getIndexedFields(); String getUserIp(); String getUserId(); String getPcId();  }
@Test public void getSort() { searchRequest.setSort("title_sort desc, board_id_sort asc"); CrescentSearchRequestWrapper searchRequestWrapper = new CrescentSearchRequestWrapper(searchRequest); Sort sort = searchRequestWrapper.getSort(); Assert.assertEquals("<string: \"title_sort\">!,<long: \"board_id_sort\">", sort.toString()); searchRequest.setSort("score desc, title_sort desc"); sort = searchRequestWrapper.getSort(); Assert.assertEquals("<score>,<string: \"title_sort\">!", sort.toString()); }