This is an automated email from the ASF dual-hosted git repository.

mkataria pushed a commit to branch 1.22
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/1.22 by this push:
     new dff9143923 OAK-10273: Index-definition json created during oak-run 
reindex should not serialise index data (#988)
dff9143923 is described below

commit dff9143923026caa4a71ee603eec47b607c54260
Author: Mohit Kataria <[email protected]>
AuthorDate: Mon Jul 3 13:43:53 2023 +0530

    OAK-10273: Index-definition json created during oak-run reindex should not 
serialise index data (#988)
---
 .../jackrabbit/oak/index/IndexerSupport.java       |  2 +-
 .../oak/index/AbstractIndexCommandTest.java        |  6 +--
 .../org/apache/jackrabbit/oak/index/ReindexIT.java | 49 ++++++++++++++++++++--
 3 files changed, 49 insertions(+), 8 deletions(-)

diff --git 
a/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexerSupport.java 
b/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexerSupport.java
index ceee84eea2..af69cdb78d 100644
--- a/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexerSupport.java
+++ b/oak-run/src/main/java/org/apache/jackrabbit/oak/index/IndexerSupport.java
@@ -111,7 +111,7 @@ public class IndexerSupport {
 
     private void dumpIndexDefinitions(NodeStore nodeStore) throws IOException, 
CommitFailedException {
         IndexDefinitionPrinter printer = new IndexDefinitionPrinter(nodeStore, 
indexHelper.getIndexPathService());
-        printer.setFilter("{\"properties\":[\"*\", 
\"-:childOrder\"],\"nodes\":[\"*\", \"-:index-definition\"]}");
+        printer.setFilter("{\"properties\":[\"*\", 
\"-:childOrder\"],\"nodes\":[\"*\", \"-:index-definition\", \"-:data\", 
\"-:suggest-data\"]}");
         PrinterDumper dumper = new PrinterDumper(getLocalIndexDir(), 
IndexDefinitionUpdater.INDEX_DEFINITIONS_JSON,
                 false, Format.JSON, printer);
         dumper.dump();
diff --git 
a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
 
b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
index 2b6e273f9a..f8f7d474b8 100644
--- 
a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
+++ 
b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/AbstractIndexCommandTest.java
@@ -60,7 +60,7 @@ public class AbstractIndexCommandTest {
     protected void addTestContent(RepositoryFixture fixture, String basePath, 
String propName, int count) throws IOException, RepositoryException {
         Session session = fixture.getAdminSession();
         for (int i = 0; i < count; i++) {
-            getOrCreateByPath(basePath+i,
+            getOrCreateByPath(basePath + i,
                     "oak:Unstructured", session).setProperty(propName, "bar");
         }
         session.save();
@@ -82,13 +82,13 @@ public class AbstractIndexCommandTest {
         if (!asyncIndex) {
             idxBuilder.noAsync();
         }
-        idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
+        
idxBuilder.indexRule("nt:base").property("foo").propertyIndex().useInSuggest().analyzed();
 
         Session session = fixture.getAdminSession();
         Node fooIndex = getOrCreateByPath(TEST_INDEX_PATH,
                 "oak:QueryIndexDefinition", session);
-
         idxBuilder.build(fooIndex);
+        
fooIndex.addNode("suggestion").setProperty("suggestUpdateFrequencyMinutes", 0);
         session.save();
         session.logout();
     }
diff --git 
a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java 
b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
index 35bd7a29d7..34bff295ff 100644
--- a/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
+++ b/oak-run/src/test/java/org/apache/jackrabbit/oak/index/ReindexIT.java
@@ -32,6 +32,7 @@ import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
 
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
@@ -53,6 +54,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static com.google.common.base.Charsets.UTF_8;
+import static org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath;
 import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.hasItem;
@@ -111,15 +113,29 @@ public class ReindexIT extends AbstractIndexCommandTest {
         assertEquals(1, idxDirs.size());
     }
 
+    private void addSuggestContent(RepositoryFixture fixture, String basePath, 
String propName, int count) throws RepositoryException, IOException {
+        Session session = fixture.getAdminSession();
+        for (int i = 0; i < count; i++) {
+            getOrCreateByPath(basePath + i,
+                    "oak:Unstructured", session).setProperty(propName, 
"suggest Property " + i + basePath);
+        }
+        session.save();
+        session.logout();
+    }
+
     @Test
     public void reindexAndThenImport() throws Exception {
         createTestData(true);
+        int fooSuggestCount = 2;
+        int contentCount = 100;
+        addSuggestContent(fixture, "/testnode/suggest1", "foo", 
fooSuggestCount);
         fixture.getAsyncIndexUpdate("async").run();
 
         //Update index to bar property also but do not index yet
         indexBarPropertyAlso(fixture);
 
         int fooCount = getFooCount(fixture, "foo");
+        List<String> suggestResults1 = getSuggestResults(fixture, "foo");
         String checkpoint = 
fixture.getNodeStore().checkpoint(TimeUnit.HOURS.toMillis(24));
 
         //Close the repository so as all changes are flushed
@@ -146,8 +162,9 @@ public class ReindexIT extends AbstractIndexCommandTest {
         //import
 
         RepositoryFixture fixture2 = new RepositoryFixture(storeDir);
-        addTestContent(fixture2, "/testNode/b", "foo", 100);
-        addTestContent(fixture2, "/testNode/c", "bar", 100);
+        addTestContent(fixture2, "/testNode/b", "foo", contentCount);
+        addTestContent(fixture2, "/testNode/c", "bar", contentCount);
+        addSuggestContent(fixture2, "/testNode/suggest2", "foo", 
fooSuggestCount);
         fixture2.getAsyncIndexUpdate("async").run();
 
         String explain = getQueryPlan(fixture2, "select * from [nt:base] where 
[bar] is not null");
@@ -155,7 +172,9 @@ public class ReindexIT extends AbstractIndexCommandTest {
         assertThat(explain, not(containsString(TEST_INDEX_PATH)));
 
         int foo2Count = getFooCount(fixture2, "foo");
-        assertEquals(fooCount + 100, foo2Count);
+        List<String> suggestResults2 = getSuggestResults(fixture2, "foo");
+        assertEquals(suggestResults1.size() + fooSuggestCount, 
suggestResults2.size());
+        assertEquals(fooCount + contentCount + fooSuggestCount, foo2Count);
         assertNotNull(fixture2.getNodeStore().retrieve(checkpoint));
         fixture2.close();
 
@@ -182,10 +201,11 @@ public class ReindexIT extends AbstractIndexCommandTest {
 
         RepositoryFixture fixture4 = new RepositoryFixture(storeDir);
         int foo4Count = getFooCount(fixture4, "foo");
+        List<String> suggestResults4 = getSuggestResults(fixture4, "foo");
 
         //new count should be same as previous
         assertEquals(foo2Count, foo4Count);
-
+        assertEquals(suggestResults2.size(), suggestResults4.size());
         //Checkpoint must be released
         assertNull(fixture4.getNodeStore().retrieve(checkpoint));
 
@@ -334,6 +354,27 @@ public class ReindexIT extends AbstractIndexCommandTest {
         return size;
     }
 
+    public List<String> getSuggestResults(RepositoryFixture fixture, String 
propName) throws Exception {
+        Session session = fixture.getAdminSession();
+
+        QueryManager qm = session.getWorkspace().getQueryManager();
+        String sql = "SELECT [rep:suggest()] FROM [nt:base] WHERE 
SUGGEST('sugge')";
+        Query q = qm.createQuery(sql, Query.SQL);
+        List<String> result = getResult(q.execute(), "rep:suggest()");
+        assertNotNull(result);
+        return result;
+    }
+
+    static List<String> getResult(QueryResult result, String propertyName) 
throws RepositoryException {
+        List<String> results = Lists.newArrayList();
+        RowIterator it = result.getRows();
+        while (it.hasNext()) {
+            Row row = it.nextRow();
+            results.add(row.getValue(propertyName).getString());
+        }
+        return results;
+    }
+
     private static String getQueryPlan(RepositoryFixture fixture, String 
query) throws RepositoryException, IOException {
         Session session = fixture.getAdminSession();
         QueryManager qm = session.getWorkspace().getQueryManager();

Reply via email to