当前位置: 首页>>代码示例>>Java>>正文


Java NumericUtils.intToPrefixCodedBytes方法代码示例

本文整理汇总了Java中org.apache.lucene.util.NumericUtils.intToPrefixCodedBytes方法的典型用法代码示例。如果您正苦于以下问题:Java NumericUtils.intToPrefixCodedBytes方法的具体用法?Java NumericUtils.intToPrefixCodedBytes怎么用?Java NumericUtils.intToPrefixCodedBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.NumericUtils的用法示例。


在下文中一共展示了NumericUtils.intToPrefixCodedBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readableToIndexed

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
  String s = val.toString();
  switch (type) {
    case INTEGER:
      NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);
      break;
    case FLOAT:
      NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
      break;
    case LONG:
      NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);
      break;
    case DOUBLE:
      NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
      break;
    case DATE:
      NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result);
      break;
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:TrieField.java

示例2: readableToIndexed

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
  String s = val.toString();
  BytesRefBuilder b = new BytesRefBuilder();
  try {
    switch (type) {
      case INTEGER:
        NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, b);
        break;
      case FLOAT:
        NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, b);
        break;
      case LONG:
        NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, b);
        break;
      case DOUBLE:
        NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, b);
        break;
      case DATE:
        NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, b);
        break;
      default:
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
    result.copyBytes(b.get());
  } catch (NumberFormatException nfe) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
                            "Invalid Number: " + val);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:TrieField.java

示例3: readableToIndexed

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void readableToIndexed(CharSequence val, BytesRef result) {
  String s = val.toString();
  try {
    switch (type) {
      case INTEGER:
        NumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);
        break;
      case FLOAT:
        NumericUtils.intToPrefixCodedBytes(NumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
        break;
      case LONG:
        NumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);
        break;
      case DOUBLE:
        NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
        break;
      case DATE:
        NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result);
        break;
      default:
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
    }
  } catch (NumberFormatException nfe) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, 
                            "Invalid Number: " + val);
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:29,代码来源:TrieField.java

示例4: toIndexForm

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
@Override
public void toIndexForm(Number number, BytesRefBuilder bytes) {
    NumericUtils.intToPrefixCodedBytes(number.intValue(), 0, bytes);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:IndexNumericFieldData.java

示例5: testRandomTrieAndClassicRangeQuery

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
  String field="field"+precisionStep;
  int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
  int num = TestUtil.nextInt(random(), 10, 20);
  for (int i = 0; i < num; i++) {
    int lower=(int)(random().nextDouble()*noDocs*distance)+startOffset;
    int upper=(int)(random().nextDouble()*noDocs*distance)+startOffset;
    if (lower>upper) {
      int a=lower; lower=upper; upper=a;
    }
    final BytesRef lowerBytes, upperBytes;
    BytesRefBuilder b = new BytesRefBuilder();
    NumericUtils.intToPrefixCodedBytes(lower, 0, b);
    lowerBytes = b.toBytesRef();
    NumericUtils.intToPrefixCodedBytes(upper, 0, b);
    upperBytes = b.toBytesRef();

    // test inclusive range
    NumericRangeQuery<Integer> tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true);
    TermRangeQuery cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, true);
    TopDocs tTopDocs = searcher.search(tq, 1);
    TopDocs cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, false);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test left exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, true);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test right exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, false);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
  }
  
  checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
  if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
    System.out.println("Average number of terms during random search on '" + field + "':");
    System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
    System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:63,代码来源:TestNumericRangeQuery32.java

示例6: testRandomTrieAndClassicRangeQuery

import org.apache.lucene.util.NumericUtils; //导入方法依赖的package包/类
private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
  String field="field"+precisionStep;
  int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
  int num = _TestUtil.nextInt(random(), 10, 20);
  for (int i = 0; i < num; i++) {
    int lower=(int)(random().nextDouble()*noDocs*distance)+startOffset;
    int upper=(int)(random().nextDouble()*noDocs*distance)+startOffset;
    if (lower>upper) {
      int a=lower; lower=upper; upper=a;
    }
    final BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_INT), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_INT);
    NumericUtils.intToPrefixCodedBytes(lower, 0, lowerBytes);
    NumericUtils.intToPrefixCodedBytes(upper, 0, upperBytes);

    // test inclusive range
    NumericRangeQuery<Integer> tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, true);
    TermRangeQuery cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, true);
    TopDocs tTopDocs = searcher.search(tq, 1);
    TopDocs cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, false);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test left exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, false, true);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
    // test right exclusive range
    tq=NumericRangeQuery.newIntRange(field, precisionStep, lower, upper, true, false);
    cq=new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
    tTopDocs = searcher.search(tq, 1);
    cTopDocs = searcher.search(cq, 1);
    assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
    totalTermCountT += termCountT = countTerms(tq);
    totalTermCountC += termCountC = countTerms(cq);
    checkTermCounts(precisionStep, termCountT, termCountC);
  }
  
  checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
  if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
    System.out.println("Average number of terms during random search on '" + field + "':");
    System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
    System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:60,代码来源:TestNumericRangeQuery32.java


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