org.apache.lucene.index.NumericDocValues Java Examples

The following examples show how to use org.apache.lucene.index.NumericDocValues. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LongValueFacetCounts.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void countAllMultiValued(IndexReader reader, String field) throws IOException {

    for (LeafReaderContext context : reader.leaves()) {

      SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);
      if (values == null) {
        // this field has no doc values for this segment
        continue;
      }
      NumericDocValues singleValues = DocValues.unwrapSingleton(values);
      if (singleValues != null) {
        countAllOneSegment(singleValues);
      } else {
        int doc;
        while ((doc = values.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
          int limit = values.docValueCount();
          totCount += limit;
          for (int i = 0; i < limit; i++) {
            increment(values.nextValue());
          }
        }
      }
    }
  }
 
Example #2
Source File: DiskDocValuesProducer.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
@Override
public NumericDocValues getNumeric(FieldInfo field) throws IOException {
  NumericDocValues numericDocValues = _numericDocValuesCache.get(field.number);
  if (numericDocValues != null) {
    return numericDocValues;
  }
  synchronized (_numericDocValuesCache) {
    numericDocValues = _numericDocValuesCache.get(field.number);
    if (numericDocValues != null) {
      return numericDocValues;
    }
    NumericEntry entry = numerics.get(field.number);
    numericDocValues = newNumeric(entry);
    if (_cache && numericDocValues != null) {
      _numericDocValuesCache.put(field.number, numericDocValues);
    }
    return numericDocValues;
  }
}
 
Example #3
Source File: LongFieldWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public boolean write(SortDoc sortDoc, LeafReader reader, MapWriter.EntryWriter ew, int fieldIndex) throws IOException {
  long val;
  SortValue sortValue = sortDoc.getSortValue(this.field);
  if (sortValue != null) {
    if (sortValue.isPresent()) {
      val = (long) sortValue.getCurrentValue();
    } else { //empty-value
      return false;
    }
  } else {
    // field is not part of 'sort' param, but part of 'fl' param
    NumericDocValues vals = DocValues.getNumeric(reader, this.field);
    if (vals.advance(sortDoc.docId) == sortDoc.docId) {
      val = vals.longValue();
    } else {
      return false;
    }
  }
  ew.put(field, val);
  return true;
}
 
Example #4
Source File: DoubleValuesSource.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public FieldComparator<Double> newComparator(String fieldname, int numHits,
                                           int sortPos, boolean reversed) {
  return new FieldComparator.DoubleComparator(numHits, fieldname, missingValue){

    LeafReaderContext ctx;
    DoubleValuesHolder holder = new DoubleValuesHolder();

    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      ctx = context;
      return asNumericDocValues(holder, Double::doubleToLongBits);
    }

    @Override
    public void setScorer(Scorable scorer) throws IOException {
      holder.values = producer.getValues(ctx, fromScorer(scorer));
    }
  };
}
 
