Package org.apache.lucene.queryparser.flexible.standard.config

Examples of org.apache.lucene.queryparser.flexible.standard.config.NumericConfig


    HashMap<String,NumericConfig> numericConfigMap = new HashMap<String,NumericConfig>();
    HashMap<String,Field> numericFieldMap = new HashMap<String,Field>();
    qp.setNumericConfigMap(numericConfigMap);
   
    for (NumericType type : NumericType.values()) {
      numericConfigMap.put(type.name(), new NumericConfig(PRECISION_STEP,
          NUMBER_FORMAT, type));

      FieldType ft = new FieldType(IntField.TYPE_NOT_STORED);
      ft.setNumericType(type);
      ft.setStored(true);
      ft.setNumericPrecisionStep(PRECISION_STEP);
      ft.freeze();
      final Field field;

      switch(type) {
      case INT:
        field = new IntField(type.name(), 0, ft);
        break;
      case FLOAT:
        field = new FloatField(type.name(), 0.0f, ft);
        break;
      case LONG:
        field = new LongField(type.name(), 0l, ft);
        break;
      case DOUBLE:
        field = new DoubleField(type.name(), 0.0, ft);
        break;
      default:
        fail();
        field = null;
      }
      numericFieldMap.put(type.name(), field);
      doc.add(field);
    }
   
    numericConfigMap.put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
        DATE_FORMAT, NumericType.LONG));
    FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
    ft.setStored(true);
    ft.setNumericPrecisionStep(PRECISION_STEP);
    LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
View Full Code Here


    HashMap<String,NumericConfig> numericConfigMap = new HashMap<String,NumericConfig>();
    HashMap<String,Field> numericFieldMap = new HashMap<String,Field>();
    qp.setNumericConfigMap(numericConfigMap);
   
    for (NumericType type : NumericType.values()) {
      numericConfigMap.put(type.name(), new NumericConfig(PRECISION_STEP,
          NUMBER_FORMAT, type));

      FieldType ft = new FieldType(IntField.TYPE_NOT_STORED);
      ft.setNumericType(type);
      ft.setStored(true);
      ft.setNumericPrecisionStep(PRECISION_STEP);
      ft.freeze();
      final Field field;

      switch(type) {
      case INT:
        field = new IntField(type.name(), 0, ft);
        break;
      case FLOAT:
        field = new FloatField(type.name(), 0.0f, ft);
        break;
      case LONG:
        field = new LongField(type.name(), 0l, ft);
        break;
      case DOUBLE:
        field = new DoubleField(type.name(), 0.0, ft);
        break;
      default:
        fail();
        field = null;
      }
      numericFieldMap.put(type.name(), field);
      doc.add(field);
    }
   
    numericConfigMap.put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
        DATE_FORMAT, NumericType.LONG));
    FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
    ft.setStored(true);
    ft.setNumericPrecisionStep(PRECISION_STEP);
    LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
View Full Code Here

        for (LuceneConfigNumericField field : _luceneConfig.getNumericFields().values()) {
            String name = field.getName();
            int precisionStep = field.getPrecisionStep();
            NumberFormat format = NumberFormat.getNumberInstance();
            NumericType type = NumericType.valueOf(field.getType().toUpperCase());
            NumericConfig config = new NumericConfig(precisionStep, format, type);
            numericMap.put(name, config);
        }
        parser.setNumericConfigMap(numericMap);
        Query q = parser.parse(cswServiceSpecificConstraint, "title");
