jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1128329 - in /jackrabbit/branches/2.2/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/ test/java/org/apache/jackrabbit/core/query/lucene/
Date Fri, 27 May 2011 14:45:30 GMT
Author: alexparvulescu
Date: Fri May 27 14:45:30 2011
New Revision: 1128329

URL: http://svn.apache.org/viewvc?rev=1128329&view=rev
Log:
2.2: merged revision r1128325 (JCR-2980)

Added:
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
  (with props)
Modified:
    jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=1128329&r1=1128328&r2=1128329&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
Fri May 27 14:45:30 2011
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Fieldable;
@@ -509,6 +510,9 @@ abstract class AbstractIndex {
                             stored, indexed, tv);
                 } else if (f.isBinary()) {
                     field = new Field(f.name(), f.binaryValue(), stored);
+                } else if (f.tokenStreamValue() != null) {
+                    TokenStream ts = f.tokenStreamValue();
+                    field = new Field(f.name(), ts);
                 }
                 if (field != null) {
                     field.setOmitNorms(f.getOmitNorms());

Modified: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java?rev=1128329&r1=1128328&r2=1128329&view=diff
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
(original)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/AbstractQueryTest.java
Fri May 27 14:45:30 2011
@@ -263,6 +263,13 @@ public class AbstractQueryTest extends A
         return qm.createQuery(statement, JCR_SQL2).execute();
     }
 
+    protected void executeSQL2Query(String statement, Node[] nodes)
+            throws RepositoryException {
+        getSearchIndex().flush();
+        QueryResult res = qm.createQuery(statement, JCR_SQL2).execute();
+        checkResult(res, nodes);
+    }
+
     /**
      * Returns a reference to the underlying search index.
      *

Added: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java?rev=1128329&view=auto
==============================================================================
--- jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
(added)
+++ jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
Fri May 27 14:45:30 2011
@@ -0,0 +1,131 @@
+/*
+ * 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.core.query.lucene;
+
+import static javax.jcr.query.Query.JCR_SQL2;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Calendar;
+
+import javax.jcr.Node;
+
+import org.apache.commons.io.input.NullInputStream;
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.apache.jackrabbit.core.query.AbstractIndexingTest;
+
+/**
+ * <code>IndexingAggregateTest</code> checks if the nt:file nt:resource
+ * aggregate defined in workspace indexing-test works properly.
+ */
+public class SQL2IndexingAggregateTest extends AbstractIndexingTest {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        for (Node c : JcrUtils.getChildNodes(testRootNode)) {
+            testRootNode.getSession().removeItem(c.getPath());
+        }
+        testRootNode.getSession().save();
+    }
+
+    public void testNtFileAggregate() throws Exception {
+
+        String sqlBase = "SELECT * FROM [nt:file] as f"
+                + " WHERE ISCHILDNODE([" + testRoot + "])";
+        String sqlCat = sqlBase + " AND CONTAINS (f.*, 'cat')";
+        String sqlDog = sqlBase + " AND CONTAINS (f.*, 'dog')";
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        Writer writer = new OutputStreamWriter(out, "UTF-8");
+        writer.write("the quick brown fox jumps over the lazy dog.");
+        writer.flush();
+
+        Node file = testRootNode.addNode("myFile", "nt:file");
+        Node resource = file.addNode("jcr:content", "nt:resource");
+        resource.setProperty("jcr:lastModified", Calendar.getInstance());
+        resource.setProperty("jcr:encoding", "UTF-8");
+        resource.setProperty("jcr:mimeType", "text/plain");
+        resource.setProperty("jcr:data", session.getValueFactory()
+                .createBinary(new ByteArrayInputStream(out.toByteArray())));
+        testRootNode.getSession().save();
+        executeSQL2Query(sqlDog, new Node[] { file });
+
+        // update jcr:data
+        out.reset();
+        writer.write("the quick brown fox jumps over the lazy cat.");
+        writer.flush();
+        resource.setProperty("jcr:data", session.getValueFactory()
+                .createBinary(new ByteArrayInputStream(out.toByteArray())));
+        testRootNode.getSession().save();
+        executeSQL2Query(sqlCat, new Node[] { file });
+
+        // replace jcr:content with unstructured
+        resource.remove();
+        Node unstrContent = file.addNode("jcr:content", "nt:unstructured");
+        Node foo = unstrContent.addNode("foo");
+        foo.setProperty("text", "the quick brown fox jumps over the lazy dog.");
+        testRootNode.getSession().save();
+        executeSQL2Query(sqlDog, new Node[] { file });
+
+        // remove foo
+        foo.remove();
+        testRootNode.getSession().save();
+
+        executeSQL2Query(sqlDog, new Node[] {});
+
+        // replace jcr:content again with resource
+        unstrContent.remove();
+        resource = file.addNode("jcr:content", "nt:resource");
+        resource.setProperty("jcr:lastModified", Calendar.getInstance());
+        resource.setProperty("jcr:encoding", "UTF-8");
+        resource.setProperty("jcr:mimeType", "text/plain");
+        resource.setProperty("jcr:data", session.getValueFactory()
+                .createBinary(new ByteArrayInputStream(out.toByteArray())));
+        testRootNode.getSession().save();
+        executeSQL2Query(sqlCat, new Node[] { file });
+
+    }
+
+    /**
+     * checks that while text extraction runs in the background, the node is
+     * available for query on any of its properties
+     * 
+     * see <a href="https://issues.apache.org/jira/browse/JCR-2980">JCR-2980</a>
+     * 
+     */
+    public void testAsyncIndexQuery() throws Exception {
+
+        Node n = testRootNode.addNode("justnode", JcrConstants.NT_UNSTRUCTURED);
+        n.setProperty("type", "testnode");
+        n.setProperty("jcr:encoding", "UTF-8");
+        n.setProperty("jcr:mimeType", "text/plain");
+        n.setProperty(
+                "jcr:data",
+                session.getValueFactory().createBinary(
+                        new NullInputStream(1024 * 40)));
+        testRootNode.getSession().save();
+
+        String sql = "SELECT * FROM [nt:unstructured] as f "
+                + " WHERE ISCHILDNODE([" + testRoot
+                + "]) and type = 'testnode' ";
+        checkResult(qm.createQuery(sql, JCR_SQL2).execute(), 1);
+    }
+}

Propchange: jackrabbit/branches/2.2/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SQL2IndexingAggregateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message