• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NumericConfig类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.queryparser.flexible.standard.config.NumericConfig的典型用法代码示例。如果您正苦于以下问题:Java NumericConfig类的具体用法?Java NumericConfig怎么用?Java NumericConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NumericConfig类属于org.apache.lucene.queryparser.flexible.standard.config包,在下文中一共展示了NumericConfig类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initAttributeNumericConfig

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
void initAttributeNumericConfig() {
    NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
    intNumericConfig = new NumericConfig(precisionStep, numberFormat, FieldType.NumericType.INT);
    longNumericConfig = new NumericConfig(precisionStep, numberFormat, FieldType.NumericType.LONG);
    floatNumericConfig = new NumericConfig(precisionStep, numberFormat, FieldType.NumericType.FLOAT);
    doubleNumericConfig = new NumericConfig(precisionStep, numberFormat, FieldType.NumericType.DOUBLE);

    attributeNumericConfigMap = new HashMap<>();
    attributeNumericConfigMap.put(Byte.TYPE, intNumericConfig);
    attributeNumericConfigMap.put(Byte.class, intNumericConfig);
    attributeNumericConfigMap.put(Short.TYPE, intNumericConfig);
    attributeNumericConfigMap.put(Short.class, intNumericConfig);
    attributeNumericConfigMap.put(Integer.TYPE, intNumericConfig);
    attributeNumericConfigMap.put(Integer.class, intNumericConfig);
    attributeNumericConfigMap.put(Long.TYPE, longNumericConfig);
    attributeNumericConfigMap.put(Long.class, longNumericConfig);
    attributeNumericConfigMap.put(Float.TYPE, floatNumericConfig);
    attributeNumericConfigMap.put(Float.class, floatNumericConfig);
    // Statistics of features are stored as Double, but Float is sufficient.
    attributeNumericConfigMap.put(Double.TYPE, floatNumericConfig);
    attributeNumericConfigMap.put(Double.class, floatNumericConfig);
}
 
开发者ID:bcdev,项目名称:esa-pfa,代码行数:23,代码来源:NumericConfiguration.java


示例2: testRangeParsing

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
@Test
public void testRangeParsing() throws Exception {
    NumericConfig numericConfig = new NumericConfig(8, NumberFormat.getNumberInstance(Locale.ENGLISH), FieldType.NumericType.FLOAT);
    HashMap<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
    numericConfigMap.put("reflec_7", numericConfig);
    numericConfigMap.put("reflec_8", numericConfig);
    numericConfigMap.put("reflec_9", numericConfig);
    StandardQueryParser parser = new StandardQueryParser();
    parser.setNumericConfigMap(numericConfigMap);

    Query query1 = parser.parse("reflec_8:[0.0 TO 1.0]", "x");
    assertEquals(NumericRangeQuery.class, query1.getClass());

    Query query2 = parser.parse("reflec_8:[0.0 TO 1.0] AND reflec_9:[0.2 TO 0.6]^3.1", "x");
    assertEquals(BooleanQuery.class, query2.getClass());
    BooleanClause clause1 = ((BooleanQuery) query2).getClauses()[0];
    BooleanClause clause2 = ((BooleanQuery) query2).getClauses()[1];
    NumericRangeQuery<Float> nrq1 = NumericRangeQuery.newFloatRange("reflec_8", 8, 0.0F, 1.0F, true, true);
    NumericRangeQuery<Float> nrq2 = NumericRangeQuery.newFloatRange("reflec_9", 8, 0.2F, 0.6F, true, true);
    nrq2.setBoost(3.1F);
    assertEquals(nrq1, clause1.getQuery());
    assertEquals(BooleanClause.Occur.MUST, clause1.getOccur());
    assertEquals(nrq2, clause2.getQuery());
    assertEquals(BooleanClause.Occur.MUST, clause2.getOccur());
}
 
开发者ID:bcdev,项目名称:esa-pfa,代码行数:26,代码来源:StandardQueryParserTest.java