Example #5
Source File: SecureAtomicReader.java    From incubator-retired-blur with Apache License 2.0 6 votes vote down vote up
private NumericDocValues secureNumericDocValues(final NumericDocValues numericDocValues, final ReadType type) {
  if (numericDocValues == null) {
    return null;
  }
  return new NumericDocValues() {

    @Override
    public long get(int docID) {
      try {
        if (_accessControl.hasAccess(type, docID)) {
          return numericDocValues.get(docID);
        }
        return 0L; // Default missing value.
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
  };
}
 
Example #6
Source File: DateFieldWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public boolean write(SortDoc sortDoc, LeafReader reader, MapWriter.EntryWriter ew, int fieldIndex) throws IOException {
  Long val;
  SortValue sortValue = sortDoc.getSortValue(this.field);
  if (sortValue != null) {
    if (sortValue.isPresent()) {
      val = (long) sortValue.getCurrentValue();
    } else { //empty-value
      return false;
    }
  } else {
    // field is not part of 'sort' param, but part of 'fl' param
    NumericDocValues vals = DocValues.getNumeric(reader, this.field);
    if (vals.advance(sortDoc.docId) == sortDoc.docId) {
      val = vals.longValue();
    } else {
      return false;
    }
  }
  ew.put(this.field, new Date(val));
  return true;
}
 
Example #7
Source File: BM25Similarity.java    From lucene4ir with Apache License 2.0 6 votes vote down vote up
private Explanation explainTFNorm(int doc, Explanation freq, BM25Stats stats, NumericDocValues norms) {
  List<Explanation> subs = new ArrayList<>();
  subs.add(freq);
  subs.add(Explanation.match(k1, "parameter k1"));
  if (norms == null) {
    subs.add(Explanation.match(0, "parameter b (norms omitted for field)"));
    return Explanation.match(
        (freq.getValue() * (k1 + 1)) / (freq.getValue() + k1),
        "tfNorm, computed from:", subs);
  } else {
    float doclen = decodeNormValue((byte)norms.get(doc));
    subs.add(Explanation.match(b, "parameter b"));
    subs.add(Explanation.match(stats.avgdl, "avgFieldLength"));
    subs.add(Explanation.match(doclen, "fieldLength"));
    return Explanation.match(
        (freq.getValue() * (k1 + 1)) / (freq.getValue() + k1 * (1 - b + b * doclen/stats.avgdl)),
        "tfNorm, computed from:", subs);
  }
}
 
Example #8
Source File: IntFieldWriter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public boolean write(SortDoc sortDoc, LeafReader reader, MapWriter.EntryWriter ew, int fieldIndex) throws IOException {
  int val;
  SortValue sortValue = sortDoc.getSortValue(this.field);
  if (sortValue != null) {
    if (sortValue.isPresent()) {
      val = (int) sortValue.getCurrentValue();
    } else { //empty-value
      return false;
    }
  } else {
    // field is not part of 'sort' param, but part of 'fl' param
    NumericDocValues vals = DocValues.getNumeric(reader, this.field);
    if (vals.advance(sortDoc.docId) == sortDoc.docId) {
      val = (int) vals.longValue();
    } else {
      return false;
    }
  }
  ew.put(this.field, val);
  return true;
}
 
Example #9
Source File: TestSimilarityProvider.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testBasics() throws Exception {
  // sanity check of norms writer
  // TODO: generalize
  NumericDocValues fooNorms = MultiDocValues.getNormValues(reader, "foo");
  NumericDocValues barNorms = MultiDocValues.getNormValues(reader, "bar");
  for (int i = 0; i < reader.maxDoc(); i++) {
    assertEquals(i, fooNorms.nextDoc());
    assertEquals(i, barNorms.nextDoc());
    assertFalse(fooNorms.longValue() == barNorms.longValue());
  }

  // sanity check of searching
  TopDocs foodocs = searcher.search(new TermQuery(new Term("foo", "brown")), 10);
  assertTrue(foodocs.totalHits.value > 0);
  TopDocs bardocs = searcher.search(new TermQuery(new Term("bar", "brown")), 10);
  assertTrue(bardocs.totalHits.value > 0);
  assertTrue(foodocs.scoreDocs[0].score < bardocs.scoreDocs[0].score);
}
 
Example #10
Source File: ToParentBlockJoinSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private FieldComparator<?> getDoubleComparator(int numHits) {
  return new FieldComparator.DoubleComparator(numHits, getField(), (Double) missingValue) {
    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      SortedNumericDocValues sortedNumeric = DocValues.getSortedNumeric(context.reader(), field);
      final BlockJoinSelector.Type type = order
          ? BlockJoinSelector.Type.MAX
          : BlockJoinSelector.Type.MIN;
      final BitSet parents = parentFilter.getBitSet(context);
      final BitSet children = childFilter.getBitSet(context);
      if (children == null) {
        return DocValues.emptyNumeric();
      }
      return new FilterNumericDocValues(BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children))) {
        @Override
        public long longValue() throws IOException {
          // undo the numericutils sortability
          return NumericUtils.sortableDoubleBits(super.longValue());
        }
      };
    }
  };
}
 
