jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1483507 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ oak-lucene/ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plu...
Date Thu, 16 May 2013 18:54:43 GMT
Author: alexparvulescu
Date: Thu May 16 18:54:42 2013
New Revision: 1483507

URL: http://svn.apache.org/r1483507
Log:
OAK-828 Lucene support for index aggregates
 - basic (hardcoded) file aggregation support

Added:
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/aggregation/
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java
  (with props)
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/apache/
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/apache/jackrabbit/
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/apache/jackrabbit/oak/
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/apache/jackrabbit/oak/jcr/
    jackrabbit/oak/trunk/oak-lucene/src/test/resources/org/apache/jackrabbit/oak/jcr/query/
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
    jackrabbit/oak/trunk/oak-lucene/pom.xml
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1483507&r1=1483506&r2=1483507&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
Thu May 16 18:54:42 2013
@@ -195,18 +195,22 @@ public class IndexUtils {
         PropertyState property = builder.getProperty(name);
         if (property != null && property.getType() == STRING) {
             return property.getValue(STRING);
-        } else {
-            return null;
         }
+        if (property != null && property.getType() == NAME) {
+            return property.getValue(NAME);
+        }
+        return null;
     }
 
     public static String getString(NodeState state, String name) {
         PropertyState property = state.getProperty(name);
         if (property != null && property.getType() == STRING) {
             return property.getValue(STRING);
-        } else {
-            return null;
         }
+        if (property != null && property.getType() == NAME) {
+            return property.getValue(NAME);
+        }
+        return null;
     }
 
     public static boolean getBoolean(NodeBuilder builder, String name) {

Modified: jackrabbit/oak/trunk/oak-lucene/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/pom.xml?rev=1483507&r1=1483506&r2=1483507&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-lucene/pom.xml Thu May 16 18:54:42 2013
@@ -174,5 +174,17 @@
         <artifactId>logback-classic</artifactId>
         <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.tika</groupId>
+      <artifactId>tika-parsers</artifactId>
+      <version>${tika.version}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>commons-logging</groupId>
+          <artifactId>commons-logging</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
   </dependencies>
 </project>

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java?rev=1483507&r1=1483506&r2=1483507&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexUpdate.java
Thu May 16 18:54:42 2013
@@ -18,9 +18,9 @@ package org.apache.jackrabbit.oak.plugin
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.getString;
+import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newFulltextField;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPathField;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newPropertyField;
-import static org.apache.jackrabbit.oak.plugins.index.lucene.FieldFactory.newFulltextField;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.ANALYZER;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INCLUDE_PROPERTY_TYPES;
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.INDEX_DATA_CHILD_NAME;
@@ -39,6 +39,8 @@ import org.apache.jackrabbit.oak.api.Blo
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.lucene.aggregation.AggregatedState;
+import org.apache.jackrabbit.oak.plugins.index.lucene.aggregation.NodeAggregator;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.lucene.document.Document;
@@ -94,6 +96,8 @@ class LuceneIndexUpdate implements Close
 
     private final Set<Integer> propertyTypes;
 
+    private final NodeAggregator aggregator;
+
     public LuceneIndexUpdate(String path, NodeBuilder index, Parser parser)
             throws CommitFailedException {
         this.path = path;
@@ -106,6 +110,7 @@ class LuceneIndexUpdate implements Close
             throw new CommitFailedException("Lucene", 1,
                     "Failed to update the full text search index", e);
         }
+        aggregator = new NodeAggregator(index);
     }
 
     private Set<Integer> buildPropertyTypes(NodeBuilder index) {
@@ -205,6 +210,21 @@ class LuceneIndexUpdate implements Close
                 }
             }
         }
+        for (AggregatedState agg : aggregator.getAggregates(state)) {
+            for (PropertyState property : agg.getProperties()) {
+                String pname = property.getName();
+                if (isVisible(pname) && propertyTypes.isEmpty()
+                        || propertyTypes.contains(property.getType().tag())) {
+                    if (Type.BINARY.tag() == property.getType().tag()) {
+                        addBinaryValue(document, property, agg.get());
+                    } else {
+                        for (String v : property.getValue(Type.STRINGS)) {
+                            document.add(newFulltextField(v));
+                        }
+                    }
+                }
+            }
+        }
         return document;
     }
 

Added: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java?rev=1483507&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java
(added)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java
Thu May 16 18:54:42 2013
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.query;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.query.AbstractQueryTest;
+
+public class TextExtractionQueryTest extends AbstractQueryTest {
+
+    public void testFileContains() throws Exception {
+        assertFileContains("test.txt", "text/plain",
+                "AE502DBEA2C411DEBD340AD156D89593");
+        assertFileContains("test.rtf", "application/rtf", "quick brown fox");
+    }
+
+    public void testNtFile() throws RepositoryException, IOException {
+        while (testRootNode.hasNode(nodeName1)) {
+            testRootNode.getNode(nodeName1).remove();
+        }
+
+        String content = "The quick brown fox jumps over the lazy dog.";
+        Node file = JcrUtils.putFile(testRootNode, nodeName1, "text/plain",
+                new ByteArrayInputStream(content.getBytes("UTF-8")));
+
+        testRootNode.getSession().save();
+        String xpath = testPath + "/*[jcr:contains(jcr:content, 'lazy')]";
+        executeXPathQuery(xpath, new Node[] { file });
+    }
+
+    private void assertFileContains(String name, String type,
+            String... statements) throws Exception {
+        while (testRootNode.hasNode(nodeName1)) {
+            testRootNode.getNode(nodeName1).remove();
+        }
+        Node resource = testRootNode.addNode(nodeName1, NodeType.NT_RESOURCE);
+        resource.setProperty(JcrConstants.JCR_MIMETYPE, type);
+        InputStream stream = getClass().getResourceAsStream(name);
+        assertNotNull(stream);
+        try {
+            Binary binary = testRootNode.getSession().getValueFactory()
+                    .createBinary(stream);
+            resource.setProperty(JcrConstants.JCR_DATA, binary);
+        } finally {
+            stream.close();
+        }
+        testRootNode.getSession().save();
+        for (String statement : statements) {
+            assertContainsQuery(statement, true);
+        }
+    }
+
+    private void assertContainsQuery(String statement, boolean match)
+            throws InvalidQueryException, RepositoryException {
+        StringBuffer stmt = new StringBuffer();
+        stmt.append("/jcr:root").append(testRoot).append("/*");
+        stmt.append("[jcr:contains(., '").append(statement);
+        stmt.append("')]");
+
+        Query q = qm.createQuery(stmt.toString(), Query.XPATH);
+        checkResult(q.execute(), match ? 1 : 0);
+
+        stmt = new StringBuffer();
+        stmt.append("SELECT * FROM nt:base ");
+        stmt.append("WHERE jcr:path LIKE '").append(testRoot).append("/%' ");
+        stmt.append("AND CONTAINS(., '").append(statement).append("')");
+
+        q = qm.createQuery(stmt.toString(), Query.SQL);
+        checkResult(q.execute(), match ? 1 : 0);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/query/TextExtractionQueryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message