Beispiel #1
0
  public void testFloatFieldMinMax() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    int numDocs = atLeast(100);
    float minValue = Float.POSITIVE_INFINITY;
    float maxValue = Float.NEGATIVE_INFINITY;
    for (int i = 0; i < numDocs; i++) {
      Document doc = new Document();
      float num = random().nextFloat();
      minValue = Math.min(num, minValue);
      maxValue = Math.max(num, maxValue);
      doc.add(new LegacyFloatField("field", num, Field.Store.NO));
      w.addDocument(doc);
    }

    IndexReader r = w.getReader();
    Terms terms = MultiFields.getTerms(r, "field");
    assertEquals(
        minValue, NumericUtils.sortableIntToFloat(LegacyNumericUtils.getMinInt(terms)), 0.0f);
    assertEquals(
        maxValue, NumericUtils.sortableIntToFloat(LegacyNumericUtils.getMaxInt(terms)), 0.0f);

    r.close();
    w.close();
    dir.close();
  }
 @Override
 public FieldStats stats(Terms terms, int maxDoc) throws IOException {
   float minValue = NumericUtils.sortableIntToFloat(NumericUtils.getMinInt(terms));
   float maxValue = NumericUtils.sortableIntToFloat(NumericUtils.getMaxInt(terms));
   return new FieldStats.Float(
       maxDoc,
       terms.getDocCount(),
       terms.getSumDocFreq(),
       terms.getSumTotalTermFreq(),
       minValue,
       maxValue);
 }
Beispiel #3
0
 @Override
 public String indexedToReadable(String indexedForm) {
   switch (type) {
     case INTEGER:
       return Integer.toString(NumericUtils.prefixCodedToInt(indexedForm));
     case FLOAT:
       return Float.toString(
           NumericUtils.sortableIntToFloat(NumericUtils.prefixCodedToInt(indexedForm)));
     case LONG:
       return Long.toString(NumericUtils.prefixCodedToLong(indexedForm));
     case DOUBLE:
       return Double.toString(
           NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexedForm)));
     case DATE:
       return dateField.toExternal(new Date(NumericUtils.prefixCodedToLong(indexedForm)));
     default:
       throw new SolrException(
           SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
   }
 }