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 mk...@apache.org on 2020/08/13 07:03:19 UTC
svn commit: r1880822 - in /jackrabbit/oak/trunk:
oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/
oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/
oak-search/src/main/java/org/apac...
Author: mkataria
Date: Thu Aug 13 07:03:18 2020
New Revision: 1880822
URL: http://svn.apache.org/viewvc?rev=1880822&view=rev
Log:
OAK-9166: Elastic indexes - Fulltext query requires more rules than expected
Modified:
jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java
jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java
Modified: jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java?rev=1880822&r1=1880821&r2=1880822&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/index/ElasticDocumentMaker.java Thu Aug 13 07:03:18 2020
@@ -114,8 +114,8 @@ class ElasticDocumentMaker extends Fullt
}
@Override
- protected boolean isFulltextValuePersisted() {
- return false;
+ protected boolean isFulltextValuePersistedAtNode(PropertyDefinition pd) {
+ return !pd.analyzed;
}
@Override
Modified: jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java?rev=1880822&r1=1880821&r2=1880822&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticAbstractQueryTest.java Thu Aug 13 07:03:18 2020
@@ -176,13 +176,19 @@ public abstract class ElasticAbstractQue
}
protected IndexDefinitionBuilder createIndex(String... propNames) {
+ return createIndex(true, propNames);
+ }
+
+ protected IndexDefinitionBuilder createIndex(boolean isPropertyIndex, String... propNames) {
IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
if (!useAsyncIndexing()) {
builder = builder.noAsync();
}
IndexDefinitionBuilder.IndexRule indexRule = builder.indexRule("nt:base");
- for (String propName : propNames) {
- indexRule.property(propName).propertyIndex();
+ if (isPropertyIndex) {
+ for (String propName : propNames) {
+ indexRule.property(propName).propertyIndex();
+ }
}
return builder;
}
Modified: jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java?rev=1880822&r1=1880821&r2=1880822&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java (original)
+++ jackrabbit/oak/trunk/oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java Thu Aug 13 07:03:18 2020
@@ -113,6 +113,67 @@ public class ElasticFullTextAsyncTest ex
});
}
+ /*
+ In this test only nodeScope property is set over index. (OAK-9166)
+ */
+ @Test
+ public void onlyNodeScopeIndexedQuery() throws Exception {
+ IndexDefinitionBuilder builder = createIndex(false, "a", "b").async("async");
+ builder.indexRule("nt:base").property("a").nodeScopeIndex();
+ builder.indexRule("nt:base").property("b").nodeScopeIndex();
+
+ setIndex(UUID.randomUUID().toString(), builder);
+ root.commit();
+
+ //add content
+ Tree test = root.getTree("/").addChild("test");
+
+ test.addChild("nodea").setProperty("a", "hello");
+ test.addChild("nodeb").setProperty("a", "world");
+ test.addChild("nodec").setProperty("a", "hello world");
+ Tree d = test.addChild("noded");
+ d.setProperty("a", "hello");
+ d.setProperty("b", "world");
+ root.commit();
+
+ assertEventually(() -> {
+ assertQuery("//*[jcr:contains(., 'Hello')] ", XPATH, Arrays.asList("/test/nodea", "/test/nodec", "/test/noded"));
+ assertQuery("//*[jcr:contains(., 'hello world')] ", XPATH, Arrays.asList("/test/nodec", "/test/noded"));
+ });
+ }
+
+ /*
+ In ES we don't add a property data to :fulltext if both nodescope and analyzed is set on index. Instead we use a
+ multimatch query with cross_fields
+ In this test only we set nodeScope on a property and on b property just analyzed property is set over index. (OAK-9166)
+ contains query of type contain(., 'string') should not return b.
+ */
+ @Test
+ public void onlyAnalyzedPropertyShouldNotBeReturnedForNodeScopeIndexedQuery() throws Exception {
+ IndexDefinitionBuilder builder = createIndex(false, "a", "b").async("async");
+ builder.indexRule("nt:base").property("a").nodeScopeIndex();
+ builder.indexRule("nt:base").property("b").analyzed();
+
+ setIndex(UUID.randomUUID().toString(), builder);
+ root.commit();
+
+ //add content
+ Tree test = root.getTree("/").addChild("test");
+
+ test.addChild("nodea").setProperty("b", "hello");
+ test.addChild("nodeb").setProperty("b", "world");
+ test.addChild("nodec").setProperty("a", "hello world");
+ Tree d = test.addChild("noded");
+ d.setProperty("a", "hello");
+ d.setProperty("b", "world");
+ root.commit();
+
+ assertEventually(() -> {
+ assertQuery("//*[jcr:contains(., 'Hello')] ", XPATH, Arrays.asList("/test/nodec", "/test/noded"));
+ assertQuery("//*[jcr:contains(., 'hello world')] ", XPATH, Arrays.asList("/test/nodec"));
+ });
+ }
+
@Test
public void fullTextMultiTermQuery() throws Exception {
IndexDefinitionBuilder builder = createIndex("analyzed_field");
Modified: jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java?rev=1880822&r1=1880821&r2=1880822&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java (original)
+++ jackrabbit/oak/trunk/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/FulltextDocumentMaker.java Thu Aug 13 07:03:18 2020
@@ -276,7 +276,7 @@ public abstract class FulltextDocumentMa
}
if (pd.nodeScopeIndex) {
- if (isFulltextValuePersisted()) {
+ if (isFulltextValuePersistedAtNode(pd)) {
indexFulltextValue(doc, value);
}
if (pd.useInSimilarity) {
@@ -305,9 +305,13 @@ public abstract class FulltextDocumentMa
}
/**
- * Returns {@code true} if nodeScopeIndex full text values need to be indexed
+ * In elastic we don't add analyzed data in :fulltext if index has both analyzed
+ * and nodescope property. Instead we fire a multiMatch with cross_fields.
+ *
+ * Returns {@code true} if nodeScopeIndex full text values need to be indexed at node level (:fulltext)
*/
- protected boolean isFulltextValuePersisted() {
+ protected boolean isFulltextValuePersistedAtNode(PropertyDefinition pd) {
+ // By default nodeScopeIndex full text values need to be indexed.
return true;
}