You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by th...@apache.org on 2022/03/14 15:39:41 UTC
[jackrabbit-oak] branch OAK-9724 created (now b165ce9)
This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a change to branch OAK-9724
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git.
at b165ce9 OAK-9724 Handle duplicate functions gracefully in indexing
This branch includes the following new commits:
new b165ce9 OAK-9724 Handle duplicate functions gracefully in indexing
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[jackrabbit-oak] 01/01: OAK-9724 Handle duplicate functions gracefully in indexing
Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
thomasm pushed a commit to branch OAK-9724
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit b165ce9c0625c26f5c15049e6281f6bedf4d5f3d
Author: Thomas Mueller <th...@apache.org>
AuthorDate: Mon Mar 14 16:38:59 2022 +0100
OAK-9724 Handle duplicate functions gracefully in indexing
---
.../plugins/index/lucene/LuceneDocumentMaker.java | 6 ++-
.../plugins/index/lucene/FunctionIndexTest.java | 50 ++++++++++++++++++++++
.../search/spi/editor/FulltextDocumentMaker.java | 5 +--
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMaker.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMaker.java
index 80caa29..c706dc8 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMaker.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneDocumentMaker.java
@@ -283,8 +283,10 @@ public class LuceneDocumentMaker extends FulltextDocumentMaker<Document> {
}
if (f != null && includePropertyValue(property, 0, pd)) {
- doc.add(f);
- fieldAdded = true;
+ if (doc.getField(f.name()) == null) {
+ doc.add(f);
+ fieldAdded = true;
+ }
}
} catch (Exception e) {
log.warn(
diff --git a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/FunctionIndexTest.java b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/FunctionIndexTest.java
index 6a1fee8..23d54b5 100644
--- a/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/FunctionIndexTest.java
+++ b/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/FunctionIndexTest.java
@@ -1117,6 +1117,56 @@ public class FunctionIndexTest extends AbstractQueryTest {
}
+ @Test
+ public void duplicateFunctionInIndex() throws Exception {
+ // Index def with same property - ordered - one with function and one without
+ Tree luceneIndex = createIndex("upper", Collections.<String>emptySet());
+ Tree prop = luceneIndex.addChild(FulltextIndexConstants.INDEX_RULES)
+ .addChild("nt:base")
+ .addChild(FulltextIndexConstants.PROP_NODE);
+ Tree upper1 = prop.addChild("upper1");
+ upper1.setProperty(FulltextIndexConstants.PROP_ORDERED,true);
+ upper1.setProperty(FulltextIndexConstants.PROP_FUNCTION, "fn:upper-case(jcr:content/n/@foo)");
+ Tree upper2 = prop.addChild("upper2");
+ upper2.setProperty(FulltextIndexConstants.PROP_ORDERED,true);
+ upper2.setProperty(FulltextIndexConstants.PROP_FUNCTION, "fn:upper-case(jcr:content/n/@foo)");
+ Tree upper3 = prop.addChild("upper3");
+ upper3.setProperty(FulltextIndexConstants.PROP_FUNCTION, "fn:upper-case(jcr:content/n/@foo)");
+ Tree upper4 = prop.addChild("upper4");
+ upper4.setProperty(FulltextIndexConstants.PROP_FUNCTION, "fn:upper-case(jcr:content/n/@foo)");
+
+ root.commit();
+
+ int i = 1;
+ // Create nodes that will be served by the index definition that follows
+ for (String node : asList("a", "c", "b", "e", "d")) {
+
+ Tree test = root.getTree("/").addChild(node);
+ test.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);
+
+ Tree a = test.addChild("jcr:content");
+ a.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);
+
+ Tree b = a.addChild("n");
+
+ b.setProperty("jcr:primaryType", "nt:unstructured", Type.NAME);
+ b.setProperty("foo", "bar"+i);
+ i++;
+ }
+
+ root.commit();
+
+ // Check ordering works for func and non func properties
+ assertOrderedPlanAndQuery(
+ "select * from [nt:base] order by upper([jcr:content/n/foo])",
+ "lucene:upper(/oak:index/upper)", asList("/a","/c","/b","/e","/d"));
+
+ assertOrderedPlanAndQuery(
+ "select * from [nt:base] order by upper([jcr:content/n/foo]) DESC",
+ "lucene:upper(/oak:index/upper)", asList("/d","/e","/b","/c","/a"));
+
+ }
+
/*
Given an index def with 2 orderable property definitions(non-relative) for same property - one with function and one without
Indexer should index any changes properly and ordering should work as expected.
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java
index 75fe0d8..e238984 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java
@@ -458,10 +458,9 @@ public abstract class FulltextDocumentMaker<D> implements DocumentMaker<D> {
PropertyState functionValue = calculateValue(path, state, pd.functionCode);
if (functionValue != null) {
if (pd.ordered) {
- addTypedOrderedFields(fields, functionValue, pd.function, pd);
+ fieldAdded |= addTypedOrderedFields(fields, functionValue, pd.function, pd);
}
- addTypedFields(fields, functionValue, pd.function, pd);
- fieldAdded = true;
+ fieldAdded |= addTypedFields(fields, functionValue, pd.function, pd);
}
}
return fieldAdded;