Example #11
Source File: ToParentBlockJoinSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private FieldComparator<?> getFloatComparator(int numHits) {
  return new FieldComparator.FloatComparator(numHits, getField(), (Float) missingValue) {
    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      SortedNumericDocValues sortedNumeric = DocValues.getSortedNumeric(context.reader(), field);
      final BlockJoinSelector.Type type = order
          ? BlockJoinSelector.Type.MAX
          : BlockJoinSelector.Type.MIN;
      final BitSet parents = parentFilter.getBitSet(context);
      final BitSet children = childFilter.getBitSet(context);
      if (children == null) {
        return DocValues.emptyNumeric();
      }
      return new FilterNumericDocValues(BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children))) {
        @Override
        public long longValue() throws IOException {
          // undo the numericutils sortability
          return NumericUtils.sortableFloatBits((int) super.longValue());
        }
      };
    }
  };
}
 
Example #12
Source File: ToParentBlockJoinSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private FieldComparator<?> getLongComparator(int numHits) {
  return new FieldComparator.LongComparator(numHits, getField(), (Long) missingValue) {
    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      SortedNumericDocValues sortedNumeric = DocValues.getSortedNumeric(context.reader(), field);
      final BlockJoinSelector.Type type = order
          ? BlockJoinSelector.Type.MAX
          : BlockJoinSelector.Type.MIN;
      final BitSet parents = parentFilter.getBitSet(context);
      final BitSet children = childFilter.getBitSet(context);
      if (children == null) {
        return DocValues.emptyNumeric();
      }
      return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children));
    }
  };
}
 
Example #13
Source File: ToParentBlockJoinSortField.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private FieldComparator<?> getIntComparator(int numHits) {
  return new FieldComparator.IntComparator(numHits, getField(), (Integer) missingValue) {
    @Override
    protected NumericDocValues getNumericDocValues(LeafReaderContext context, String field) throws IOException {
      SortedNumericDocValues sortedNumeric = DocValues.getSortedNumeric(context.reader(), field);
      final BlockJoinSelector.Type type = order
          ? BlockJoinSelector.Type.MAX
          : BlockJoinSelector.Type.MIN;
      final BitSet parents = parentFilter.getBitSet(context);
      final BitSet children = childFilter.getBitSet(context);
      if (children == null) {
        return DocValues.emptyNumeric();
      }
      return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children));
    }
  };
}
 
Example #14
Source File: LatLonPointDistanceFeatureQuery.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
protected DistanceScorer(Weight weight, int maxDoc, long leadCost, float boost,
    PointValues pointValues, NumericDocValues docValues) {
  super(weight);
  this.maxDoc = maxDoc;
  this.leadCost = leadCost;
  this.boost = boost;
  this.pointValues = pointValues;
  this.docValues = docValues;
  // initially use doc values in order to iterate all documents that have
  // a value for this field
  this.it = docValues;
}
 
Example #15
Source File: BBoxValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public ShapeValues getValues(LeafReaderContext readerContext) throws IOException {
  LeafReader reader = readerContext.reader();
  final NumericDocValues minX = DocValues.getNumeric(reader, strategy.field_minX);
  final NumericDocValues minY = DocValues.getNumeric(reader, strategy.field_minY);
  final NumericDocValues maxX = DocValues.getNumeric(reader, strategy.field_maxX);
  final NumericDocValues maxY = DocValues.getNumeric(reader, strategy.field_maxY);

  //reused
  final Rectangle rect = strategy.getSpatialContext().getShapeFactory().rect(0,0,0,0);

  return new ShapeValues() {

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return minX.advanceExact(doc) && minY.advanceExact(doc) && maxX.advanceExact(doc) && maxY.advanceExact(doc);
    }

    @Override
    public Shape value() throws IOException {
      double minXValue = Double.longBitsToDouble(minX.longValue());
      double minYValue = Double.longBitsToDouble(minY.longValue());
      double maxXValue = Double.longBitsToDouble(maxX.longValue());
      double maxYValue = Double.longBitsToDouble(maxY.longValue());
      rect.reset(minXValue, maxXValue, minYValue, maxYValue);
      return rect;
    }

  };
}
 
