JCR-4455 condition index-rule handling more broken after JCR-4339
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1862783 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java b/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
index b795d25..00bfe9b 100644
--- a/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
+++ b/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImpl.java
@@ -389,17 +389,20 @@
rules.addAll(r);
}
}
-
+ IndexingRule matchingNodeTypeRule = null;
if (rules != null) {
for (IndexingRule rule : rules) {
- if (rule.appliesTo(state)) {
- return rule;
+ if (rule.appliesToNodeType(state)) {
+ if (!rule.containsCondition()) {
+ matchingNodeTypeRule = rule;
+ } else if (rule.appliesToCondition(state)) {
+ return rule;
+ }
}
}
}
- // no applicable rule
- return null;
+ return matchingNodeTypeRule;
}
/**
@@ -811,21 +814,43 @@
}
/**
- * Returns <code>true</code> if this rule applies to the given node
- * <code>state</code>.
+ * Returns <code>true</code> if the nodetype of this rule
+ * applies to the given node <code>state</code>.
*
* @param state the state to check.
* @return <code>true</code> the rule applies to the given node;
* <code>false</code> otherwise.
*/
- public boolean appliesTo(NodeState state) {
+ public boolean appliesToNodeType(NodeState state) {
if (state.getMixinTypeNames().contains(nodeTypeName)) {
return true;
}
if (!nodeTypeName.equals(state.getNodeTypeName())) {
return false;
}
- return condition == null || condition.evaluate(state);
+ return true;
+ }
+
+ /**
+ * Returns <code>true</code> if the condition of this rule
+ * applies to the given node <code>state</code>.
+ *
+ * @param state the state to check.
+ * @return <code>true</code> the rule applies to the given node;
+ * <code>false</code> otherwise.
+ */
+ public boolean appliesToCondition(NodeState state) {
+ return condition != null && condition.evaluate(state);
+ }
+
+ /**
+ * Returns <code>true</code> this rule contains a condition.
+ *
+ * @return <code>true</code> the rule contains a condition;
+ * <code>false</code> otherwise.
+ */
+ public boolean containsCondition() {
+ return condition != null;
}
//-------------------------< internal >---------------------------------
diff --git a/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java b/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
index e627129..0c8c8f2 100644
--- a/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
+++ b/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingConfigurationImplTest.java
@@ -41,6 +41,7 @@
public class IndexingConfigurationImplTest extends AbstractIndexingTest {
private static final Name FOO = NameFactoryImpl.getInstance().create("", "foo");
+ private static final Name OTHER = NameFactoryImpl.getInstance().create("", "other");
private NodeState nState;
private Node n;
@@ -114,6 +115,15 @@
session.save();
nState = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(
new NodeId(n.getIdentifier()));
+ assertTrue(config.isIndexed(nState, FOO));
+ assertFalse(config.isIndexed(nState, OTHER));
+
+ n = testRootNode.addNode(nodeName2, ntUnstructured);
+ n.addMixin(mixReferenceable);
+ session.save();
+ nState = (NodeState) getSearchIndex().getContext().getItemStateManager().getItemState(
+ new NodeId(n.getIdentifier()));
+ assertTrue(config.isIndexed(nState, OTHER));
assertFalse(config.isIndexed(nState, FOO));
}
diff --git a/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config6.xml b/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config6.xml
index f57ca1a..f8c2b37 100644
--- a/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config6.xml
+++ b/jackrabbit-core/src/test/resources/org/apache/jackrabbit/core/query/lucene/indexing_config6.xml
@@ -19,7 +19,12 @@
<configuration xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
+ <index-rule nodeType="nt:unstructured">
+ <property>other</property>
+ </index-rule>
+
<index-rule nodeType="nt:unstructured" condition="@foo = 'high'">
+ <property>foo</property>
</index-rule>
</configuration>
\ No newline at end of file