jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r538484 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: AbstractExcerpt.java NodeIndexer.java
Date Wed, 16 May 2007 08:49:14 GMT
Author: mreutegg
Date: Wed May 16 01:49:13 2007
New Revision: 538484

URL: http://svn.apache.org/viewvc?view=rev&rev=538484
Log:
JCR-920: rep:excerpt() should also work on properties
- make sure query is rewritten

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java?view=diff&rev=538484&r1=538483&r2=538484
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
Wed May 16 01:49:13 2007
@@ -82,10 +82,7 @@
             throws IOException {
         IndexReader reader = index.getIndexReader();
         try {
-            if (!rewritten) {
-                query = query.rewrite(reader);
-                rewritten = true;
-            }
+            checkRewritten(reader);
             Term idTerm = new Term(FieldNames.UUID, id.getUUID().toString());
             TermDocs tDocs = reader.termDocs(idTerm);
             int docNumber;
@@ -112,6 +109,9 @@
             StringBuffer text = new StringBuffer();
             String separator = "";
             for (int i = 0; i < fields.length; i++) {
+                if (fields[i].stringValue().length() == 0) {
+                    continue;
+                }
                 text.append(separator);
                 text.append(fields[i].stringValue());
                 // this is a hack! in general multiple fields with the same
@@ -155,6 +155,7 @@
      * {@inheritDoc}
      */
     public String highlight(String text) throws IOException {
+        checkRewritten(null);
         return createExcerpt(createTermPositionVector(text),
                 text, 1, (text.length() + 1) * 2);
     }
@@ -196,6 +197,33 @@
             }
         }
         return relevantTerms;
+    }
+
+    /**
+     * Makes sure the {@link #query} is rewritten. If the query is already
+     * rewritten, this method returns immediately.
+     *
+     * @param reader an optional index reader, if none is passed this method
+     *               will retrieve one from the {@link #index} and close it
+     *               again after the rewrite operation.
+     * @throws IOException if an error occurs while the query is rewritten.
+     */
+    private void checkRewritten(IndexReader reader) throws IOException {
+        if (!rewritten) {
+            IndexReader r = reader;
+            if (r == null) {
+                r = index.getIndexReader();
+            }
+            try {
+                query = query.rewrite(r);
+            } finally {
+                // only close reader if this method opened one
+                if (reader == null) {
+                    r.close();
+                }
+            }
+            rewritten = true;
+        }
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?view=diff&rev=538484&r1=538483&r2=538484
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
Wed May 16 01:49:13 2007
@@ -538,6 +538,9 @@
                                   Object internalValue, boolean tokenized,
                                   boolean includeInNodeIndex, float boost) {
         String stringValue = String.valueOf(internalValue);
+        if (stringValue.length() == 0) {
+            return;
+        }
 
         // simple String
         doc.add(new Field(FieldNames.PROPERTIES,



Mime
View raw message