Package com.tistory.devyongsik.crescent.collection.entity

Examples of com.tistory.devyongsik.crescent.collection.entity.CrescentCollectionField


        }
       
        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


    }

    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();
View Full Code Here

    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"))) {
View Full Code Here

    for(CrescentCollection crescentCollection : crescentCollectionList) {
      List<CrescentSortField> crescentSortFieldList = crescentCollection.getSortFields();
      Map<String, CrescentCollectionField> fieldMap = crescentCollection.getCrescentFieldByName();
     
      for(CrescentSortField sortField : crescentSortFieldList) {
        CrescentCollectionField field = fieldMap.get(sortField.getSource());
       
        if(field == null) {
          throw new IllegalStateException("정렬 필드 설정에 필요한 원본(source) 필드가 없습니다.");
        }
       
        try {
          CrescentCollectionField newSortField = (CrescentCollectionField)field.clone();
         
          newSortField.setAnalyze(false);
          newSortField.setIndex(true);
          newSortField.setName(sortField.getDest());
         
          fieldMap.put(sortField.getDest(), newSortField);
         
        } catch (CloneNotSupportedException e1) {
          logger.error("error : ", e1);
View Full Code Here

      Document document = new Document();
     
      for(String fieldName : fieldNamesFromDataFile) {
        String value = doc.get(fieldName);
       
        CrescentCollectionField crescentCollectionField = fieldsByName.get(fieldName);
       
        if(crescentCollectionField == null) {
          logger.error("해당 collection에 존재하지 않는 필드입니다. [{}]", fieldName);
          throw new IllegalStateException("해당 collection에 존재하지 않는 필드입니다. ["+fieldName+"]");
        }
       
        if (crescentCollectionField.isRemoveHtmlTag()) {
          Source source = new Source(value);
          value = source.getTextExtractor().toString();
        }
       
        IndexableField indexableField = luceneFieldBuilder.create(fieldsByName.get(fieldName), value);
        document.add(indexableField);
       
        CrescentCollectionField crescentSortField = fieldsByName.get(fieldName+"_sort");
        if(crescentSortField != null) {
          IndexableField sortFieldAble = luceneFieldBuilder.create(fieldsByName.get(fieldName+"_sort"), value);
          document.add(sortFieldAble);
        }
      }
View Full Code Here

   
    List<QueryAnalysisResult> queryAnalysisResultList = getQueryAnalysisResults(customQueryString);
   
    BooleanQuery resultQuery = new BooleanQuery();
   
    CrescentCollectionField searchTargetField = null;
   
    String fieldName = "";
    Occur occur = Occur.SHOULD;
    String userRequestQuery = "";
    float boost = 0F;
   
    boolean isRangeQuery = false;
   
    boolean any = true;
    boolean isLongField = false;
    boolean isAnalyzed = false;
   
    for(QueryAnalysisResult queryAnalysisResult : queryAnalysisResultList) {
   
      fieldName = queryAnalysisResult.getFieldName();
      occur = queryAnalysisResult.getOccur();
      userRequestQuery = queryAnalysisResult.getUserQuery();
      boost = queryAnalysisResult.getBoost();
      isRangeQuery = queryAnalysisResult.isRangeQuery();
     
      //field가 검색 대상에 있는지 확인..
      for(CrescentCollectionField crescentField : indexedFields) {
        if(fieldName.equals(crescentField.getName())) {
          any = false;
          searchTargetField = crescentField;
         
          isLongField = "LONG".equals(crescentField.getType());
          isAnalyzed = crescentField.isAnalyze();
         
          logger.debug("selected searchTargetField : {} ", searchTargetField);
          break;
        }
      }
     
      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 {
        //쿼리 생성..
        String[] keywords = userRequestQuery.split( " " );
       
        if(logger.isDebugEnabled()) {
          logger.debug("split keyword : {}", Arrays.toString(keywords));
        }
       
        for(int i = 0; i < keywords.length; i++) {
          ArrayList<String> analyzedTokenList = analyzedTokenList(analyzer, keywords[i]);

          if(!isAnalyzed || analyzedTokenList.size() == 0) {
           
            Term t = new Term(fieldName, keywords[i]);
            Query query = new TermQuery(t);
           
            if(searchTargetField.getBoost() > 1F && boost > 1F) {
              query.setBoost(searchTargetField.getBoost() + boost);
            } else if (boost > 1F) {
              query.setBoost(boost);
            } else if (searchTargetField.getBoost() > 1F) {
              query.setBoost(searchTargetField.getBoost());
            }
           
            resultQuery.add(query, occur);
           
            logger.debug("query : {} ", query.toString());
            logger.debug("result query : {} ", resultQuery.toString());
           
          } else {
           
            for(String str : analyzedTokenList) {
             
              Term t = new Term(fieldName, str);
              Query query = new TermQuery(t);
             
              if(searchTargetField.getBoost() > 1F && boost > 1F) {
                query.setBoost(searchTargetField.getBoost() + boost);
              } else if (boost > 1F) {
                query.setBoost(boost);
              } else if (searchTargetField.getBoost() > 1F) {
                query.setBoost(searchTargetField.getBoost());
              }
             
              resultQuery.add(query, occur);
             
              logger.debug("query : {} ", query.toString());
View Full Code Here

        } 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++) {
View Full Code Here

                for (String field : fieldNames) {
                    Terms terms = fields.terms(field);
                    if (terms != null) {
                        te = terms.iterator(te);
                        CrescentCollectionField crescentField = selectCollection.getCrescentFieldByName().get(field);
                        fillQueue(field, te, termStatsQueue, crescentField.getType());
                    }
                }
            }

        } catch (Exception e) {
View Full Code Here

    }
   
    if(searchRequest.getSearchField() != null && !"".equals(searchRequest.getSearchField())) {
      String[] requestSearchField = searchRequest.getSearchField().split(",");
      for(String fieldName : requestSearchField) {
        CrescentCollectionField field = collectionFieldsMap.get(fieldName);
        if(field == null) {
          throw new IllegalStateException("There is no Field in Collection [" + searchRequest.getCollectionName() + "] [" + fieldName + "]");
        }
       
        searchFields.add(collectionFieldsMap.get(fieldName));
View Full Code Here

    if(indexedFields.size() > 0) {
      return indexedFields;
    }
   
    for(String fieldName : collectionFieldsMap.keySet()) {
      CrescentCollectionField f = collectionFieldsMap.get(fieldName);
      if(f.isIndex()) {
        indexedFields.add(f);
      }
    }
   
    return indexedFields;
View Full Code Here

TOP

Related Classes of com.tistory.devyongsik.crescent.collection.entity.CrescentCollectionField

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.