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.Long stats(IndexReader reader) throws IOException { int maxDoc = reader.maxDoc(); Terms terms = org.apache.lucene.index.MultiFields.getTerms(reader, name()); if (terms == null) { return null; } long minValue = LegacyNumericUtils.getMinInt(terms); long maxValue = LegacyNumericUtils.getMaxInt(terms); return new FieldStats.Long( maxDoc, terms.getDocCount(), terms.getSumDocFreq(), terms.getSumTotalTermFreq(), isSearchable(), isAggregatable(), minValue, maxValue); }
public void testIntFieldMinMax() throws Exception { Directory dir = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), dir); int numDocs = atLeast(100); int minValue = Integer.MAX_VALUE; int maxValue = Integer.MIN_VALUE; for (int i = 0; i < numDocs; i++) { Document doc = new Document(); int num = random().nextInt(); minValue = Math.min(num, minValue); maxValue = Math.max(num, maxValue); doc.add(new LegacyIntField("field", num, Field.Store.NO)); w.addDocument(doc); } IndexReader r = w.getReader(); Terms terms = MultiFields.getTerms(r, "field"); assertEquals(new Integer(minValue), LegacyNumericUtils.getMinInt(terms)); assertEquals(new Integer(maxValue), LegacyNumericUtils.getMaxInt(terms)); r.close(); w.close(); dir.close(); }
public void testEmptyIntFieldMinMax() throws Exception { assertNull(LegacyNumericUtils.getMinInt(EMPTY_TERMS)); assertNull(LegacyNumericUtils.getMaxInt(EMPTY_TERMS)); }