Java Code Examples for org.apache.lucene.index.SortedSetDocValues#NO_MORE_ORDS

The following examples show how to use org.apache.lucene.index.SortedSetDocValues#NO_MORE_ORDS . 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: TermsWithScoreCollector.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  if (docValues.advanceExact(doc)) {
    long ord;
    while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      int termID = collectedTerms.add(docValues.lookupOrd(ord));
      if (termID < 0) {
        termID = -termID - 1;
      } else {
        if (termID >= scoreSums.length) {
          scoreSums = ArrayUtil.grow(scoreSums);
          scoreCounts = ArrayUtil.grow(scoreCounts);
        }
      }
    
      scoreSums[termID] += scorer.score();
      scoreCounts[termID]++;
    }
  }
}
 
Example 2
Source File: IpColumnReference.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public String value() {
    try {
        if (values.advanceExact(docId)) {
            long ord = values.nextOrd();
            if (values.nextOrd() != SortedSetDocValues.NO_MORE_ORDS) {
                throw new GroupByOnArrayUnsupportedException(columnName);
            }
            BytesRef encoded = values.lookupOrd(ord);
            return (String) DocValueFormat.IP.format(encoded);
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 3
Source File: GraphEdgeCollector.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
void addEdgeIdsToResult(int doc) throws IOException {
  // set the doc to pull the edges ids for.
  if (doc > docTermOrds.docID()) {
    docTermOrds.advance(doc);
  }
  if (doc == docTermOrds.docID()) {
    BytesRef edgeValue = new BytesRef();
    long ord;
    while ((ord = docTermOrds.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      edgeValue = docTermOrds.lookupOrd(ord);
      // add the edge id to the collector terms.
      collectorTerms.add(edgeValue);
    }
  }
}
 
Example 4
Source File: DocValuesAdapter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Optional<DocValues> createSortedSetDocValues(int docid, String field, DocValuesType dvType)
    throws IOException {
  SortedSetDocValues ssvalues = IndexUtils.getSortedSetDocvalues(reader, field);

  if (ssvalues.advanceExact(docid)) {
    List<BytesRef> values = new ArrayList<>();

    long ord;
    while ((ord = ssvalues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      values.add(BytesRef.deepCopyOf(ssvalues.lookupOrd(ord)));
    }

    DocValues dv = DocValues.of(
        dvType,
        values,
        Collections.emptyList()
    );
    return Optional.of(dv);
  }

  return Optional.empty();
}
 
Example 5
Source File: LongMultiTrieField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  count = 0;
  if (docValues.advanceExact(doc)) {
    int term;
    while ((term = (int)docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      if (count == values.length) {
        resizeValues();
      }
      values[count++] = LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term));
    }
  }
}
 
Example 6
Source File: PercentileAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  AVLTreeDigest digest = digests[slot];
  if (digest == null) {
    digests[slot] = digest = new AVLTreeDigest(100);
  }
  long ord;
  while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef term = values.lookupOrd(ord);
    Object obj = sf.getType().toObject(sf, term);
    double val = obj instanceof Date ? ((Date)obj).getTime(): ((Number)obj).doubleValue();
    digest.add(val);
  }
}
 
Example 7
Source File: SumsqAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  long ord;
  while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef term = values.lookupOrd(ord);
    Object obj = sf.getType().toObject(sf, term);
    double val = obj instanceof Date ? ((Date)obj).getTime(): ((Number)obj).doubleValue();
    result[slot] += val * val;
  }
}
 
Example 8
Source File: DocValuesAcc.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  long ord;
  while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef term = values.lookupOrd(ord);
    Object obj = sf.getType().toObject(sf, term);
    double val = obj instanceof Date ? ((Date) obj).getTime() : ((Number) obj).doubleValue();
    result[slot] += val * val;
    sum[slot] += val;
    counts[slot]++;
  }
}
 
Example 9
Source File: AvgAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  long ord;
  while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef term = values.lookupOrd(ord);
    Object obj = sf.getType().toObject(sf, term);
    double val = obj instanceof Date ? ((Date)obj).getTime(): ((Number)obj).doubleValue();
    result[slot] += val;
    counts[slot]++;
  }
}
 
Example 10
Source File: SumAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  long ord;
  while ((ord = values.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef term = values.lookupOrd(ord);
    Object obj = sf.getType().toObject(sf, term);
    double val = obj instanceof Date? ((Date)obj).getTime(): ((Number)obj).doubleValue();
    result[slot] += val;
  }
}
 
Example 11
Source File: DoubleMultiTrieField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  count = 0;
  if (docValues.advanceExact(doc)) {
    int term;
    while ((term = (int)docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      if (count == values.length) {
        resizeValues();
      }
      values[count++] = NumericUtils.sortableLongToDouble(LegacyNumericUtils.prefixCodedToLong(docValues.lookupOrd(term)));
    }
  }
}
 
Example 12
Source File: FloatMultiTrieField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  count = 0;
  if (docValues.advanceExact(doc)) {
    int term;
    while ((term = (int)docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      if (count == values.length) {
        resizeValues();
      }
      values[count++] = NumericUtils.sortableIntToFloat(LegacyNumericUtils.prefixCodedToInt(docValues.lookupOrd(term)));
    }
  }
}
 
Example 13
Source File: MultiValueTermOrdinalCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  final int globalDoc = docBase + doc;

  if (topLevelDocValues.advanceExact(globalDoc)) {
    long ord = SortedSetDocValues.NO_MORE_ORDS;
    while ((ord = topLevelDocValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      topLevelDocValuesBitSet.set(ord);
    }
  }
}
 
