Skip to content

Commit

Permalink
cache leadingImpactsPerField
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharymorn committed Nov 19, 2021
1 parent 68eb9b8 commit 6d5e780
Showing 1 changed file with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ static ImpactsSource mergeImpacts(
Map<String, List<Impacts>> fieldsWithImpacts,
Map<String, Float> fieldWeights) {
return new ImpactsSource() {
Map<String, Impacts> leadingImpactsPerField = null;

class SubIterator {
final Iterator<Impact> iterator;
Expand All @@ -523,26 +524,28 @@ public Impacts getImpacts() throws IOException {
// Use the impacts that have the lower next boundary (doc id in skip entry) as a lead for
// each field
// They collectively will decide on the number of levels and the block boundaries.
Map<String, Impacts> leadingImpactsPerField = new HashMap<>(fieldsWithImpactsEnums.size());

for (Map.Entry<String, List<ImpactsEnum>> fieldImpacts :
fieldsWithImpactsEnums.entrySet()) {
String field = fieldImpacts.getKey();
List<ImpactsEnum> impactsEnums = fieldImpacts.getValue();
fieldsWithImpacts.put(field, new ArrayList<>(impactsEnums.size()));

Impacts tmpLead = null;
// find the impact that has the lowest next boundary for this field
for (int i = 0; i < impactsEnums.size(); ++i) {
Impacts impacts = impactsEnums.get(i).getImpacts();
fieldsWithImpacts.get(field).add(impacts);

if (tmpLead == null || impacts.getDocIdUpTo(0) < tmpLead.getDocIdUpTo(0)) {
tmpLead = impacts;

if (leadingImpactsPerField == null) {
leadingImpactsPerField = new HashMap<>(fieldsWithImpactsEnums.size());
for (Map.Entry<String, List<ImpactsEnum>> fieldImpacts :
fieldsWithImpactsEnums.entrySet()) {
String field = fieldImpacts.getKey();
List<ImpactsEnum> impactsEnums = fieldImpacts.getValue();
fieldsWithImpacts.put(field, new ArrayList<>(impactsEnums.size()));

Impacts tmpLead = null;
// find the impact that has the lowest next boundary for this field
for (int i = 0; i < impactsEnums.size(); ++i) {
Impacts impacts = impactsEnums.get(i).getImpacts();
fieldsWithImpacts.get(field).add(impacts);

if (tmpLead == null || impacts.getDocIdUpTo(0) < tmpLead.getDocIdUpTo(0)) {
tmpLead = impacts;
}
}
}

leadingImpactsPerField.put(field, tmpLead);
leadingImpactsPerField.put(field, tmpLead);
}
}

return new Impacts() {
Expand Down Expand Up @@ -754,6 +757,7 @@ public void advanceShallow(int target) throws IOException {
}
}
}
leadingImpactsPerField = null;
}
};
}
Expand Down

0 comments on commit 6d5e780

Please sign in to comment.