示例3: ExpertRevisionSearchCommand

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
private ExpertRevisionSearchCommand(DirectoryManager.DirectoryPath path, String qry, Configuration configuration)
        throws QueryNodeException {
    super(path, ResultList.ResultType.REVISION);
    setLanguage(extractLanguage(qry));
    Map<String, NumericConfig> nums = new HashMap<>();

    /*StandardQueryParser parser = new StandardQueryParser(getAnalyzer());*/
    StandardQueryParser parser = new StandardQueryParser();
    parser.setAllowLeadingWildcard(true);
    parser.setAnalyzer(getAnalyzer());
    if(!StringUtils.hasText(qry)) {
        throw new ParseException(new MessageImpl("EMPTY_QUERY"));
    }
    query = parser.parse(qry, "general");

    // No matter if we have configuraion or not we'll parse the query twice. This second parsing will add analyzers for known keys like key.id
    // as well as fields found from configuration if configuration is provided
    addAnalyzersAndConfigs(query, nums, configuration);
    parser.setAnalyzer(getAnalyzer());
    parser.setNumericConfigMap(nums);
    query = parser.parse(qry, "general");
}
 
开发者ID:Tietoarkisto,项目名称:metka,代码行数:23,代码来源:ExpertRevisionSearchCommand.java


示例4: setBounds

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
/**
 * Sets the upper and lower bounds of this range query node and the
 * {@link NumericConfig} associated with these bounds.
 * 
 * @param lower the lower bound
 * @param upper the upper bound
 * @param lowerInclusive <code>true</code> if the lower bound is inclusive, otherwise, <code>false</code>
 * @param upperInclusive <code>true</code> if the upper bound is inclusive, otherwise, <code>false</code>
 * @param numericConfig the {@link NumericConfig} that represents associated with the upper and lower bounds
 * 
 */
public void setBounds(NumericQueryNode lower, NumericQueryNode upper,
    boolean lowerInclusive, boolean upperInclusive, NumericConfig numericConfig) throws QueryNodeException {
  
  if (numericConfig == null) {
    throw new IllegalArgumentException("numericConfig cannot be null!");
  }
  
  NumericType lowerNumberType, upperNumberType;
  
  if (lower != null && lower.getValue() != null) {
    lowerNumberType = getNumericDataType(lower.getValue());
  } else {
    lowerNumberType = null;
  }
  
  if (upper != null && upper.getValue() != null) {
    upperNumberType = getNumericDataType(upper.getValue());
  } else {
    upperNumberType = null;
  }
  
  if (lowerNumberType != null
      && !lowerNumberType.equals(numericConfig.getType())) {
    throw new IllegalArgumentException(
        "lower value's type should be the same as numericConfig type: "
            + lowerNumberType + " != " + numericConfig.getType());
  }
  
  if (upperNumberType != null
      && !upperNumberType.equals(numericConfig.getType())) {
    throw new IllegalArgumentException(
        "upper value's type should be the same as numericConfig type: "
            + upperNumberType + " != " + numericConfig.getType());
  }
  
  super.setBounds(lower, upper, lowerInclusive, upperInclusive);
  this.numericConfig = numericConfig;
  
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:51,代码来源:NumericRangeQueryNode.java


示例5: getNumericConfigMap

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
public Map<String, NumericConfig> getNumericConfigMap(DatasetDescriptor dsDescriptor) {
    initAttributeNumericConfig();
    Map<String, NumericConfig> numericConfigMap = new HashMap<>();
    numericConfigMap.put("id", longNumericConfig);
    numericConfigMap.put("px", intNumericConfig);
    numericConfigMap.put("py", intNumericConfig);
    numericConfigMap.put("rnd", doubleNumericConfig);
    numericConfigMap.put("lat", floatNumericConfig);
    numericConfigMap.put("lon", floatNumericConfig);
    numericConfigMap.put("time", longNumericConfig);
    addAttributeNumericConfigs(dsDescriptor, numericConfigMap);
    return numericConfigMap;
}
 
开发者ID:bcdev,项目名称:esa-pfa,代码行数:14,代码来源:NumericConfiguration.java


示例6: addAnalyzersAndConfigs

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
private void addAnalyzersAndConfigs(Query query, Map<String, NumericConfig> nums, Configuration config) {
    if(query instanceof TermQuery) {
        addTermQuery((TermQuery) query, nums, config);
    } else if(query instanceof MultiTermQuery) {
        addMultiQuery((MultiTermQuery)query, nums, config);
    } else if(query instanceof SpanQuery) {
        addSpanQuery((SpanQuery)query, nums, config);
    } else if(query instanceof BooleanQuery) {
        addBooleanQuery((BooleanQuery)query, nums, config);
    }/* else if(query instanceof PhraseQuery) {
        addPhraseQuery((PhraseQuery)query, nums, config);
    }*/
    // TODO: Some query types might still be missed in which case they don't have correct numeric configurations etc.
}
 
开发者ID:Tietoarkisto,项目名称:metka,代码行数:15,代码来源:ExpertRevisionSearchCommand.java


示例7: postProcessNode

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
@Override
protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException {
  
  if (node instanceof FieldQueryNode
      && !(node.getParent() instanceof RangeQueryNode)) {
    
    QueryConfigHandler config = getQueryConfigHandler();
    
    if (config != null) {
      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();
                break;
              case DOUBLE:
                number = number.doubleValue();
                break;
              case FLOAT:
                number = number.floatValue();
            }
            
          } else {
            throw new QueryNodeParseException(new MessageImpl(
                QueryParserMessages.NUMERIC_CANNOT_BE_EMPTY, fieldNode.getFieldAsString()));
          }
          
          NumericQueryNode lowerNode = new NumericQueryNode(fieldNode
              .getField(), number, numberFormat);
          NumericQueryNode upperNode = new NumericQueryNode(fieldNode
              .getField(), number, numberFormat);
          
          return new NumericRangeQueryNode(lowerNode, upperNode, true, true,
              numericConfig);
          
        }
        
      }
      
    }
    
  }
  
  return node;
  
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:74,代码来源:NumericQueryNodeProcessor.java


