jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1418236 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Date Fri, 07 Dec 2012 09:43:25 GMT
Author: alexparvulescu
Date: Fri Dec  7 09:43:24 2012
New Revision: 1418236

URL: http://svn.apache.org/viewvc?rev=1418236&view=rev
Log:
JCR-3478 Partial search terms matching fails when there is a lot of matching content outside
the query's scope

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractExcerpt.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.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?rev=1418236&r1=1418235&r2=1418236&view=diff
==============================================================================
--- 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
Fri Dec  7 09:43:24 2012
@@ -40,6 +40,7 @@ import org.apache.lucene.index.TermPosit
 import org.apache.lucene.index.TermVectorOffsetInfo;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -199,7 +200,15 @@ public abstract class AbstractExcerpt im
         q.extractTerms(extractedTerms);
         Set<Term> filteredTerms = filterRelevantTerms(extractedTerms);
         if (!filteredTerms.isEmpty()) {
-            relevantTerms.add(filteredTerms.toArray(new Term[] {}));
+            if (q instanceof PhraseQuery) {
+                // inline the terms, basically a 'must all' condition
+                relevantTerms.add(filteredTerms.toArray(new Term[] {}));
+            } else {
+                // each possible term gets a new slot
+                for (Term t : filteredTerms) {
+                    relevantTerms.add(new Term[] { t });
+                }
+            }
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java?rev=1418236&r1=1418235&r2=1418236&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/ExcerptTest.java
Fri Dec  7 09:43:24 2012
@@ -301,4 +301,36 @@ public class ExcerptTest extends Abstrac
     private String createExcerpt(String fragments) {
         return EXCERPT_START + fragments + EXCERPT_END;
     }
+
+    /**
+     * <p>
+     * Test when there are multiple tokens that match the fulltext search (which
+     * will generate multiple lucene terms for the highlighter to use) in the
+     * repository but not all of them are present in the current property.
+     * </p>
+     * 
+     */
+    public void testMatchMultipleNonMatchingTokens() throws RepositoryException {
+        String text = "lorem ipsum";
+        String fragmentText = "lorem <strong>ipsum</strong>";
+        String terms = "ipsu*";
+
+        String excerpt = createExcerpt(fragmentText);
+
+        // here we'll add more matching garbage data so we have more tokens
+        // passed to the highlighter
+        Node parent = testRootNode.addNode(nodeName1);
+        Node n = parent.addNode("test");
+        n.setProperty("text", text);
+        testRootNode.addNode(nodeName2).setProperty("foo", "ipsuFoo");
+        testRootNode.addNode(nodeName3).setProperty("bar", "ipsuBar");
+        superuser.save();
+        // --
+        String stmt = testPath + "/" + nodeName1 + "//*[jcr:contains(., '"
+                + terms + "')]/rep:excerpt(.)";
+        QueryResult result = executeQuery(stmt);
+        RowIterator rows = result.getRows();
+        assertEquals(1, rows.getSize());
+        assertEquals(excerpt, getExcerpt(rows.nextRow()));
+    }
 }



Mime
View raw message