Java Code Examples for org.apache.lucene.codecs.DocValuesProducer#getSorted()

The following examples show how to use org.apache.lucene.codecs.DocValuesProducer#getSorted() . 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: Lucene80DocValuesConsumer.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void doAddSortedField(FieldInfo field, DocValuesProducer valuesProducer) throws IOException {
  SortedDocValues values = valuesProducer.getSorted(field);
  int numDocsWithField = 0;
  for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
    numDocsWithField++;
  }

  if (numDocsWithField == 0) {
    meta.writeLong(-2); // docsWithFieldOffset
    meta.writeLong(0L); // docsWithFieldLength
    meta.writeShort((short) -1); // jumpTableEntryCount
    meta.writeByte((byte) -1);   // denseRankPower
  } else if (numDocsWithField == maxDoc) {
    meta.writeLong(-1); // docsWithFieldOffset
    meta.writeLong(0L); // docsWithFieldLength
    meta.writeShort((short) -1); // jumpTableEntryCount
    meta.writeByte((byte) -1);   // denseRankPower
  } else {
    long offset = data.getFilePointer();
    meta.writeLong(offset); // docsWithFieldOffset
    values = valuesProducer.getSorted(field);
    final short jumpTableentryCount = IndexedDISI.writeBitSet(values, data, IndexedDISI.DEFAULT_DENSE_RANK_POWER);
    meta.writeLong(data.getFilePointer() - offset); // docsWithFieldLength
    meta.writeShort(jumpTableentryCount);
    meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
  }

  meta.writeInt(numDocsWithField);
  if (values.getValueCount() <= 1) {
    meta.writeByte((byte) 0); // bitsPerValue
    meta.writeLong(0L); // ordsOffset
    meta.writeLong(0L); // ordsLength
  } else {
    int numberOfBitsPerOrd = DirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
    meta.writeByte((byte) numberOfBitsPerOrd); // bitsPerValue
    long start = data.getFilePointer();
    meta.writeLong(start); // ordsOffset
    DirectWriter writer = DirectWriter.getInstance(data, numDocsWithField, numberOfBitsPerOrd);
    values = valuesProducer.getSorted(field);
    for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
      writer.add(values.ordValue());
    }
    writer.finish();
    meta.writeLong(data.getFilePointer() - start); // ordsLength
  }

  addTermsDict(DocValues.singleton(valuesProducer.getSorted(field)));
}
 
Example 2
Source File: PerFieldDocValuesFormat.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SortedDocValues getSorted(FieldInfo field) throws IOException {
  DocValuesProducer producer = fields.get(field.name);
  return producer == null ? null : producer.getSorted(field);
}
 
Example 3
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public OrdScoreCollector(int maxDoc,
                         int segments,
                         DocValuesProducer collapseValuesProducer,
                         int nullPolicy,
                         IntIntHashMap boostDocsMap,
                         IndexSearcher searcher) throws IOException {
  this.maxDoc = maxDoc;
  this.contexts = new LeafReaderContext[segments];
  List<LeafReaderContext> con = searcher.getTopReaderContext().leaves();
  for(int i=0; i<con.size(); i++) {
    contexts[i] = con.get(i);
  }

  this.collapsedSet = new FixedBitSet(maxDoc);
  this.collapseValuesProducer = collapseValuesProducer;
  this.collapseValues = collapseValuesProducer.getSorted(null);

  int valueCount = collapseValues.getValueCount();
  if(collapseValues instanceof MultiDocValues.MultiSortedDocValues) {
    this.multiSortedDocValues = (MultiDocValues.MultiSortedDocValues)collapseValues;
    this.ordinalMap = multiSortedDocValues.mapping;
  }
  this.ords = new IntIntDynamicMap(valueCount, -1);
  this.scores = new IntFloatDynamicMap(valueCount, -Float.MAX_VALUE);
  this.nullPolicy = nullPolicy;
  if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
    nullScores = new FloatArrayList();
  }

  if(boostDocsMap != null) {
    this.boosts = true;
    this.boostOrds = new IntArrayList();
    this.boostDocs = new IntArrayList();
    int[] bd = new int[boostDocsMap.size()];
    Iterator<IntIntCursor> it =  boostDocsMap.iterator();
    int index = -1;
    while(it.hasNext()) {
      IntIntCursor cursor = it.next();
      bd[++index] = cursor.key;
    }

    Arrays.sort(bd);
    this.mergeBoost = new MergeBoost(bd);
  }
}