Example #16
Source File: TestLegacyFieldCache.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNonIndexedFields() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new StoredField("bogusbytes", "bogus"));
  doc.add(new StoredField("bogusshorts", "bogus"));
  doc.add(new StoredField("bogusints", "bogus"));
  doc.add(new StoredField("boguslongs", "bogus"));
  doc.add(new StoredField("bogusfloats", "bogus"));
  doc.add(new StoredField("bogusdoubles", "bogus"));
  doc.add(new StoredField("bogusbits", "bogus"));
  iw.addDocument(doc);
  DirectoryReader ir = iw.getReader();
  iw.close();
  
  LeafReader ar = getOnlyLeafReader(ir);
  
  final FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();
  assertEquals(0, cache.getCacheEntries().length);
  
  NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.LEGACY_INT_PARSER);
  assertEquals(NO_MORE_DOCS, ints.nextDoc());
  
  NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.LEGACY_LONG_PARSER);
  assertEquals(NO_MORE_DOCS, longs.nextDoc());
  
  NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.LEGACY_FLOAT_PARSER);
  assertEquals(NO_MORE_DOCS, floats.nextDoc());
  
  NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.LEGACY_DOUBLE_PARSER);
  assertEquals(NO_MORE_DOCS, doubles.nextDoc());
  
  // check that we cached nothing
  assertEquals(0, cache.getCacheEntries().length);
  ir.close();
  dir.close();
}
 
Example #17
Source File: DoubleValuesSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
  final NumericDocValues values = DocValues.getNumeric(ctx.reader(), field);
  return new DoubleValues() {
    @Override
    public double doubleValue() throws IOException {
      return decoder.applyAsDouble(values.longValue());
    }

    @Override
    public boolean advanceExact(int target) throws IOException {
      return values.advanceExact(target);
    }
  };
}
 
Example #18
Source File: DistanceValueSource.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the FunctionValues used by the function query.
 */
@Override
public DoubleValues getValues(LeafReaderContext readerContext, DoubleValues scores) throws IOException {
  LeafReader reader = readerContext.reader();

  final NumericDocValues ptX = DocValues.getNumeric(reader, strategy.getFieldNameX());
  final NumericDocValues ptY = DocValues.getNumeric(reader, strategy.getFieldNameY());

  return DoubleValues.withDefault(new DoubleValues() {

    private final Point from = DistanceValueSource.this.from;
    private final DistanceCalculator calculator = strategy.getSpatialContext().getDistCalc();

    @Override
    public double doubleValue() throws IOException {
      double x = Double.longBitsToDouble(ptX.longValue());
      double y = Double.longBitsToDouble(ptY.longValue());
      return calculator.distance(from, x, y) * multiplier;
    }

    @Override
    public boolean advanceExact(int doc) throws IOException {
      return ptX.advanceExact(doc) && ptY.advanceExact(doc);
    }

  }, nullValue);
}
 
Example #19
Source File: TestLegacyFieldCache.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testNonexistantFields() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  iw.addDocument(doc);
  DirectoryReader ir = iw.getReader();
  iw.close();
  
  LeafReader ar = getOnlyLeafReader(ir);
  
  final FieldCache cache = FieldCache.DEFAULT;
  cache.purgeAllCaches();
  assertEquals(0, cache.getCacheEntries().length);
  
  NumericDocValues ints = cache.getNumerics(ar, "bogusints", FieldCache.LEGACY_INT_PARSER);
  assertEquals(NO_MORE_DOCS, ints.nextDoc());
  
  NumericDocValues longs = cache.getNumerics(ar, "boguslongs", FieldCache.LEGACY_LONG_PARSER);
  assertEquals(NO_MORE_DOCS, longs.nextDoc());
  
  NumericDocValues floats = cache.getNumerics(ar, "bogusfloats", FieldCache.LEGACY_FLOAT_PARSER);
  assertEquals(NO_MORE_DOCS, floats.nextDoc());
  
  NumericDocValues doubles = cache.getNumerics(ar, "bogusdoubles", FieldCache.LEGACY_DOUBLE_PARSER);
  assertEquals(NO_MORE_DOCS, doubles.nextDoc());
  
  // check that we cached nothing
  assertEquals(0, cache.getCacheEntries().length);
  ir.close();
  dir.close();
}
 
