com.carrotsearch.hppc.IntIntHashMap Java Examples

The following examples show how to use com.carrotsearch.hppc.IntIntHashMap. 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: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public IntFloatStrategy(int maxDoc,
                        int size,
                        String collapseField,
                        int nullValue,
                        int nullPolicy,
                        GroupHeadSelector groupHeadSelector,
                        boolean needsScores,
                        IntIntHashMap boostDocs) throws IOException {

  super(maxDoc, size, collapseField, nullValue, nullPolicy, needsScores, boostDocs);
  this.field = groupHeadSelector.selectorText;
  this.testValues = new IntFloatDynamicMap(size, 0.0f);

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxFloatComp();
    this.nullCompVal = -Float.MAX_VALUE;
  } else {
    comp = new MinFloatComp();
    this.nullCompVal = Float.MAX_VALUE;
  }
}
 
Example #2
Source File: CFSA2Serializer.java    From morfologik-stemming with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Compute in-link count for each state.
 */
private IntIntHashMap computeInlinkCount(final FSA fsa) {
  IntIntHashMap inlinkCount = new IntIntHashMap();
  BitSet visited = new BitSet();
  IntStack nodes = new IntStack();
  nodes.push(fsa.getRootNode());

  while (!nodes.isEmpty()) {
    final int node = nodes.pop();
    if (visited.get(node))
      continue;

    visited.set(node);

    for (int arc = fsa.getFirstArc(node); arc != 0; arc = fsa.getNextArc(arc)) {
      if (!fsa.isArcTerminal(arc)) {
        final int target = fsa.getEndNode(arc);
        inlinkCount.putOrAdd(target, 1, 1);
        if (!visited.get(target))
          nodes.push(target);
      }
    }
  }

  return inlinkCount;
}
 
Example #3
Source File: FSAUtils.java    From morfologik-stemming with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Calculate the size of "right language" for each state in an FSA. The right
 * language is the number of sequences encoded from a given node in the automaton.
 * 
 * @param fsa The automaton to calculate right language for.
 * @return Returns a map with node identifiers as keys and their right language
 * counts as associated values. 
 */
public static IntIntHashMap rightLanguageForAllStates(final FSA fsa) {
  final IntIntHashMap numbers = new IntIntHashMap();

  fsa.visitInPostOrder(new StateVisitor() {
    public boolean accept(int state) {
      int thisNodeNumber = 0;
      for (int arc = fsa.getFirstArc(state); arc != 0; arc = fsa.getNextArc(arc)) {
        thisNodeNumber += (fsa.isArcFinal(arc) ? 1 : 0)
            + (fsa.isArcTerminal(arc) ? 0 : numbers.get(fsa.getEndNode(arc)));
      }
      numbers.put(state, thisNodeNumber);

      return true;
    }
  });

  return numbers;
}
 
Example #4
Source File: DependencyStructure.java    From EasySRL with Apache License 2.0 6 votes vote down vote up
private static void normalize(final Collection<UnresolvedDependency> unresolvedDependencies,
		final IntIntHashMap substitutions, final Set<UnresolvedDependency> newUnresolvedDependencies,
		final Collection<UnlabelledDependency> newResolvedDependencies) {
	for (final UnresolvedDependency dep : unresolvedDependencies) {
		final int newID = substitutions.getOrDefault(dep.argumentID, Integer.MIN_VALUE);
		if (newID != Integer.MIN_VALUE) {
			if (newID == dep.argumentID) {
				newUnresolvedDependencies.add(dep);
			} else {
				newUnresolvedDependencies.add(new UnresolvedDependency(dep.getHead(), dep.getCategory(), dep.getArgNumber(),
						newID, dep.getPreposition()));
			}
		} else {
			// Dependencies that don't get any attachment (e.g. in arbitrary control).
			newResolvedDependencies.add(new UnlabelledDependency(dep.getHead(), dep.getCategory(), dep.getArgNumber(),
					Collections.singletonList(dep.getHead()), dep.getPreposition()));
		}
	}
}
 