Example 14
Source File: StringMultiField.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  values.clear();
  if (docValues.advanceExact(doc)) {
    int term;
    while ((term = (int)docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      values.add(docValues.lookupOrd(term).utf8ToString());
    }
  }
}
 
Example 15
Source File: TermsWithScoreCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  if (docValues.advanceExact(doc)) {
    long ord;
    while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      int termID = collectedTerms.add(docValues.lookupOrd(ord));
      if (termID < 0) {
        termID = -termID - 1;
      } else {
        if (termID >= scoreSums.length) {
          int begin = scoreSums.length;
          scoreSums = ArrayUtil.grow(scoreSums);
          if (scoreMode == ScoreMode.Min) {
            Arrays.fill(scoreSums, begin, scoreSums.length, Float.POSITIVE_INFINITY);
          } else if (scoreMode == ScoreMode.Max) {
            Arrays.fill(scoreSums, begin, scoreSums.length, Float.NEGATIVE_INFINITY);
          }
        }
      }
    
      switch (scoreMode) {
      case Total:
        scoreSums[termID] += scorer.score();
        break;
      case Min:
        scoreSums[termID] = Math.min(scoreSums[termID], scorer.score());
        break;
      case Max:
        scoreSums[termID] = Math.max(scoreSums[termID], scorer.score());
        break;
      default:
        throw new AssertionError("unexpected: " + scoreMode);
      }
    }
  }
}
 
Example 16
Source File: TermsCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  long ord;
  if (doc > docValues.docID()) {
    docValues.advance(doc);
  }
  if (doc == docValues.docID()) {
    while ((ord = docValues.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      final BytesRef term = docValues.lookupOrd(ord);
      collectorTerms.add(term);
    }
  }
}
 
Example 17
Source File: DocValuesStats.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
protected void doAccumulate(int count) throws IOException {
  long ord;
  while ((ord = ssdv.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
    BytesRef val = ssdv.lookupOrd(ord);
    if (max == null || val.compareTo(max) > 0) {
      max = copyFrom(val, max);
    }
    if (min == null || val.compareTo(min) < 0) {
      min = copyFrom(val, min);
    }
  }
}
 
Example 18
Source File: CountValsAgg.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected void collectValues(int doc, int slot) throws IOException {
  while (values.nextOrd() != SortedSetDocValues.NO_MORE_ORDS) {
    result[slot]++;
  }
}
 
Example 19
Source File: DocValuesTermsQuery.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
  return new ConstantScoreWeight(this, boost) {

    @Override
    public Scorer scorer(LeafReaderContext context) throws IOException {
      final SortedSetDocValues values = DocValues.getSortedSet(context.reader(), field);
      final LongBitSet bits = new LongBitSet(values.getValueCount());
      boolean matchesAtLeastOneTerm = false;
      TermIterator iterator = termData.iterator();
      for (BytesRef term = iterator.next(); term != null; term = iterator.next()) {
        final long ord = values.lookupTerm(term);
        if (ord >= 0) {
          matchesAtLeastOneTerm = true;
          bits.set(ord);
        }
      }
      if (matchesAtLeastOneTerm == false) {
        return null;
      }
      return new ConstantScoreScorer(this, score(), scoreMode, new TwoPhaseIterator(values) {

        @Override
        public boolean matches() throws IOException {
          for (long ord = values.nextOrd(); ord != SortedSetDocValues.NO_MORE_ORDS; ord = values.nextOrd()) {
            if (bits.get(ord)) {
              return true;
            }
          }
          return false;
        }

        @Override
        public float matchCost() {
          return 3; // lookup in a bitset
        }

      });
    }

    @Override
    public boolean isCacheable(LeafReaderContext ctx) {
      return DocValues.isCacheable(ctx, field);
    }

  };
}
 
Example 20
Source File: TermGroupFacetCollector.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
  if (doc > groupFieldTermsIndex.docID()) {
    groupFieldTermsIndex.advance(doc);
  }

  int groupOrd;
  if (doc == groupFieldTermsIndex.docID()) {
    groupOrd = groupFieldTermsIndex.ordValue();
  } else {
    groupOrd = -1;
  }
  
  if (facetFieldNumTerms == 0) {
    int segmentGroupedFacetsIndex = groupOrd * (facetFieldNumTerms + 1);
    if (facetPrefix != null || segmentGroupedFacetHits.exists(segmentGroupedFacetsIndex)) {
      return;
    }

    segmentTotalCount++;
    segmentFacetCounts[facetFieldNumTerms]++;

    segmentGroupedFacetHits.put(segmentGroupedFacetsIndex);
    BytesRef groupKey;
    if (groupOrd == -1) {
      groupKey = null;
    } else {
      groupKey = BytesRef.deepCopyOf(groupFieldTermsIndex.lookupOrd(groupOrd));
    }
    groupedFacetHits.add(new GroupedFacetHit(groupKey, null));
    return;
  }

  if (doc > facetFieldDocTermOrds.docID()) {
    facetFieldDocTermOrds.advance(doc);
  }
  boolean empty = true;
  if (doc == facetFieldDocTermOrds.docID()) {
    long ord;
    while ((ord = facetFieldDocTermOrds.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
      process(groupOrd, (int) ord);
      empty = false;
    }
  }
  
  if (empty) {
    process(groupOrd, facetFieldNumTerms); // this facet ord is reserved for docs not containing facet field.
  }
}