View Full Code Here

    NumericQueryNode upperNumericNode = numericRangeNode.getUpperBound();
   
    Number lowerNumber = lowerNumericNode.getValue();
    Number upperNumber = upperNumericNode.getValue();
   
    NumericConfig numericConfig = numericRangeNode.getNumericConfig();
    NumericType numberType = numericConfig.getType();
    String field = StringUtils.toString(numericRangeNode.getField());
    boolean minInclusive = numericRangeNode.isLowerInclusive();
    boolean maxInclusive = numericRangeNode.isUpperInclusive();
    int precisionStep = numericConfig.getPrecisionStep();
   
    switch (numberType) {
     
      case LONG:
        return NumericRangeQuery.newLongRange(field, precisionStep,
View Full Code Here

        FieldQueryNode fieldNode = (FieldQueryNode) node;
        FieldConfig fieldConfig = config.getFieldConfig(fieldNode
            .getFieldAsString());
       
        if (fieldConfig != null) {
          NumericConfig numericConfig = fieldConfig
              .get(ConfigurationKeys.NUMERIC_CONFIG);
         
          if (numericConfig != null) {
           
            NumberFormat numberFormat = numericConfig.getNumberFormat();
            String text = fieldNode.getTextAsString();
            Number number = null;
           
            if (text.length() > 0) {
             
              try {
                number = numberFormat.parse(text);
               
              } catch (ParseException e) {
                throw new QueryNodeParseException(new MessageImpl(
                    QueryParserMessages.COULD_NOT_PARSE_NUMBER, fieldNode
                        .getTextAsString(), numberFormat.getClass()
                        .getCanonicalName()), e);
              }
             
              switch (numericConfig.getType()) {
                case LONG:
                  number = number.longValue();
                  break;
                case INT:
                  number = number.intValue();
View Full Code Here

        FieldConfig fieldConfig = config.getFieldConfig(StringUtils
            .toString(termRangeNode.getField()));
       
        if (fieldConfig != null) {
         
          NumericConfig numericConfig = fieldConfig
              .get(ConfigurationKeys.NUMERIC_CONFIG);
         
          if (numericConfig != null) {
           
            FieldQueryNode lower = termRangeNode.getLowerBound();
            FieldQueryNode upper = termRangeNode.getUpperBound();
           
            String lowerText = lower.getTextAsString();
            String upperText = upper.getTextAsString();
            NumberFormat numberFormat = numericConfig.getNumberFormat();
            Number lowerNumber = null, upperNumber = null;
           
             if (lowerText.length() > 0) {
             
              try {
                lowerNumber = numberFormat.parse(lowerText);
               
              } catch (ParseException e) {
                throw new QueryNodeParseException(new MessageImpl(
                    QueryParserMessages.COULD_NOT_PARSE_NUMBER, lower
                        .getTextAsString(), numberFormat.getClass()
                        .getCanonicalName()), e);
              }
             
            }
           
             if (upperText.length() > 0) {
           
              try {
                upperNumber = numberFormat.parse(upperText);
               
              } catch (ParseException e) {
                throw new QueryNodeParseException(new MessageImpl(
                    QueryParserMessages.COULD_NOT_PARSE_NUMBER, upper
                        .getTextAsString(), numberFormat.getClass()
                        .getCanonicalName()), e);
              }
           
            }
           
            switch (numericConfig.getType()) {
              case LONG:
                if (upperNumber != null) upperNumber = upperNumber.longValue();
                if (lowerNumber != null) lowerNumber = lowerNumber.longValue();
                break;
              case INT:
View Full Code Here

    HashMap<String,NumericConfig> numericConfigMap = new HashMap<>();
    HashMap<String,Field> numericFieldMap = new HashMap<>();
    qp.setNumericConfigMap(numericConfigMap);
   
    for (NumericType type : NumericType.values()) {
      numericConfigMap.put(type.name(), new NumericConfig(PRECISION_STEP,
          NUMBER_FORMAT, type));

      FieldType ft = new FieldType(IntField.TYPE_NOT_STORED);
      ft.setNumericType(type);
      ft.setStored(true);
      ft.setNumericPrecisionStep(PRECISION_STEP);
      ft.freeze();
      final Field field;

      switch(type) {
      case INT:
        field = new IntField(type.name(), 0, ft);
        break;
      case FLOAT:
        field = new FloatField(type.name(), 0.0f, ft);
        break;
      case LONG:
        field = new LongField(type.name(), 0l, ft);
        break;
      case DOUBLE:
        field = new DoubleField(type.name(), 0.0, ft);
        break;
      default:
        fail();
        field = null;
      }
      numericFieldMap.put(type.name(), field);
      doc.add(field);
    }
   
    numericConfigMap.put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
        DATE_FORMAT, NumericType.LONG));
    FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
    ft.setStored(true);
    ft.setNumericPrecisionStep(PRECISION_STEP);
    LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
View Full Code Here

    {
        super(analyzer);

        // All fields indexed numerically need to be listed here in order to properly search on them.
        Map<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
        numericConfigMap.put("year", new NumericConfig(8, NumberFormat.getInstance(), FieldType.NumericType.INT));
        numericConfigMap.put("modified", new NumericConfig(8, NumberFormat.getInstance(), FieldType.NumericType.LONG));
        numericConfigMap.put("published", new NumericConfig(8, NumberFormat.getInstance(), FieldType.NumericType.LONG));
        numericConfigMap.put("when", new NumericConfig(8, NumberFormat.getInstance(), FieldType.NumericType.LONG));
        this.setNumericConfigMap(numericConfigMap);
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.queryparser.flexible.standard.config.NumericConfig

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.