Example #5
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public IntSortSpecStrategy(int maxDoc,
                           int size,
                           String collapseField,
                           int nullValue,
                           int nullPolicy,
                           GroupHeadSelector groupHeadSelector,
                           boolean needsScores4Collapsing,
                           boolean needsScores,
                           IntIntHashMap boostDocs,
                           SortSpec sortSpec,
                           IndexSearcher searcher) throws IOException {

  super(maxDoc, size, collapseField, nullValue, nullPolicy, needsScores, boostDocs);
  this.needsScores4Collapsing = needsScores4Collapsing;

  assert GroupHeadSelectorType.SORT.equals(groupHeadSelector.type);

  this.sortSpec = sortSpec;
  this.sort = rewriteSort(sortSpec, searcher);
  this.compareState = new SortFieldsCompare(sort.getSort(), size);
}
 
Example #6
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public IntIntStrategy(int maxDoc,
                      int size,
                      String collapseField,
                      int nullValue,
                      int nullPolicy,
                      GroupHeadSelector groupHeadSelector,
                      boolean needsScores,
                      IntIntHashMap boostDocs) throws IOException {

  super(maxDoc, size, collapseField, nullValue, nullPolicy, needsScores, boostDocs);
  this.field = groupHeadSelector.selectorText;
  this.testValues = new IntIntDynamicMap(size, 0);

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxIntComp();
    this.nullCompVal = Integer.MIN_VALUE;
  } else {
    comp = new MinIntComp();
    this.nullCompVal = Integer.MAX_VALUE;
  }
}
 
Example #7
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public OrdSortSpecStrategy(int maxDoc,
                           int nullPolicy,
                           int valueCount,
                           GroupHeadSelector groupHeadSelector,
                           boolean needsScores4Collapsing,
                           boolean needsScores,
                           IntIntHashMap boostDocs,
                           SortSpec sortSpec,
                           IndexSearcher searcher,
                           SortedDocValues values) throws IOException {
  super(maxDoc, valueCount, nullPolicy, needsScores, boostDocs, values);
  this.needsScores4Collapsing = needsScores4Collapsing;

  assert GroupHeadSelectorType.SORT.equals(groupHeadSelector.type);

  this.sort = rewriteSort(sortSpec, searcher);

  this.compareState = new SortFieldsCompare(sort.getSort(), valueCount);
}
 
Example #8
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public OrdLongStrategy(int maxDoc,
                       int nullPolicy,
                       int valueCount,
                       GroupHeadSelector groupHeadSelector,
                       boolean needsScores,
                       IntIntHashMap boostDocs, SortedDocValues values) throws IOException {
  super(maxDoc, valueCount, nullPolicy, needsScores, boostDocs, values);
  this.field = groupHeadSelector.selectorText;

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxLongComp();
    this.ordVals = new IntLongDynamicMap(valueCount, Long.MIN_VALUE);
  } else {
    this.nullVal = Long.MAX_VALUE;
    comp = new MinLongComp();
    this.ordVals = new IntLongDynamicMap(valueCount, Long.MAX_VALUE);
  }
}
 
Example #9
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public OrdFloatStrategy(int maxDoc,
                        int nullPolicy,
                        int valueCount,
                        GroupHeadSelector groupHeadSelector,
                        boolean needsScores,
                        IntIntHashMap boostDocs,
                        SortedDocValues values) throws IOException {
  super(maxDoc, valueCount, nullPolicy, needsScores, boostDocs, values);
  this.field = groupHeadSelector.selectorText;

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxFloatComp();
    this.ordVals = new IntFloatDynamicMap(valueCount, -Float.MAX_VALUE);
    this.nullVal = -Float.MAX_VALUE;
  } else {
    comp = new MinFloatComp();
    this.ordVals = new IntFloatDynamicMap(valueCount, Float.MAX_VALUE);
    this.nullVal = Float.MAX_VALUE;
  }
}
 
Example #10
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public OrdIntStrategy(int maxDoc,
                      int nullPolicy,
                      int valueCount,
                      GroupHeadSelector groupHeadSelector,
                      boolean needsScores,
                      IntIntHashMap boostDocs,
                      SortedDocValues values) throws IOException {
  super(maxDoc, valueCount, nullPolicy, needsScores, boostDocs, values);
  this.field = groupHeadSelector.selectorText;

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxIntComp();
    this.ordVals = new IntIntDynamicMap(valueCount, Integer.MIN_VALUE);
  } else {
    comp = new MinIntComp();
    this.ordVals = new IntIntDynamicMap(valueCount, Integer.MAX_VALUE);
    this.nullVal = Integer.MAX_VALUE;
  }
}
 
Example #11
Source File: PrelUtil.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public ProjectPushInfo(List<SchemaPath> columns, ImmutableList<DesiredField> desiredFields, ImmutableList<RexNode> inputRefs) {
  super();
  this.columns = columns;
  this.desiredFields = desiredFields;
  this.inputsRefs = inputRefs;

  this.fieldNames = Lists.newArrayListWithCapacity(desiredFields.size());
  this.types = Lists.newArrayListWithCapacity(desiredFields.size());
  IntIntHashMap oldToNewIds = new IntIntHashMap();

  int i =0;
  for (DesiredField f : desiredFields) {
    fieldNames.add(f.name);
    types.add(f.field.getType());
    oldToNewIds.put(f.origIndex, i);
    i++;
  }
  this.rewriter = new InputRewriter(oldToNewIds);
}
 
Example #12
Source File: QueryElevationComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static IntIntHashMap getBoostDocs(SolrIndexSearcher indexSearcher, Set<BytesRef> boosted,
                                         @SuppressWarnings({"rawtypes"})Map context) throws IOException {

  IntIntHashMap boostDocs = null;

  if (boosted != null) {

    //First see if it's already in the request context. Could have been put there by another caller.
    if (context != null) {
      boostDocs = (IntIntHashMap) context.get(BOOSTED_DOCIDS);
      if (boostDocs != null) {
        return boostDocs;
      }
    }

    //Not in the context yet so load it.
    boostDocs = new IntIntHashMap(boosted.size()); // docId to boost
    int priority = boosted.size() + 1; // the corresponding priority for each boosted key (starts at this; decrements down)
    for (BytesRef uniqueKey : boosted) {
      priority--; // therefore first == bosted.size(); last will be 1
      long segAndId = indexSearcher.lookupId(uniqueKey); // higher 32 bits == segment ID, low 32 bits == doc ID
      if (segAndId == -1) { // not found
        continue;
      }
      int seg = (int) (segAndId >> 32);
      int localDocId = (int) segAndId;
      final IndexReaderContext indexReaderContext = indexSearcher.getTopReaderContext().children().get(seg);
      int docId = indexReaderContext.docBaseInParent + localDocId;
      boostDocs.put(docId, priority);
    }
    assert priority == 1; // the last priority (lowest)
  }

  if (context != null) {
    context.put(BOOSTED_DOCIDS, boostDocs);
  }

  return boostDocs;
}
 
Example #13
Source File: CFSA2Serializer.java    From morfologik-stemming with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Compute the set of states that should be linearized first to minimize other
 * states goto length.
 */
private int[] computeFirstStates(IntIntHashMap inlinkCount, int maxStates, int minInlinkCount) {
  Comparator<IntIntHolder> comparator = new Comparator<FSAUtils.IntIntHolder>() {
    public int compare(IntIntHolder o1, IntIntHolder o2) {
      int v = o1.a - o2.a;
      return v == 0 ? (o1.b - o2.b) : v;
    } 
  };

  PriorityQueue<IntIntHolder> stateInlink = new PriorityQueue<IntIntHolder>(1, comparator);
  IntIntHolder scratch = new IntIntHolder();
  for (IntIntCursor c : inlinkCount) {
    if (c.value > minInlinkCount) {
      scratch.a = c.value;
      scratch.b = c.key;

      if (stateInlink.size() < maxStates || comparator.compare(scratch, stateInlink.peek()) > 0) {
        stateInlink.add(new IntIntHolder(c.value, c.key));
        if (stateInlink.size() > maxStates) {
          stateInlink.remove();
        }
      }
    }
  }

  int [] states = new int [stateInlink.size()];
  for (int position = states.length; !stateInlink.isEmpty();) {
    IntIntHolder i = stateInlink.remove();
    states[--position] = i.b;
  }

  return states;
}
 
Example #14
Source File: HppcMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final IntIntHashMap m_map = new IntIntHashMap( m_keys.length / 2 + 1, m_fillFactor );
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.put( m_keys[ add ], m_keys[ add ] );
        ++add;
        m_map.remove( m_keys[ remove++ ] );
    }
    return m_map.size();
}
 
Example #15
Source File: HppcMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final IntIntHashMap m_map = new IntIntHashMap( m_keys.length, m_fillFactor );
    for ( int i = 0; i < m_keys.length; ++i )
       m_map.put( m_keys[ i ],m_keys[ i ] );
    for ( int i = 0; i < m_keys.length; ++i )
       m_map.put( m_keys[ i ],m_keys[ i ] );
    return m_map.size();
}
 
Example #16
Source File: DependencyStructure.java    From EasySRL with Apache License 2.0 5 votes vote down vote up
private static Coindexation normalize(final Coindexation coindexation,
		final Set<UnresolvedDependency> unresolvedDependencies,
		final Set<UnresolvedDependency> normalizedUnresolvedDependencies,
		final List<UnlabelledDependency> newResolvedDependencies, final int minValue) {
	final IntIntHashMap normalizingSubsitution = new IntIntHashMap();
	final Coindexation normalizedCoindexation = coindexation.normalize(normalizingSubsitution, minValue);
	normalize(unresolvedDependencies, normalizingSubsitution, normalizedUnresolvedDependencies,
			newResolvedDependencies);
	return normalizedCoindexation;
}
 
Example #17
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public DelegatingCollector getFilterCollector(IndexSearcher indexSearcher) {
  try {

    SolrIndexSearcher searcher = (SolrIndexSearcher)indexSearcher;
    CollectorFactory collectorFactory = new CollectorFactory();
    //Deal with boosted docs.
    //We have to deal with it here rather then the constructor because
    //because the QueryElevationComponent runs after the Queries are constructed.

    IntIntHashMap boostDocsMap = null;
    @SuppressWarnings({"rawtypes"})
    Map context = null;
    SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
    if(info != null) {
      context = info.getReq().getContext();
    }

    if(this.boosted == null && context != null) {
      this.boosted = (Set<BytesRef>)context.get(QueryElevationComponent.BOOSTED);
    }

    boostDocsMap = QueryElevationComponent.getBoostDocs(searcher, this.boosted, context);
    return collectorFactory.getCollector(this.collapseField,
                                         this.groupHeadSelector,
                                         this.sortSpec,
                                         this.nullPolicy,
                                         this.hint,
                                         this.needsScores4Collapsing,
                                         this.needsScores,
                                         this.size,
                                         boostDocsMap,
                                         searcher);

  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #18
Source File: Coindexation.java    From EasySRL with Apache License 2.0 5 votes vote down vote up
Coindexation normalize(final IntIntHashMap substitutions, final int minValue) {
	Coindexation.IDorHead newIDorHead = idOrHead;
	if (idOrHead.id != null) {
		int newID = substitutions.getOrDefault(idOrHead.id, Integer.MIN_VALUE);
		if (newID == Integer.MIN_VALUE) {
			newID = substitutions.size() + minValue;
			substitutions.put(idOrHead.id, newID);
		}
		newIDorHead = new Coindexation.IDorHead(newID);
	}

	return new Coindexation(left == null ? null : left.normalize(substitutions, minValue), right == null ? null
			: right.normalize(substitutions, minValue), newIDorHead, preposition);
}
 
Example #19
Source File: IntIntDynamicMap.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Create map with expected max value of key.
 * Although the map will automatically do resizing to be able to hold key {@code >= expectedKeyMax}.
 * But putting key much larger than {@code expectedKeyMax} is discourage since it can leads to use LOT OF memory.
 */
public IntIntDynamicMap(int expectedKeyMax, int emptyValue) {
  this.threshold = threshold(expectedKeyMax);
  this.maxSize = expectedKeyMax;
  this.emptyValue = emptyValue;
  if (useArrayBased(expectedKeyMax)) {
    upgradeToArray();
  } else {
    this.hashMap = new IntIntHashMap(mapExpectedElements(expectedKeyMax));
  }
}
 
Example #20
Source File: QueryElevationComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private ElevationComparatorSource(IntIntHashMap elevatedWithPriority, boolean useConfiguredElevatedOrder) {
  this.elevatedWithPriority = elevatedWithPriority;
  this.useConfiguredElevatedOrder = useConfiguredElevatedOrder;

  // copy elevatedWithPriority keys (doc IDs) into sortedElevatedDocIds, sorted
  sortedElevatedDocIds = new int[elevatedWithPriority.size()];
  final Iterator<IntIntCursor> iterator = elevatedWithPriority.iterator();
  for (int i = 0; i < sortedElevatedDocIds.length; i++) {
    IntIntCursor next = iterator.next();
    sortedElevatedDocIds[i] = next.key;
  }
  assert iterator.hasNext() == false;
  Arrays.sort(sortedElevatedDocIds);
}
 
Example #21
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public OrdFieldValueStrategy(int maxDoc,
                             int valueCount,
                             int nullPolicy,
                             boolean needsScores,
                             IntIntHashMap boostDocsMap,
                             SortedDocValues values) {
  this.ords = new IntIntDynamicMap(valueCount, -1);
  this.nullPolicy = nullPolicy;
  this.needsScores = needsScores;
  this.collapsedSet = new FixedBitSet(maxDoc);
  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);
    this.boosted = true;
  }

  if (this.needsScores) {
    this.scores = new IntFloatDynamicMap(valueCount, 0.0f);
    if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
      nullScores = new FloatArrayList();
    }
  }
}
 
