當前位置: 首頁>>代碼示例>>Java>>正文


Java NumericUtils.longToPrefixCodedBytes方法代碼示例

本文整理匯總了Java中org.apache.lucene.util.NumericUtils.longToPrefixCodedBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java NumericUtils.longToPrefixCodedBytes方法的具體用法?Java NumericUtils.longToPrefixCodedBytes怎麽用?Java NumericUtils.longToPrefixCodedBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.util.NumericUtils的用法示例。


在下文中一共展示了NumericUtils.longToPrefixCodedBytes方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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.longToPrefixCodedBytes(number.longValue(), 0, bytes);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:5,代碼來源:IndexNumericFieldData.java

示例5: makeNumberTermQuery

import org.apache.lucene.util.NumericUtils; //導入方法依賴的package包/類
private Query makeNumberTermQuery(String field, double number) {
  BytesRefBuilder bytes = new BytesRefBuilder();
  NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(number), 0, bytes);
  return new TermQuery(new Term(field, bytes.get()));
}
 
開發者ID:europeana,項目名稱:search,代碼行數:6,代碼來源:BBoxStrategy.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++) {
    long lower=(long)(random().nextDouble()*noDocs*distance)+startOffset;
    long upper=(long)(random().nextDouble()*noDocs*distance)+startOffset;
    if (lower>upper) {
      long a=lower; lower=upper; upper=a;
    }
    final BytesRef lowerBytes, upperBytes;
    BytesRefBuilder b = new BytesRefBuilder();
    NumericUtils.longToPrefixCodedBytes(lower, 0, b);
    lowerBytes = b.toBytesRef();
    NumericUtils.longToPrefixCodedBytes(upper, 0, b);
    upperBytes = b.toBytesRef();
    
    // test inclusive range
    NumericRangeQuery<Long> tq=NumericRangeQuery.newLongRange(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.newLongRange(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.newLongRange(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.newLongRange(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,代碼來源:TestNumericRangeQuery64.java

示例7: 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++) {
    long lower=(long)(random().nextDouble()*noDocs*distance)+startOffset;
    long upper=(long)(random().nextDouble()*noDocs*distance)+startOffset;
    if (lower>upper) {
      long a=lower; lower=upper; upper=a;
    }
    final BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_LONG);
    NumericUtils.longToPrefixCodedBytes(lower, 0, lowerBytes);
    NumericUtils.longToPrefixCodedBytes(upper, 0, upperBytes);
    
    // test inclusive range
    NumericRangeQuery<Long> tq=NumericRangeQuery.newLongRange(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.newLongRange(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.newLongRange(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.newLongRange(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,代碼來源:TestNumericRangeQuery64.java


注:本文中的org.apache.lucene.util.NumericUtils.longToPrefixCodedBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。