Package com.tistory.devyongsik.crescent.search.exception

Examples of com.tistory.devyongsik.crescent.search.exception.CrescentInvalidRequestException


   
    CrescentCollection collection = collectionHandler.getCrescentCollections()
                          .getCrescentCollection(searchRequest.getCollectionName());
   
    if(collection == null) {
      throw new CrescentInvalidRequestException("Wrong Collection Name : " + searchRequest.getCollectionName());
    }
   
   
    //request search field
    if(searchRequest.getSearchField() != null) {
      String[] requestSearchFieldNames = searchRequest.getSearchField().split(",");
     
      if(requestSearchFieldNames != null && requestSearchFieldNames[0].length() > 0) {
        for(String requestFieldName : requestSearchFieldNames) {
          if(!collection.getCrescentFieldByName().containsKey(requestFieldName)) {
            throw new CrescentInvalidRequestException("Wrong Search Field Name : " + searchRequest.getSearchField());
          }
        }
      }
    }
   
    //page num
    if(searchRequest.getPageNum() != null) {
      if(!StringUtil.isNumeric(searchRequest.getPageNum())) {
        throw new CrescentInvalidRequestException("Page_Num parameter value is must positive number: " + searchRequest.getPageNum());
      }
    }
   
    //request sort field
    String sortQueryString = searchRequest.getSort();
    if(sortQueryString == null || "".equals(sortQueryString) || "null".equals(sortQueryString)) {
      //nothing
    } else {
 
      String[] parts = sortQueryString.split(",");
      if(parts.length == 0) {
        throw new CrescentInvalidRequestException("Wrong Sort Field Name : " + sortQueryString);
      }
 
      for(int i = 0; i < parts.length; i++) {
        String part = parts[i].trim(); //part = field desc
       
        int idx = part.indexOf( ' ' );
       
        if(idx <= 0) {
          throw new CrescentInvalidRequestException("No Order Condition (DESC/ASC) : " + sortQueryString);
        }
       
        part = part.substring( 0, idx ).trim(); //part = field
        Map<String, CrescentCollectionField> collectionFields = collection.getCrescentFieldByName();
       
        CrescentCollectionField f = collectionFields.get(part);
       
        if(f == null) throw new CrescentInvalidRequestException("요청된 필드가 존재하지 않습니다. ["+part+"]");
        if(f.isAnalyze()) throw new CrescentInvalidRequestException("Analyze 된 필드는 Sort가 불가능합니다. ["+part+"]");
      }
    }
   
    return true;
  }
View Full Code Here


        }
      }
     
      if(any) {
        logger.error("검색 할 수 없는 필드입니다. {} " , fieldName);
        throw new CrescentInvalidRequestException("검색 할 수 없는 필드입니다. [" + fieldName + "]");
      }
     
      //range쿼리인 경우에는 RangeQuery 생성
      if(isRangeQuery) {

        //QueryParser qp = new QueryParser(Version.LUCENE_36, fieldName, analyzer);
        String minValue = "";
        String maxValue = "";
        boolean isIncludeMin = false;
        boolean isIncludeMax = false;
       
        String[] splitQuery = userRequestQuery.split("TO");
        logger.info("splitQuery : {}", Arrays.toString(splitQuery));
       
        if(splitQuery.length != 2) {
          logger.error("문법 오류 확인바랍니다. {} " , userRequestQuery);
          throw new CrescentInvalidRequestException("문법 오류 확인바랍니다. [" + userRequestQuery + "]");
        }
       
        if(splitQuery[0].trim().startsWith("[")) {
          isIncludeMin = true;
        }
       
        if(splitQuery[1].trim().endsWith("]")) {
          isIncludeMax = true;
        }
       
        logger.debug("minInclude : {}, maxInclude : {}", isIncludeMin, isIncludeMax);
       
        minValue = splitQuery[0].trim().substring(1);
        maxValue = splitQuery[1].trim().substring(0, splitQuery[1].trim().length() - 1);
       
        logger.debug("minValue : {}, maxValue : {}", minValue, maxValue);
       
        boolean isNumeric = false;
        isNumeric = StringUtils.isNumeric(minValue) && StringUtils.isNumeric(maxValue);
       
        logger.debug("isLongField : {}", isLongField);
        logger.debug("is numeric : {}", isNumeric);
       
        Query query = null;
       
        if(isAnalyzed) {
          logger.error("범위검색 대상 field는 analyzed값이 false이어야 합니다. {} " , userRequestQuery);
          throw new CrescentInvalidRequestException("범위검색 대상 field는 analyzed값이 false이어야 합니다. [" + userRequestQuery + "]");
        }
       
        if(isLongField && isNumeric) {
       
          query = NumericRangeQuery.newLongRange(fieldName, Long.parseLong(minValue), Long.parseLong(maxValue), isIncludeMin, isIncludeMax);
       
        } else if (!(isLongField && isNumeric)){
         
          BytesRef minValBytes = new BytesRef(minValue);
          BytesRef maxValBytes = new BytesRef(maxValue);
         
          query = new TermRangeQuery(fieldName, minValBytes, maxValBytes, isIncludeMin, isIncludeMax);
         
        } else {
          logger.error("범위검색은 필드의 타입과 쿼리의 타입이 맞아야 합니다. {} " , userRequestQuery);
          throw new CrescentInvalidRequestException("범위검색은 필드의 타입과 쿼리의 타입이 맞아야 합니다. [" + userRequestQuery + "]");
        }
       
        resultQuery.add(query, occur);
       
      } else {
View Full Code Here

   
    Matcher m = pattern.matcher(analysisTargetString);
   
    while(m.find()) {
      if(m.groupCount() != 3) {
        throw new CrescentInvalidRequestException("쿼리 문법 오류. [" + analysisTargetString + "]");
      }
     
      QueryAnalysisResult anaysisResult = new QueryAnalysisResult();
     
      Occur occur = Occur.SHOULD;
View Full Code Here

       
        resultQuery = queryParser.getQuery(getIndexedFields(), customQueryString, collection.getSearchModeAnalyzer(), regexQueryString);
     
      } catch (Exception e) {
        logger.error("Error In getQuery ", e);
        throw new CrescentInvalidRequestException(e.getMessage());
      }
     
    } else {
     
      if (getKeyword() == null || getKeyword().length() == 0) {
View Full Code Here

       
        return filter;
       
      } catch (Exception e) {
        logger.error("Error In getFilter ", e);
        throw new CrescentInvalidRequestException(e.getMessage());
      }
     
    } else {
     
      return null;
View Full Code Here

TOP

Related Classes of com.tistory.devyongsik.crescent.search.exception.CrescentInvalidRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.