jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r535223 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: DefaultHighlighter.java DefaultXMLExcerpt.java
Date Fri, 04 May 2007 13:02:59 GMT
Author: mreutegg
Date: Fri May  4 06:02:58 2007
New Revision: 535223

URL: http://svn.apache.org/viewvc?view=rev&rev=535223
Log:
JCR-894: rep:excerpt() not working for attribute searches

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultXMLExcerpt.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java?view=diff&rev=535223&r1=535222&r2=535223
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultHighlighter.java
Fri May  4 06:02:58 2007
@@ -20,14 +20,12 @@
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.lucene.document.Field;
 import org.apache.lucene.index.TermPositionVector;
 import org.apache.lucene.index.TermVectorOffsetInfo;
 import org.apache.lucene.index.Term;
-import org.apache.lucene.search.Query;
 import org.apache.jackrabbit.util.Text;
 
 /**
@@ -70,34 +68,29 @@
     }
 
     /**
-     * @param tvec    the term position vector for this hit
-     * @param query   the {@link Query query object} which must already have
-     *                been rewritten into primitive types
-     * @param field   the field name
-     * @param text    the original text that was used to create the tokens.
-     * @param prepend the string used to prepend a highlighted token, for
-     *                example <tt>&quot;&lt;b&gt;&quot;</tt>
-     * @param append  the string used to append a highlighted token, for example
-     *                <tt>&quot;&lt;/b&gt;&quot;</tt>
+     * @param tvec       the term position vector for this hit
+     * @param queryTerms the query terms.
+     * @param text       the original text that was used to create the tokens.
+     * @param prepend    the string used to prepend a highlighted token, for
+     *                   example <tt>&quot;&lt;b&gt;&quot;</tt>
+     * @param append     the string used to append a highlighted token, for
+     *                   example <tt>&quot;&lt;/b&gt;&quot;</tt>
      * @return a String with text fragments where tokens from the query are
      *         highlighted
      */
     public static String highlight(TermPositionVector tvec,
-                                   Query query,
-                                   String field,
+                                   Set queryTerms,
                                    String text,
                                    String prepend,
                                    String append)
             throws IOException {
-        return highlight(tvec, query, field, text, prepend, append,
+        return highlight(tvec, queryTerms, text, prepend, append,
                 DEFAULT_MAXFRAGMENTS, DEFAULT_SURROUND);
     }
 
     /**
      * @param tvec         the term position vector for this hit
-     * @param query        the {@link Query query object} which must already
-     *                     have been rewritten into primitive types
-     * @param field        the field name
+     * @param queryTerms   the query terms.
      * @param text         the original text that was used to create the tokens.
      * @param prepend      the string used to prepend a highlighted token, for
      *                     example <tt>&quot;&lt;b&gt;&quot;</tt>
@@ -110,24 +103,15 @@
      *         highlighted
      */
     public static String highlight(TermPositionVector tvec,
-                                   Query query,
-                                   String field,
+                                   Set queryTerms,
                                    String text,
                                    String prepend,
                                    String append,
                                    int maxFragments,
                                    int surround)
             throws IOException {
-        Set extractedTerms = new HashSet();
-        query.extractTerms(extractedTerms);
-        // only keep terms for given field
-        for (Iterator it = extractedTerms.iterator(); it.hasNext(); ) {
-            if (!((Term) it.next()).field().equals(field)) {
-                it.remove();
-            }
-        }
-        String[] terms = new String[extractedTerms.size()];
-        Iterator it = extractedTerms.iterator();
+        String[] terms = new String[queryTerms.size()];
+        Iterator it = queryTerms.iterator();
         for (int i = 0; it.hasNext(); i++) {
             terms[i] = ((Term) it.next()).text();
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultXMLExcerpt.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultXMLExcerpt.java?view=diff&rev=535223&r1=535222&r2=535223
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultXMLExcerpt.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DefaultXMLExcerpt.java
Fri May  4 06:02:58 2007
@@ -29,6 +29,9 @@
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
 
 /**
  * <code>DefaultXMLExcerpt</code> implements an ExcerptProvider.
@@ -143,7 +146,24 @@
                                  int maxFragments,
                                  int maxFragmentSize)
             throws IOException {
-        return DefaultHighlighter.highlight(tpv, query, FieldNames.FULLTEXT,
-                text, "<highlight>", "</highlight>", maxFragments, maxFragmentSize
/ 2);
+
+        Set extractedTerms = new HashSet();
+        Set relevantTerms = new HashSet();
+        query.extractTerms(extractedTerms);
+        // only keep terms for fulltext fields
+        for (Iterator it = extractedTerms.iterator(); it.hasNext(); ) {
+            Term t = (Term) it.next();
+            if (t.field().equals(FieldNames.FULLTEXT)) {
+                relevantTerms.add(t);
+            } else {
+                int idx = t.field().indexOf(FieldNames.FULLTEXT_PREFIX);
+                if (idx != -1) {
+                    relevantTerms.add(new Term(FieldNames.FULLTEXT, t.text()));
+                }
+            }
+        }
+
+        return DefaultHighlighter.highlight(tpv, relevantTerms, text,
+                "<highlight>", "</highlight>", maxFragments, maxFragmentSize
/ 2);
     }
 }



Mime
View raw message