Example #20
Source File: BM25Similarity.java    From lucene4ir with Apache License 2.0 5 votes vote down vote up
private Explanation explainScore(int doc, Explanation freq, BM25Stats stats, NumericDocValues norms) {
  Explanation boostExpl = Explanation.match(stats.boost, "boost");
  List<Explanation> subs = new ArrayList<>();
  if (boostExpl.getValue() != 1.0f)
    subs.add(boostExpl);
  subs.add(stats.idf);
  Explanation tfNormExpl = explainTFNorm(doc, freq, stats, norms);
  subs.add(tfNormExpl);
  return Explanation.match(
      boostExpl.getValue() * stats.idf.getValue() * tfNormExpl.getValue(),
      "score(doc="+doc+",freq="+freq+"), product of:", subs);
}
 
Example #21
Source File: MultiNormsLeafSimScorer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Sole constructor: Score documents of {@code reader} with {@code scorer}.
 *
 */
MultiNormsLeafSimScorer(SimScorer scorer, LeafReader reader, Collection<FieldAndWeight> normFields, boolean needsScores) throws IOException {
  this.scorer = Objects.requireNonNull(scorer);
  if (needsScores) {
    final List<NumericDocValues> normsList = new ArrayList<>();
    final List<Float> weightList = new ArrayList<>();
    for (FieldAndWeight field : normFields) {
      NumericDocValues norms = reader.getNormValues(field.field);
      if (norms != null) {
        normsList.add(norms);
        weightList.add(field.weight);
      }
    }
    if (normsList.isEmpty()) {
      norms = null;
    } else if (normsList.size() == 1) {
      norms = normsList.get(0);
    } else {
      final NumericDocValues[] normsArr = normsList.toArray(new NumericDocValues[0]);
      final float[] weightArr = new float[normsList.size()];
      for (int i = 0; i < weightList.size(); i++) {
        weightArr[i] = weightList.get(i);
      }
      norms = new MultiFieldNormValues(normsArr, weightArr);
    }
  } else {
    norms = null;
  }
}
 
Example #22
Source File: RecoverySourcePruneMergePolicyTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testPruneNone() throws IOException {
    try (Directory dir = newDirectory()) {
        IndexWriterConfig iwc = newIndexWriterConfig();
        iwc.setMergePolicy(new RecoverySourcePruneMergePolicy("extra_source",
                                                              () -> new MatchAllDocsQuery(), iwc.getMergePolicy()));
        try (IndexWriter writer = new IndexWriter(dir, iwc)) {
            for (int i = 0; i < 20; i++) {
                if (i > 0 && randomBoolean()) {
                    writer.flush();
                }
                Document doc = new Document();
                doc.add(new StoredField("source", "hello world"));
                doc.add(new StoredField("extra_source", "hello world"));
                doc.add(new NumericDocValuesField("extra_source", 1));
                writer.addDocument(doc);
            }
            writer.forceMerge(1);
            writer.commit();
            try (DirectoryReader reader = DirectoryReader.open(writer)) {
                assertEquals(1, reader.leaves().size());
                NumericDocValues extra_source = reader.leaves().get(0).reader().getNumericDocValues("extra_source");
                assertNotNull(extra_source);
                for (int i = 0; i < reader.maxDoc(); i++) {
                    Document document = reader.document(i);
                    Set<String> collect = document.getFields().stream().map(IndexableField::name).collect(Collectors.toSet());
                    assertTrue(collect.contains("source"));
                    assertTrue(collect.contains("extra_source"));
                    assertEquals(i, extra_source.nextDoc());
                }
                assertEquals(DocIdSetIterator.NO_MORE_DOCS, extra_source.nextDoc());
            }
        }
    }
}
 
Example #23
Source File: UninvertingReader.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public NumericDocValues getNumericDocValues(String field) throws IOException {
  NumericDocValues values = super.getNumericDocValues(field);
  if (values != null) {
    return values;
  }
  Type v = getType(field);
  if (v != null) {
    switch (v) {
      case INTEGER_POINT: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.INT_POINT_PARSER);
      case FLOAT_POINT: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.FLOAT_POINT_PARSER);
      case LONG_POINT: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.LONG_POINT_PARSER);
      case DOUBLE_POINT: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.DOUBLE_POINT_PARSER);
      case LEGACY_INTEGER: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.LEGACY_INT_PARSER);
      case LEGACY_FLOAT: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.LEGACY_FLOAT_PARSER);
      case LEGACY_LONG: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.LEGACY_LONG_PARSER);
      case LEGACY_DOUBLE: return FieldCache.DEFAULT.getNumerics(in, field, FieldCache.LEGACY_DOUBLE_PARSER);
      case BINARY:
      case SORTED:
      case SORTED_SET_BINARY:
      case SORTED_SET_DOUBLE:
      case SORTED_SET_FLOAT:
      case SORTED_SET_INTEGER:
      case SORTED_SET_LONG:
        break;
    }
  }
  return null;
}
 
