LUCENE-5151: Associations aggregators enter an infinite loop if some documents have no category associations

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1508440 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-07-30 13:53:38 +00:00
parent 2c5856cf25
commit 6ec978de46
4 changed files with 40 additions and 39 deletions

View File

@ -100,6 +100,9 @@ Bug Fixes
considered if the input is equal causing the malformed weight to be identical as well.
(Simon Willnauer)
* LUCENE-5151: Associations FacetsAggregators could enter an infinite loop when
some result documents were missing category associations. (Shai Erera)
API Changes
* LUCENE-5094: Add ramBytesUsed() to MultiDocValues.OrdinalMap.

View File

@ -54,23 +54,20 @@ public class SumFloatAssociationFacetsAggregator implements FacetsAggregator {
int doc = 0;
while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
dv.get(doc, bytes);
if (bytes.length == 0) {
continue; // no associations for this document
if (bytes.length > 0) {
// aggreate float association values for ordinals
int bytesUpto = bytes.offset + bytes.length;
int pos = bytes.offset;
while (pos < bytesUpto) {
int ordinal = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
int value = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
values[ordinal] += Float.intBitsToFloat(value);
}
}
// aggreate float association values for ordinals
int bytesUpto = bytes.offset + bytes.length;
int pos = bytes.offset;
while (pos < bytesUpto) {
int ordinal = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
int value = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
values[ordinal] += Float.intBitsToFloat(value);
}
++doc;
}
}

View File

@ -53,23 +53,20 @@ public class SumIntAssociationFacetsAggregator implements FacetsAggregator {
int doc = 0;
while (doc < length && (doc = matchingDocs.bits.nextSetBit(doc)) != -1) {
dv.get(doc, bytes);
if (bytes.length == 0) {
continue; // no associations for this document
if (bytes.length > 0) {
// aggreate association values for ordinals
int bytesUpto = bytes.offset + bytes.length;
int pos = bytes.offset;
while (pos < bytesUpto) {
int ordinal = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
int value = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
values[ordinal] += value;
}
}
// aggreate association values for ordinals
int bytesUpto = bytes.offset + bytes.length;
int pos = bytes.offset;
while (pos < bytesUpto) {
int ordinal = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
int value = ((bytes.bytes[pos++] & 0xFF) << 24) | ((bytes.bytes[pos++] & 0xFF) << 16)
| ((bytes.bytes[pos++] & 0xFF) << 8) | (bytes.bytes[pos++] & 0xFF);
values[ordinal] += value;
}
++doc;
}
}

View File

@ -67,14 +67,18 @@ public class AssociationsFacetRequestTest extends FacetTestCase {
AssociationsFacetFields assocFacetFields = new AssociationsFacetFields(taxoWriter);
// index documents, 50% have only 'b' and all have 'a'
for (int i = 0; i < 100; i++) {
for (int i = 0; i < 110; i++) {
Document doc = new Document();
CategoryAssociationsContainer associations = new CategoryAssociationsContainer();
associations.setAssociation(aint, new CategoryIntAssociation(2));
associations.setAssociation(afloat, new CategoryFloatAssociation(0.5f));
if (i % 2 == 0) { // 50
associations.setAssociation(bint, new CategoryIntAssociation(3));
associations.setAssociation(bfloat, new CategoryFloatAssociation(0.2f));
// every 11th document is added empty, this used to cause the association
// aggregators to go into an infinite loop
if (i % 11 != 0) {
associations.setAssociation(aint, new CategoryIntAssociation(2));
associations.setAssociation(afloat, new CategoryFloatAssociation(0.5f));
if (i % 2 == 0) { // 50
associations.setAssociation(bint, new CategoryIntAssociation(3));
associations.setAssociation(bfloat, new CategoryFloatAssociation(0.2f));
}
}
assocFacetFields.addFields(doc, associations);
writer.addDocument(doc);