Java Code Examples for org.apache.lucene.index.MultiDocValues#MultiSortedDocValues

The following examples show how to use org.apache.lucene.index.MultiDocValues#MultiSortedDocValues . 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: ExpandComponent.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public GroupExpandCollector(SortedDocValues docValues, FixedBitSet groupBits, IntHashSet collapsedSet, int limit, Sort sort) throws IOException {
  int numGroups = collapsedSet.size();
  groups = new LongObjectHashMap<>(numGroups);
  DocIdSetIterator iterator = new BitSetIterator(groupBits, 0); // cost is not useful here
  int group;
  while ((group = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    groups.put(group, getCollector(limit, sort));
  }

  this.collapsedSet = collapsedSet;
  this.groupBits = groupBits;
  this.docValues = docValues;
  if(docValues instanceof MultiDocValues.MultiSortedDocValues) {
    this.multiSortedDocValues = (MultiDocValues.MultiSortedDocValues)docValues;
    this.ordinalMap = multiSortedDocValues.mapping;
  }
}
 
Example 2
Source File: UniqueSinglevaluedSlotAcc.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void resetIterators() throws IOException {
  super.resetIterators();
  topLevel = FieldUtil.getSortedDocValues(fcontext.qcontext, field, null);
  nTerms = topLevel.getValueCount();
  if (topLevel instanceof MultiDocValues.MultiSortedDocValues) {
    ordMap = ((MultiDocValues.MultiSortedDocValues)topLevel).mapping;
    subDvs = ((MultiDocValues.MultiSortedDocValues)topLevel).values;
  } else {
    ordMap = null;
    subDvs = null;
  }
}
 
Example 3
Source File: MinMaxAgg.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void resetIterators() throws IOException {
  super.resetIterators();
  topLevel = FieldUtil.getSortedDocValues(fcontext.qcontext, field, null);
  if (topLevel instanceof MultiDocValues.MultiSortedDocValues) {
    ordMap = ((MultiDocValues.MultiSortedDocValues)topLevel).mapping;
    subDvs = ((MultiDocValues.MultiSortedDocValues)topLevel).values;
  } else {
    ordMap = null;
    subDvs = null;
  }
}
 
Example 4
Source File: StringValue.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public StringValue(SortedDocValues globalDocValues, String field, IntComp comp)  {
  this.globalDocValues = globalDocValues;
  this.docValues = globalDocValues;
  if (globalDocValues instanceof MultiDocValues.MultiSortedDocValues) {
    this.ordinalMap = ((MultiDocValues.MultiSortedDocValues) globalDocValues).mapping;
  }
  this.field = field;
  this.comp = comp;
  this.currentOrd = comp.resetValue();
  this.present = false;
}
 
Example 5
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);
  }
}
 
Example 6
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public void finish() throws IOException {
  if(contexts.length == 0) {
    return;
  }

  int currentContext = 0;
  int currentDocBase = 0;

  this.collapseValues = collapseValuesProducer.getSorted(null);
  if(collapseValues instanceof MultiDocValues.MultiSortedDocValues) {
    this.multiSortedDocValues = (MultiDocValues.MultiSortedDocValues)collapseValues;
    this.ordinalMap = multiSortedDocValues.mapping;
  }
  if(ordinalMap != null) {
    this.segmentValues = this.multiSortedDocValues.values[currentContext];
    this.segmentOrdinalMap = this.ordinalMap.getGlobalOrds(currentContext);
  } else {
    this.segmentValues = collapseValues;
  }

  int nextDocBase = currentContext+1 < contexts.length ? contexts[currentContext+1].docBase : maxDoc;
  leafDelegate = delegate.getLeafCollector(contexts[currentContext]);
  ScoreAndDoc dummy = new ScoreAndDoc();
  leafDelegate.setScorer(dummy);
  DocIdSetIterator it = new BitSetIterator(collapseStrategy.getCollapsedSet(), 0); // cost is not useful here
  int globalDoc = -1;
  int nullScoreIndex = 0;
  IntFloatDynamicMap scores = collapseStrategy.getScores();
  FloatArrayList nullScores = collapseStrategy.getNullScores();
  float nullScore = collapseStrategy.getNullScore();

  MergeBoost mergeBoost = collapseStrategy.getMergeBoost();
  while((globalDoc = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {


    while(globalDoc >= nextDocBase) {
      currentContext++;
      currentDocBase = contexts[currentContext].docBase;
      nextDocBase = currentContext+1 < contexts.length ? contexts[currentContext+1].docBase : maxDoc;
      leafDelegate = delegate.getLeafCollector(contexts[currentContext]);
      leafDelegate.setScorer(dummy);
      if(ordinalMap != null) {
        this.segmentValues = this.multiSortedDocValues.values[currentContext];
        this.segmentOrdinalMap = this.ordinalMap.getGlobalOrds(currentContext);
      }
    }

    int contextDoc = globalDoc-currentDocBase;

    if(this.needsScores){
      int ord = -1;
      if(this.ordinalMap != null) {
        //Handle ordinalMapping case
        if (segmentValues.advanceExact(contextDoc)) {
          ord = (int) segmentOrdinalMap.get(segmentValues.ordValue());
        }
      } else {
        //Handle top Level FieldCache or Single Segment Case
        if (segmentValues.advanceExact(globalDoc)) {
          ord = segmentValues.ordValue();
        }
      }

      if(ord > -1) {
        dummy.score = scores.get(ord);
      } else if (mergeBoost != null && mergeBoost.boost(globalDoc)) {
        //It's an elevated doc so no score is needed
        dummy.score = 0F;
      } else if (nullPolicy == CollapsingPostFilter.NULL_POLICY_COLLAPSE) {
        dummy.score = nullScore;
      } else if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
        dummy.score = nullScores.get(nullScoreIndex++);
      }
    }

    dummy.docId = contextDoc;
    leafDelegate.collect(contextDoc);
  }

  if(delegate instanceof DelegatingCollector) {
    ((DelegatingCollector) delegate).finish();
  }
}