You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by al...@apache.org on 2011/06/05 06:33:38 UTC

svn commit: r1131652 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/lucene/

Author: alexparvulescu
Date: Sun Jun  5 04:33:37 2011
New Revision: 1131652

URL: http://svn.apache.org/viewvc?rev=1131652&view=rev
Log:
JCR-2980 Nodes that have properties marked for async extraction should be available for querying

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java Sun Jun  5 04:33:37 2011
@@ -28,12 +28,15 @@ import java.util.concurrent.CountDownLat
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Fieldable;
 import org.apache.lucene.index.IndexDeletionPolicy;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.Payload;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.store.Directory;
@@ -502,9 +505,14 @@ abstract class AbstractIndex {
                             indexed, tv);
                 } else if (f.isBinary()) {
                     field = new Field(f.name(), f.getBinaryValue(), stored);
-                } else if (f.tokenStreamValue() != null) {
-                    TokenStream ts = f.tokenStreamValue();
-                    field = new Field(f.name(), ts);
+                } else if (f.tokenStreamValue() != null && f.tokenStreamValue() instanceof SingletonTokenStream) {
+                    TokenStream tokenStream = f.tokenStreamValue();
+                    TermAttribute termAttribute = tokenStream.addAttribute(TermAttribute.class);
+                    PayloadAttribute payloadAttribute = tokenStream.addAttribute(PayloadAttribute.class);
+                    tokenStream.incrementToken();
+                    String value = new String(termAttribute.termBuffer(), 0, termAttribute.termLength());
+                    tokenStream.reset();
+                    field = new Field(f.name(), new SingletonTokenStream(value, (Payload) payloadAttribute.getPayload().clone()));
                 }
                 if (field != null) {
                     field.setOmitNorms(f.getOmitNorms());

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java Sun Jun  5 04:33:37 2011
@@ -925,7 +925,7 @@ public class MultiIndex {
      *
      * @throws IOException if the flush fails.
      */
-    void flush() throws IOException {
+    private void flush() throws IOException {
         synchronized (this) {
 
             // only start transaction when there is something to commit
@@ -1276,24 +1276,28 @@ public class MultiIndex {
                 if (redoLog.hasEntries()) {
                     log.debug("Flushing index after being idle for "
                             + idleTime + " ms.");
-                    synchronized (updateMonitor) {
-                        updateInProgress = true;
-                    }
-                    try {
-                        flush();
-                    } finally {
-                        synchronized (updateMonitor) {
-                            updateInProgress = false;
-                            updateMonitor.notifyAll();
-                            releaseMultiReader();
-                        }
-                    }
+                    safeFlush();
                 }
             } catch (IOException e) {
                 log.error("Unable to commit volatile index", e);
             }
         }
     }
+    
+    void safeFlush() throws IOException{
+        synchronized (updateMonitor) {
+            updateInProgress = true;
+        }
+        try {
+            flush();
+        } finally {
+            synchronized (updateMonitor) {
+                updateInProgress = false;
+                updateMonitor.notifyAll();
+                releaseMultiReader();
+            }
+        }
+    }
 
     /**
      * Checks the indexing queue for finished text extrator jobs and updates the

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Recovery.java Sun Jun  5 04:33:37 2011
@@ -167,7 +167,6 @@ class Recovery {
         }
 
         // now we are consistent again -> flush
-        index.flush();
-        index.releaseMultiReader();
+        index.safeFlush();
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Sun Jun  5 04:33:37 2011
@@ -16,6 +16,29 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.InvalidQueryException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -61,40 +84,14 @@ import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.TermQuery;
 import org.apache.tika.config.TikaConfig;
-import org.apache.tika.exception.TikaException;
 import org.apache.tika.fork.ForkParser;
-import org.apache.tika.metadata.Metadata;
 import org.apache.tika.parser.AutoDetectParser;
-import org.apache.tika.parser.ParseContext;
 import org.apache.tika.parser.Parser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
-import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.query.InvalidQueryException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * Implements a {@link org.apache.jackrabbit.core.query.QueryHandler} using
  * Lucene.
@@ -751,7 +748,7 @@ public class SearchIndex extends Abstrac
     public void flush() throws RepositoryException {
         try {
             index.waitUntilIndexingQueueIsEmpty();
-            index.flush();
+            index.safeFlush();
             // flush may have pushed nodes into the indexing queue
             // -> wait again
             index.waitUntilIndexingQueueIsEmpty();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java Sun Jun  5 04:33:37 2011
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.IOException;
+
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
 import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.index.Payload;
 
-import java.io.IOException;
-
 /**
  * <code>SingletonTokenStream</code> implements a token stream that wraps a
  * single value with a given property type. The property type is stored as a
@@ -38,7 +38,7 @@ public final class SingletonTokenStream 
     /**
      * The payload of the token.
      */
-    private final Payload payload;
+    private Payload payload;
 
     /**
      * The term attribute of the current token
@@ -50,11 +50,15 @@ public final class SingletonTokenStream 
      */
     private PayloadAttribute payloadAttribute;
 
+    private boolean consumed = false;
+
     /**
      * Creates a new SingleTokenStream with the given value and payload.
-     *
-     * @param value the string value that will be returned with the token.
-     * @param payload the payload that will be attached to this token
+     * 
+     * @param value
+     *            the string value that will be returned with the token.
+     * @param payload
+     *            the payload that will be attached to this token
      */
     public SingletonTokenStream(String value, Payload payload) {
         this.value = value;
@@ -66,9 +70,11 @@ public final class SingletonTokenStream 
     /**
      * Creates a new SingleTokenStream with the given value and a property
      * <code>type</code>.
-     *
-     * @param value the string value that will be returned with the token.
-     * @param type the JCR property type.
+     * 
+     * @param value
+     *            the string value that will be returned with the token.
+     * @param type
+     *            the JCR property type.
      */
     public SingletonTokenStream(String value, int type) {
         this(value, new Payload(new PropertyMetaData(type).toByteArray()));
@@ -76,15 +82,33 @@ public final class SingletonTokenStream 
 
     @Override
     public boolean incrementToken() throws IOException {
-        if (value == null) {
+        if (consumed) {
             return false;
         }
-
         clearAttributes();
         termAttribute.setTermBuffer(value);
         payloadAttribute.setPayload(payload);
+        consumed = true;
+        return true;
+    }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void reset() throws IOException {
+        consumed = false;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void close() throws IOException {
+        consumed = true;
         value = null;
-        return true;
+        payload = null;
+        payloadAttribute = null;
+        termAttribute = null;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java?rev=1131652&r1=1131651&r2=1131652&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/TestAll.java Sun Jun  5 04:33:37 2011
@@ -42,6 +42,7 @@ public class TestAll extends TestCase {
         suite.addTestSuite(IndexMigrationTest.class);
         suite.addTestSuite(ChainedTermEnumTest.class);
         suite.addTestSuite(IndexingConfigurationImplTest.class);
+        suite.addTestSuite(SQL2IndexingAggregateTest.class);
 
         return suite;
     }