FrancoisZhang commented on a change in pull request #489:
URL: https://github.com/apache/jackrabbit-oak/pull/489#discussion_r804219599



##########
File path: 
oak-search-elastic/src/test/java/org/apache/jackrabbit/oak/plugins/index/elastic/ElasticFullTextAsyncTest.java
##########
@@ -264,16 +259,104 @@ public void fulltextWithModifiedNodeScopeIndex() throws 
Exception {
         test.addChild("a").setProperty("analyzed_field", "sun.jpg");
         root.commit();
 
-        assertEventually(() ->
-                assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", 
XPATH, Collections.singletonList("/test/a")));
+        assertEventually(() -> assertQuery("//*[jcr:contains(@analyzed_field, 
'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a")));
 
         // add nodeScopeIndex at a later stage
-        index.getChild("indexRules").getChild("nt:base").getChild("properties")
-                
.getChild("analyzed_field").setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX,
 true);
+        index.getChild("indexRules")
+                .getChild("nt:base")
+                .getChild("properties")
+                .getChild("analyzed_field")
+                .setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, 
true);
+        root.commit();
+
+        assertEventually(() -> assertQuery("//*[jcr:contains(., 'jpg')] ", 
XPATH, Collections.singletonList("/test/a")));
+    }
+
+    @Test
+    public void nodeScopeFulltextQuery() throws CommitFailedException {
+        IndexDefinitionBuilder builder = createIndex("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();
+
+        prepareTestContent();
+
+        assertEventually(() -> {
+            // case insensitive
+            assertQuery("//*[jcr:contains(., 'WORLD')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // wild card
+            assertQuery("//*[jcr:contains(., 'Hell*')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'He*o')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., '*llo')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., '?orld')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'wo?ld')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'worl?')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // space explained as AND
+            assertQuery("//*[jcr:contains(., 'hello world')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // exclude
+            assertQuery("//*[jcr:contains(., 'hello -world')] ", XPATH, 
Arrays.asList("/test/nodea"));
+
+            // explicit OR
+            assertQuery("//*[jcr:contains(., 'ocean OR world')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+        });
+    }
+
+    @Test
+    public void analyzedNodeScopeFulltextQuery() throws CommitFailedException {
+        IndexDefinitionBuilder builder = createIndex("a", "b").async("async");
+        builder.indexRule("nt:base").property("a").nodeScopeIndex().analyzed();
+        builder.indexRule("nt:base").property("b").nodeScopeIndex().analyzed();
+
+        setIndex(UUID.randomUUID().toString(), builder);
         root.commit();
 
-        assertEventually(() ->
-                assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, 
Collections.singletonList("/test/a")));
+        prepareTestContent();
+
+        assertEventually(() -> {
+            // case insensitive
+            assertQuery("//*[jcr:contains(., 'WORLD')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // wild card
+            assertQuery("//*[jcr:contains(., 'Hell*')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'He*o')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., '*llo')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., '?orld')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'wo?ld')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+            assertQuery("//*[jcr:contains(., 'worl?')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // space explained as AND
+            assertQuery("//*[jcr:contains(., 'hello world')] ", XPATH, 
Arrays.asList("/test/nodeb", "/test/nodec"));
+
+            // exclude
+            assertQuery("//*[jcr:contains(., 'hello -world')] ", XPATH, 
Arrays.asList("/test/nodea"));
+
+            // explicit OR
+            assertQuery("//*[jcr:contains(., 'ocean OR world')] ", XPATH, 
Arrays.asList("/test/nodea", "/test/nodeb", "/test/nodec"));
+
+            // analyzed field
+            assertQuery("//*[jcr:contains(., 'soccer')] ", XPATH, 
Arrays.asList("/test/nodeb"));

Review comment:
       @fabriziofortino thanks, but I also found there is a legacy test 
defaultAnalyzer in same class which is covered for analyzed field. hence may no 
need to create dup tests here. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to