jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1387066 - in /jackrabbit/branches/2.4/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Date Tue, 18 Sep 2012 09:19:46 GMT
Author: alexparvulescu
Date: Tue Sep 18 09:19:46 2012
New Revision: 1387066

URL: http://svn.apache.org/viewvc?rev=1387066&view=rev
Log:
JCR-3428 Partial search terms are no longer highlighted in the excerpts (2.4 backport)

Modified:
    jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
    jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java?rev=1387066&r1=1387065&r2=1387066&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
Tue Sep 18 09:19:46 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import org.apache.jackrabbit.core.query.lucene.WildcardTermEnum.TermValueFactory;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermEnum;
@@ -65,7 +66,7 @@ public class WildcardQuery extends Query
     /**
      * Creates a term value for a given string.
      */
-    private final WildcardTermEnum.TermValueFactory tvf;
+    private final TermValueFactory tvf;
 
     /**
      * The wildcard pattern.
@@ -144,23 +145,9 @@ public class WildcardQuery extends Query
      */
     @Override
     public Query rewrite(IndexReader reader) throws IOException {
-        Query stdWildcardQuery = new MultiTermQuery() {
-            protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
-                return new WildcardTermEnum(reader, field, tvf, pattern, transform);
-            }
-
-            /** Prints a user-readable version of this query. */
-            @Override
-            public String toString(String field) {
-                StringBuffer buffer = new StringBuffer();
-                buffer.append(field);
-                buffer.append(':');
-                buffer.append(ToStringUtils.boost(getBoost()));
-                return buffer.toString();
-            }
-        };
         try {
-            multiTermQuery = stdWildcardQuery.rewrite(reader);
+            multiTermQuery = new StdWildcardQuery(field, tvf, pattern,
+                    transform).rewrite(reader);
             return multiTermQuery;
         } catch (BooleanQuery.TooManyClauses e) {
             // MultiTermQuery not possible
@@ -198,6 +185,39 @@ public class WildcardQuery extends Query
         }
     }
 
+    private static class StdWildcardQuery extends MultiTermQuery {
+
+        private final String field;
+        private final TermValueFactory tvf;
+        private final String pattern;
+        private final int transform;
+
+        public StdWildcardQuery(String field, TermValueFactory tvf,
+                String pattern, int transform) {
+            this.field = field;
+            this.tvf = tvf;
+            this.pattern = pattern;
+            this.transform = transform;
+            setRewriteMethod(SCORING_BOOLEAN_QUERY_REWRITE);
+        }
+
+        @Override
+        protected FilteredTermEnum getEnum(IndexReader reader)
+                throws IOException {
+            return new WildcardTermEnum(reader, field, tvf, pattern, transform);
+        }
+
+        /** Prints a user-readable version of this query. */
+        @Override
+        public String toString(String field) {
+            StringBuffer buffer = new StringBuffer();
+            buffer.append(field);
+            buffer.append(':');
+            buffer.append(ToStringUtils.boost(getBoost()));
+            return buffer.toString();
+        }
+    }
+
     /**
      * The <code>Weight</code> implementation for this <code>WildcardQuery</code>.
      */

Modified: jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java?rev=1387066&r1=1387065&r2=1387066&view=diff
==============================================================================
--- jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
(original)
+++ jackrabbit/branches/2.4/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Tue Sep 18 09:19:46 2012
@@ -239,6 +239,34 @@ public class ExcerptTest extends Abstrac
         checkExcerpt(content, expectedExcerpt, jTest);
     }
 
+    /**
+     * test for https://issues.apache.org/jira/browse/JCR-3428
+     * 
+     * when given an incomplete fulltext search token, the excerpt should
+     * highlight the entire matching token
+     * 
+     */
+    public void testEagerMatch() throws RepositoryException {
+        checkExcerpt("lorem ipsum dolor sit amet",
+                "lorem <strong>ipsum</strong> dolor sit amet", "ipsu*");
+    }
+
+    /**
+     * @see #testEagerMatch()
+     */
+    public void testEagerMatch2() throws RepositoryException {
+        checkExcerpt("lorem ipsum dolor sit amet",
+                "<strong>lorem</strong> <strong>ipsum</strong> dolor
sit amet",
+                "lorem ipsu*");
+    }
+
+    /**
+     * @see #testEagerMatch()
+     */
+    public void testEagerMatch3() throws RepositoryException {
+        checkExcerpt("lorem ipsum dolor sit amet",
+                "lorem <strong>ipsum</strong> <strong>dolor</strong>
sit amet", "ipsu* dolor");
+    }
 
     private void checkExcerpt(String text, String fragmentText, String terms)
             throws RepositoryException {



Mime
View raw message