示例8: setNumericConfigMap

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
public void setNumericConfigMap(Map<String,NumericConfig> numericConfigMap) {
  getQueryConfigHandler().set(ConfigurationKeys.NUMERIC_CONFIG_MAP, numericConfigMap);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:StandardQueryParser.java


示例9: getNumericConfigMap

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
public Map<String,NumericConfig> getNumericConfigMap() {
  return getQueryConfigHandler().get(ConfigurationKeys.NUMERIC_CONFIG_MAP);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:StandardQueryParser.java


示例10: build

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
@Override
public NumericRangeQuery<? extends Number> build(QueryNode queryNode)
    throws QueryNodeException {
  NumericRangeQueryNode numericRangeNode = (NumericRangeQueryNode) queryNode;
  
  NumericQueryNode lowerNumericNode = numericRangeNode.getLowerBound();
  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,
          (Long) lowerNumber, (Long) upperNumber, minInclusive, maxInclusive);
    
    case INT:
      return NumericRangeQuery.newIntRange(field, precisionStep,
          (Integer) lowerNumber, (Integer) upperNumber, minInclusive,
          maxInclusive);
    
    case FLOAT:
      return NumericRangeQuery.newFloatRange(field, precisionStep,
          (Float) lowerNumber, (Float) upperNumber, minInclusive,
          maxInclusive);
    
    case DOUBLE:
      return NumericRangeQuery.newDoubleRange(field, precisionStep,
          (Double) lowerNumber, (Double) upperNumber, minInclusive,
          maxInclusive);
      
      default :
        throw new QueryNodeException(new MessageImpl(
          QueryParserMessages.UNSUPPORTED_NUMERIC_DATA_TYPE, numberType));
      
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:NumericRangeQueryNodeBuilder.java


示例11: getAttributeNumericConfig

import org.apache.lucene.queryparser.flexible.standard.config.NumericConfig; //导入依赖的package包/类
private NumericConfig getAttributeNumericConfig(AttributeType attributeType) {
    Class<?> valueType = attributeType.getValueType();
    return attributeNumericConfigMap.get(valueType);
}
 
开发者ID:bcdev,项目名称:esa-pfa,代码行数:5,代码来源:NumericConfiguration.java



注:本文中的org.apache.lucene.queryparser.flexible.standard.config.NumericConfig类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IWorkbenchActivitySupport类代码示例发布时间:2022-05-23
下一篇:
Java EdmPrimitiveTypeException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap