Example usage for org.apache.lucene.util MapOfSets putAll

List of usage examples for org.apache.lucene.util MapOfSets putAll

Introduction

In this page you can find the example usage for org.apache.lucene.util MapOfSets putAll.

Prototype

public int putAll(K key, Collection<? extends V> vals) 

Source Link

Document

Adds multiple vals to the Set associated with key in the Map.

Usage

From source file:org.apache.solr.uninverting.FieldCacheSanityChecker.java

License:Apache License

/** 
 * Internal helper method used by check that iterates over 
 * the keys of readerFieldToValIds and generates a Collection 
 * of Insanity instances whenever two (or more) ReaderField instances are 
 * found that have an ancestry relationships.  
 *
 * @see InsanityType#SUBREADER/*  w  ww  .  j a  va 2 s .  co  m*/
 */
private Collection<Insanity> checkSubreaders(MapOfSets<Integer, CacheEntry> valIdToItems,
        MapOfSets<ReaderField, Integer> readerFieldToValIds) {

    final List<Insanity> insanity = new ArrayList<>(23);

    Map<ReaderField, Set<ReaderField>> badChildren = new HashMap<>(17);
    MapOfSets<ReaderField, ReaderField> badKids = new MapOfSets<>(badChildren); // wrapper

    Map<Integer, Set<CacheEntry>> viToItemSets = valIdToItems.getMap();
    Map<ReaderField, Set<Integer>> rfToValIdSets = readerFieldToValIds.getMap();

    Set<ReaderField> seen = new HashSet<>(17);

    Set<ReaderField> readerFields = rfToValIdSets.keySet();
    for (final ReaderField rf : readerFields) {

        if (seen.contains(rf))
            continue;

        List<Object> kids = getAllDescendantReaderKeys(rf.readerKey);
        for (Object kidKey : kids) {
            ReaderField kid = new ReaderField(kidKey, rf.fieldName);

            if (badChildren.containsKey(kid)) {
                // we've already process this kid as RF and found other problems
                // track those problems as our own
                badKids.put(rf, kid);
                badKids.putAll(rf, badChildren.get(kid));
                badChildren.remove(kid);

            } else if (rfToValIdSets.containsKey(kid)) {
                // we have cache entries for the kid
                badKids.put(rf, kid);
            }
            seen.add(kid);
        }
        seen.add(rf);
    }

    // every mapping in badKids represents an Insanity
    for (final ReaderField parent : badChildren.keySet()) {
        Set<ReaderField> kids = badChildren.get(parent);

        List<CacheEntry> badEntries = new ArrayList<>(kids.size() * 2);

        // put parent entr(ies) in first
        {
            for (final Integer value : rfToValIdSets.get(parent)) {
                badEntries.addAll(viToItemSets.get(value));
            }
        }

        // now the entries for the descendants
        for (final ReaderField kid : kids) {
            for (final Integer value : rfToValIdSets.get(kid)) {
                badEntries.addAll(viToItemSets.get(value));
            }
        }

        CacheEntry[] badness = new CacheEntry[badEntries.size()];
        badness = badEntries.toArray(badness);

        insanity.add(new Insanity(InsanityType.SUBREADER,
                "Found caches for descendants of " + parent.toString(), badness));
    }

    return insanity;

}