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

Java NumericType类代码示例

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

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



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

示例1: getNumericDataType

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
private static NumericType getNumericDataType(Number number) throws QueryNodeException {
  
  if (number instanceof Long) {
    return NumericType.LONG;
  } else if (number instanceof Integer) {
    return NumericType.INT;
  } else if (number instanceof Double) {
    return NumericType.DOUBLE;
  } else if (number instanceof Float) {
    return NumericType.FLOAT;
  } else {
    throw new QueryNodeException(
        new MessageImpl(
            QueryParserMessages.NUMBER_CLASS_NOT_SUPPORTED_BY_NUMERIC_RANGE_QUERY,
            number.getClass()));
  }
  
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:NumericRangeQueryNode.java


示例2: setFieldValues

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
private static void setFieldValues(NumberType numberType,
    HashMap<String,Field> numericFieldMap) {
  
  Number number = getNumberType(numberType, NumericType.DOUBLE
      .name());
  numericFieldMap.get(NumericType.DOUBLE.name()).setDoubleValue(
      number.doubleValue());
  
  number = getNumberType(numberType, NumericType.INT.name());
  numericFieldMap.get(NumericType.INT.name()).setIntValue(
      number.intValue());
  
  number = getNumberType(numberType, NumericType.LONG.name());
  numericFieldMap.get(NumericType.LONG.name()).setLongValue(
      number.longValue());
  
  number = getNumberType(numberType, NumericType.FLOAT.name());
  numericFieldMap.get(NumericType.FLOAT.name()).setFloatValue(
      number.floatValue());
  
  number = getNumberType(numberType, DATE_FIELD_NAME);
  numericFieldMap.get(DATE_FIELD_NAME).setLongValue(number.longValue());
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestNumericQueryParser.java


示例3: assertSimpleQuery

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
public void assertSimpleQuery(NumberType numberType, int expectedDocCount)
    throws QueryNodeException, IOException {
  StringBuilder sb = new StringBuilder();
  
  for (NumericType type : NumericType.values()) {
    String numberStr = numberToString(getNumberType(numberType, type.name()));
    sb.append('+').append(type.name()).append(":\"").append(numberStr)
        .append("\" ");
  }
  
  String dateStr = ESCAPER.escape(
      DATE_FORMAT.format(new Date(getNumberType(numberType, DATE_FIELD_NAME)
          .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
  
  sb.append('+').append(DATE_FIELD_NAME).append(":\"").append(dateStr)
      .append('"');
  
  testQuery(sb.toString(), expectedDocCount);
  
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TestNumericQueryParser.java


示例4: getNumericType

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
@Override
public NumericType getNumericType() {
  switch (type) {
    case INTEGER:
      return NumericType.INT;
    case LONG:
    case DATE:
      return NumericType.LONG;
    case FLOAT:
      return NumericType.FLOAT;
    case DOUBLE:
      return NumericType.DOUBLE;
    default:
      throw new AssertionError();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TrieField.java


示例5: NumericRangeQuery

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
private NumericRangeQuery(final String field, final int precisionStep, final NumericType dataType,
  T min, T max, final boolean minInclusive, final boolean maxInclusive
) {
  super(field);
  if (precisionStep < 1)
    throw new IllegalArgumentException("precisionStep must be >=1");
  this.precisionStep = precisionStep;
  this.dataType = dataType;
  this.min = min;
  this.max = max;
  this.minInclusive = minInclusive;
  this.maxInclusive = maxInclusive;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:NumericRangeQuery.java


示例6: setBounds

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的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


示例7: extractQuery

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
private static Query extractQuery(IndexSchema schema, String term, String value) {
    String field = term;
    if (hasBlockJoinHint(term)) {
        field = term.split(BLOCK_JOIN_PATH_HINT)[1];
    }
    if (field.indexOf(":") > -1) {
        String[] keyValue = field.split(":");
        field = keyValue[0];
        String query = keyValue[1];
        return buildQueryFromText(field, schema, query);
    } else if (value.matches("^.*:\\[.*\\sTO\\s.*\\]$")) {
    	return buildQueryFromText(field, schema, value);
    } else if (null != tryParseDate(value)) {
        if (schema.getField(field).getType() instanceof TrieDateField) {
            return new TrieDateField().getFieldQuery(null, schema.getField(field), value);
        }
        throw new RuntimeException("Can not group on date field not a TrieDateField");
    } else if (value.matches("^-{0,1}[0-9]+")) {
    	// number
    	FieldType type = schema.getField(field).getType();
    	NumericType numericType = type.getNumericType();
    	if (numericType == NumericType.FLOAT) {
    		return new TrieFloatField().getFieldQuery(null, schema.getField(field), value);
    	} else if (numericType == NumericType.INT) {
    		return new TrieIntField().getFieldQuery(null, schema.getField(field), value);
    	} else if (numericType == NumericType.LONG) {
    		return new TrieLongField().getFieldQuery(null, schema.getField(field), value);
    	} else if (numericType == NumericType.DOUBLE) {
    		return new TrieDoubleField().getFieldQuery(null, schema.getField(field), value);
    	} else {
    		return new WildcardQuery(new Term(field, null != value ? value : "*"));
    	}
    } else {
        return new WildcardQuery(new Term(field, null != value ? value : "*"));
    }
}
 
开发者ID:terrancesnyder,项目名称:solr-groupby-component,代码行数:37,代码来源:GroupByComponent.java


示例8: build

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的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


示例9: assertRangeQuery

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
public void assertRangeQuery(NumberType lowerType, NumberType upperType,
    boolean lowerInclusive, boolean upperInclusive, int expectedDocCount)
    throws QueryNodeException, IOException {
  
  StringBuilder sb = new StringBuilder();
  
  String lowerInclusiveStr = (lowerInclusive ? "[" : "{");
  String upperInclusiveStr = (upperInclusive ? "]" : "}");
  
  for (NumericType type : NumericType.values()) {
    String lowerStr = numberToString(getNumberType(lowerType, type.name()));
    String upperStr = numberToString(getNumberType(upperType, type.name()));
    
    sb.append("+").append(type.name()).append(':').append(lowerInclusiveStr)
        .append('"').append(lowerStr).append("\" TO \"").append(upperStr)
        .append('"').append(upperInclusiveStr).append(' ');
  }
  
  Number lowerDateNumber = getNumberType(lowerType, DATE_FIELD_NAME);
  Number upperDateNumber = getNumberType(upperType, DATE_FIELD_NAME);
  String lowerDateStr;
  String upperDateStr;
  
  if (lowerDateNumber != null) {
    lowerDateStr = ESCAPER.escape(
        DATE_FORMAT.format(new Date(lowerDateNumber.longValue())), LOCALE,
        EscapeQuerySyntax.Type.STRING).toString();
    
  } else {
    lowerDateStr = "*";
  }
  
  if (upperDateNumber != null) {
  upperDateStr = ESCAPER.escape(
        DATE_FORMAT.format(new Date(upperDateNumber.longValue())), LOCALE,
        EscapeQuerySyntax.Type.STRING).toString();
  
  } else {
    upperDateStr = "*";
  }
  
  sb.append("+").append(DATE_FIELD_NAME).append(':')
      .append(lowerInclusiveStr).append('"').append(lowerDateStr).append(
          "\" TO \"").append(upperDateStr).append('"').append(
          upperInclusiveStr);
  
  testQuery(sb.toString(), expectedDocCount);
  
}
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:TestNumericQueryParser.java


示例10: assertOpenRangeQuery

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
public void assertOpenRangeQuery(NumberType boundType, String operator, int expectedDocCount)
    throws QueryNodeException, IOException {

  StringBuilder sb = new StringBuilder();
  
  for (NumericType type : NumericType.values()) {
    String boundStr = numberToString(getNumberType(boundType, type.name()));
    
    sb.append("+").append(type.name()).append(operator).append('"').append(boundStr).append('"').append(' ');
  }
  
  String boundDateStr = ESCAPER.escape(
      DATE_FORMAT.format(new Date(getNumberType(boundType, DATE_FIELD_NAME)
          .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
  
  sb.append("+").append(DATE_FIELD_NAME).append(operator).append('"').append(boundDateStr).append('"');
  
  testQuery(sb.toString(), expectedDocCount);
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:TestNumericQueryParser.java


示例11: testEquals

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
public void testEquals() throws Exception {
  FieldType ft = new FieldType();
  assertEquals(ft, ft);
  assertFalse(ft.equals(null));
  
  FieldType ft2 = new FieldType();
  assertEquals(ft, ft2);
  assertEquals(ft.hashCode(), ft2.hashCode());
  
  FieldType ft3 = new FieldType();
  ft3.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  assertFalse(ft3.equals(ft));
  
  FieldType ft4 = new FieldType();
  ft4.setDocValueType(DocValuesType.BINARY);
  assertFalse(ft4.equals(ft));
  
  FieldType ft5 = new FieldType();
  ft5.setIndexed(true);
  assertFalse(ft5.equals(ft));
  
  FieldType ft6 = new FieldType();
  ft6.setStored(true);
  assertFalse(ft6.equals(ft));
  
  FieldType ft7 = new FieldType();
  ft7.setOmitNorms(true);
  assertFalse(ft7.equals(ft));
  
  FieldType ft8 = new FieldType();
  ft8.setNumericType(NumericType.DOUBLE);
  assertFalse(ft8.equals(ft));
  
  FieldType ft9 = new FieldType();
  ft9.setNumericPrecisionStep(3);
  assertFalse(ft9.equals(ft));
  
  FieldType ft10 = new FieldType();
  ft10.setStoreTermVectors(true);
  assertFalse(ft10.equals(ft));

}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:TestFieldType.java


示例12: createField

import org.apache.lucene.document.FieldType.NumericType; //导入依赖的package包/类
@Override
public IndexableField createField(SchemaField field, Object value, float boost) {
  boolean indexed = field.indexed();
  boolean stored = field.stored();
  boolean docValues = field.hasDocValues();

  if (!indexed && !stored && !docValues) {
    if (log.isTraceEnabled())
      log.trace("Ignoring unindexed/unstored field: " + field);
    return null;
  }
  
  FieldType ft = new FieldType();
  ft.setStored(stored);
  ft.setTokenized(true);
  ft.setIndexed(indexed);
  ft.setOmitNorms(field.omitNorms());
  ft.setIndexOptions(getIndexOptions(field, value.toString()));

  switch (type) {
    case INTEGER:
      ft.setNumericType(NumericType.INT);
      break;
    case FLOAT:
      ft.setNumericType(NumericType.FLOAT);
      break;
    case LONG:
      ft.setNumericType(NumericType.LONG);
      break;
    case DOUBLE:
      ft.setNumericType(NumericType.DOUBLE);
      break;
    case DATE:
      ft.setNumericType(NumericType.LONG);
      break;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
  }
  ft.setNumericPrecisionStep(precisionStep);

  final org.apache.lucene.document.Field f;

  switch (type) {
    case INTEGER:
      int i = (value instanceof Number)
        ? ((Number)value).intValue()
        : Integer.parseInt(value.toString());
      f = new org.apache.lucene.document.IntField(field.getName(), i, ft);
      break;
    case FLOAT:
      float fl = (value instanceof Number)
        ? ((Number)value).floatValue()
        : Float.parseFloat(value.toString());
      f = new org.apache.lucene.document.FloatField(field.getName(), fl, ft);
      break;
    case LONG:
      long l = (value instanceof Number)
        ? ((Number)value).longValue()
        : Long.parseLong(value.toString());
      f = new org.apache.lucene.document.LongField(field.getName(), l, ft);
      break;
    case DOUBLE:
      double d = (value instanceof Number)
        ? ((Number)value).doubleValue()
        : Double.parseDouble(value.toString());
      f = new org.apache.lucene.document.DoubleField(field.getName(), d, ft);
      break;
    case DATE:
      Date date = (value instanceof Date)
        ? ((Date)value)
        : dateField.parseMath(null, value.toString());
      f = new org.apache.lucene.document.LongField(field.getName(), date.getTime(), ft);
      break;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
  }

  f.setBoost(boost);
  return f;
}
 
开发者ID:europeana,项目名称:search,代码行数:81,代码来源:TrieField.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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