Example #22
Source File: QueryElevationComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void setSort(ResponseBuilder rb, Elevation elevation) throws IOException {
  if (elevation.elevatedIds.isEmpty()) {
    return;
  }
  boolean forceElevation = rb.req.getParams().getBool(QueryElevationParams.FORCE_ELEVATION, this.forceElevation);
  boolean useConfigured = rb.req.getParams().getBool(QueryElevationParams.USE_CONFIGURED_ELEVATED_ORDER, this.useConfiguredElevatedOrder);
  final IntIntHashMap elevatedWithPriority = getBoostDocs(rb.req.getSearcher(), elevation.elevatedIds, rb.req.getContext());
  ElevationComparatorSource comparator = new ElevationComparatorSource(elevatedWithPriority, useConfigured);
  setSortSpec(rb, forceElevation, comparator);
  setGroupingSpec(rb, forceElevation, comparator);
}
 
Example #23
Source File: ReRankCollector.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public BoostedComp(IntIntHashMap boostedDocs, ScoreDoc[] scoreDocs, float maxScore) {
  this.boostedMap = new IntFloatHashMap(boostedDocs.size()*2);

  for(int i=0; i<scoreDocs.length; i++) {
    final int idx;
    if((idx = boostedDocs.indexOf(scoreDocs[i].doc)) >= 0) {
      boostedMap.put(scoreDocs[i].doc, maxScore+boostedDocs.indexGet(idx));
    } else {
      break;
    }
  }
}
 
Example #24
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public IntValueSourceStrategy(int maxDoc,
                              int size,
                              String collapseField,
                              int nullValue,
                              int nullPolicy,
                              GroupHeadSelector groupHeadSelector,
                              boolean needsScores4Collapsing,
                              boolean needsScores,
                              IntIntHashMap boostDocs,
                              FunctionQuery funcQuery,
                              IndexSearcher searcher) throws IOException {

  super(maxDoc, size, collapseField, nullValue, nullPolicy, needsScores, boostDocs);

  this.needsScores4Collapsing = needsScores4Collapsing;
  this.testValues = new IntFloatDynamicMap(size, 0.0f);

  this.valueSource = funcQuery.getValueSource();
  this.rcontext = ValueSource.newContext(searcher);

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    this.nullCompVal = -Float.MAX_VALUE;
    comp = new MaxFloatComp();
  } else {
    this.nullCompVal = Float.MAX_VALUE;
    comp = new MinFloatComp();
  }

  collapseScore.setupIfNeeded(groupHeadSelector, rcontext);
}
 
Example #25
Source File: AlfrescoReRankQParserPlugin.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BoostedComp(IntIntHashMap boostedDocs, ScoreDoc[] scoreDocs, float maxScore) {
    this.boostedMap = new IntFloatHashMap(boostedDocs.size()*2);

    for(int i=0; i<scoreDocs.length; i++) {
        if(boostedDocs.containsKey(scoreDocs[i].doc)) {
            boostedMap.put(scoreDocs[i].doc, maxScore+boostedDocs.get(scoreDocs[i].doc));
        } else {
            break;
        }
    }
}
 