Example #24
Source File: NumericDoubleValues.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/** Returns numeric docvalues view of raw double bits */
public NumericDocValues getRawDoubleValues() {
    return new NumericDocValues() {
      @Override
      public long get(int docID) {
          return Double.doubleToRawLongBits(NumericDoubleValues.this.get(docID));
      }
    };
}
 
Example #25
Source File: Insanity.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public NumericDocValues getNumericDocValues(String field) throws IOException {
  if (insaneField.equals(field)) {
    return null;
  } else {
    return in.getNumericDocValues(field);
  }
}
 
Example #26
Source File: EngineTestCase.java    From crate with Apache License 2.0 5 votes vote down vote up
static long maxSeqNosInReader(DirectoryReader reader) throws IOException {
    long maxSeqNo = SequenceNumbers.NO_OPS_PERFORMED;
    for (LeafReaderContext leaf : reader.leaves()) {
        final NumericDocValues seqNoDocValues = leaf.reader().getNumericDocValues(SeqNoFieldMapper.NAME);
        while (seqNoDocValues.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
            maxSeqNo = SequenceNumbers.max(maxSeqNo, seqNoDocValues.longValue());
        }
    }
    return maxSeqNo;
}
 
Example #27
Source File: DiversifiedMapSamplerAggregator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected NumericDocValues getKeys(LeafReaderContext context) {
    try {
        values = valuesSource.bytesValues(context);
    } catch (IOException e) {
        throw new ElasticsearchException("Error reading values", e);
    }
    return new NumericDocValues() {
        @Override
        public long get(int doc) {

            values.setDocument(doc);
            final int valuesCount = values.count();
            if (valuesCount > 1) {
                throw new IllegalArgumentException("Sample diversifying key must be a single valued-field");
            }
            if (valuesCount == 1) {
                final BytesRef bytes = values.valueAt(0);

                long bucketOrdinal = bucketOrds.add(bytes);
                if (bucketOrdinal < 0) { // already seen
                    bucketOrdinal = -1 - bucketOrdinal;
                }
                return bucketOrdinal;
            }
            return 0;
        }
    };
}
 
Example #28
Source File: LongValueFacetCounts.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void countOneSegment(NumericDocValues values, MatchingDocs hits) throws IOException {
  DocIdSetIterator it = ConjunctionDISI.intersectIterators(
                           Arrays.asList(hits.bits.iterator(), values));

  for (int doc = it.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = it.nextDoc()) {
    increment(values.longValue());
    totCount++;
  }
}
 
Example #29
Source File: LongValueFacetCounts.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Optimized version that directly counts all doc values. */
private void countAll(IndexReader reader, String field) throws IOException {

  for (LeafReaderContext context : reader.leaves()) {

    NumericDocValues values = context.reader().getNumericDocValues(field);
    if (values == null) {
      // this field has no doc values for this segment
      continue;
    }

    countAllOneSegment(values);
  }
}
 
Example #30
Source File: BlockJoinSelector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/** Wraps the provided {@link SortedNumericDocValues} in order to only select
 *  one value per parent among its {@code children} using the configured
 *  {@code selection} type. */
public static NumericDocValues wrap(SortedNumericDocValues sortedNumerics, Type selection, BitSet parents, DocIdSetIterator children) {
  NumericDocValues values;
  switch (selection) {
    case MIN:
      values = SortedNumericSelector.wrap(sortedNumerics, SortedNumericSelector.Type.MIN, SortField.Type.LONG);
      break;
    case MAX:
      values = SortedNumericSelector.wrap(sortedNumerics, SortedNumericSelector.Type.MAX, SortField.Type.LONG);
      break;
    default:
      throw new AssertionError();
  }
  return wrap(values, selection, parents, children);
}