Skip to content

Apache Lucene open-source search software

LUCENE-5129: CategoryAssociationsContainer should not allow null associations

Shai Ereraf9bb96db815d
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 21621e5ef57..68cbb43acc3 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -84,6 +84,10 @@ API Changes
searchAfter exceeds the number of documents in the reader.
(Crocket via Shai Erera)
+* LUCENE-5129: CategoryAssociationsContainer no longer supports null
+ association values for categories. If you want to index categories without
+ associations, you should add them using FacetFields. (Shai Erera)
+
Optimizations
* LUCENE-5088: Added TermFilter to filter docs by a specific term.
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsListBuilder.java b/lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsListBuilder.java
index 42a4218f323..3c9db4514db 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsListBuilder.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/associations/AssociationsListBuilder.java
@@ -54,13 +54,6 @@ public class AssociationsListBuilder implements CategoryListBuilder {
// build per-association key BytesRef
CategoryAssociation association = associations.getAssociation(cp);
- if (association == null) {
- // it is ok to set a null association for a category - it's treated as a
- // regular category in that case.
- ++idx;
- continue;
- }
-
BytesRef bytes = res.get(association.getCategoryListID());
if (bytes == null) {
bytes = new BytesRef(32);
diff --git a/lucene/facet/src/java/org/apache/lucene/facet/associations/CategoryAssociationsContainer.java b/lucene/facet/src/java/org/apache/lucene/facet/associations/CategoryAssociationsContainer.java
index 67e6c4c8e90..d40a0c1a33e 100644
--- a/lucene/facet/src/java/org/apache/lucene/facet/associations/CategoryAssociationsContainer.java
+++ b/lucene/facet/src/java/org/apache/lucene/facet/associations/CategoryAssociationsContainer.java
@@ -30,11 +30,12 @@ public class CategoryAssociationsContainer implements Iterable<CategoryPath> {
/**
* Adds the {@link CategoryAssociation} for the given {@link CategoryPath
- * category}. Overrides any assocation that was previously set. It is ok to
- * pass {@code null}, in which case the category will be treated as a regular
- * one (i.e. without association value).
+ * category}. Overrides any assocation that was previously set.
*/
public void setAssociation(CategoryPath category, CategoryAssociation association) {
+ if (association == null) {
+ throw new IllegalArgumentException("cannot set a null association to a category");
+ }
categoryAssociations.put(category, association);
}