class 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(); //part = field desc

			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(); //part = field

			} 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);
			}
		}//end for

		if(logger.isDebugEnabled()) {
			for(int i=0; i < lst.length; i++) {
				logger.debug(lst[i].getField());
			}
		}
		
		return new Sort(lst);
	}

	public  CrescentSearchRequestWrapper(SearchRequest searchRequest);

}