Example #26
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public IntFieldValueStrategy(int maxDoc,
                             int size,
                             String collapseField,
                             int nullValue,
                             int nullPolicy,
                             boolean needsScores,
                             IntIntHashMap boostDocsMap) {
  this.collapseField = collapseField;
  this.nullValue = nullValue;
  this.nullPolicy = nullPolicy;
  this.needsScores = needsScores;
  this.collapsedSet = new FixedBitSet(maxDoc);
  this.cmap = new IntIntHashMap(size);
  this.docs = new IntIntDynamicMap(size, 0);
  if(boostDocsMap != null) {
    this.boosts = true;
    this.boostDocs = new IntArrayList();
    this.boostKeys = 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);
  }

  if(needsScores) {
    this.scores = new IntFloatDynamicMap(size, 0.0f);
    if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
      nullScores = new FloatArrayList();
    }
  }
}
 
Example #27
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public OrdValueSourceStrategy(int maxDoc,
                              int nullPolicy,
                              int valueCount,
                              GroupHeadSelector groupHeadSelector,
                              boolean needsScores4Collapsing,
                              boolean needsScores,
                              IntIntHashMap boostDocs,
                              FunctionQuery funcQuery,
                              IndexSearcher searcher,
                              SortedDocValues values) throws IOException {
  super(maxDoc, valueCount, nullPolicy, needsScores, boostDocs, values);
  this.needsScores4Collapsing = needsScores4Collapsing;
  this.valueSource = funcQuery.getValueSource();
  this.rcontext = ValueSource.newContext(searcher);

  assert GroupHeadSelectorType.MIN_MAX.contains(groupHeadSelector.type);

  if (GroupHeadSelectorType.MAX.equals(groupHeadSelector.type)) {
    comp = new MaxFloatComp();
    this.ordVals = new IntFloatDynamicMap(valueCount, -Float.MAX_VALUE);
  } else {
    this.nullVal = Float.MAX_VALUE;
    comp = new MinFloatComp();
    this.ordVals = new IntFloatDynamicMap(valueCount, Float.MAX_VALUE);
  }

  collapseScore.setupIfNeeded(groupHeadSelector, rcontext);
}
 
Example #28
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public DelegatingCollector getCollector(String collapseField,
                                      GroupHeadSelector groupHeadSelector,
                                      SortSpec sortSpec,
                                      int nullPolicy,
                                      String hint,
                                      boolean needsScores4Collapsing,
                                      boolean needsScores,
                                      int size,
                                      IntIntHashMap boostDocs,
                                      SolrIndexSearcher searcher) throws IOException {

DocValuesProducer docValuesProducer = null;
FunctionQuery funcQuery = null;

FieldType collapseFieldType = searcher.getSchema().getField(collapseField).getType();
String defaultValue = searcher.getSchema().getField(collapseField).getDefaultValue();

if(collapseFieldType instanceof StrField) {
  if(HINT_TOP_FC.equals(hint)) {
    @SuppressWarnings("resource")
    final LeafReader uninvertingReader = getTopFieldCacheReader(searcher, collapseField);

    docValuesProducer = new EmptyDocValuesProducer() {
        @Override
        public SortedDocValues getSorted(FieldInfo ignored) throws IOException {
          return uninvertingReader.getSortedDocValues(collapseField);
        }
      };
  } else {
    docValuesProducer = new EmptyDocValuesProducer() {
 
Example #29
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 #30
Source File: CollapsingQParserPlugin.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public IntScoreCollector(int maxDoc,
                         int segments,
                         int nullValue,
                         int nullPolicy,
                         int size,
                         String field,
                         IntIntHashMap boostDocsMap,
                         IndexSearcher searcher) {
  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.nullValue = nullValue;
  this.nullPolicy = nullPolicy;
  if(nullPolicy == CollapsingPostFilter.NULL_POLICY_EXPAND) {
    nullScores = new FloatArrayList();
  }
  this.cmap = new IntLongHashMap(size);
  this.field = field;

  if(boostDocsMap != null) {
    this.boosts = true;
    this.boostDocs = new IntArrayList();
    this.boostKeys = 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);
    this.boosts = true;
  }

}