jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r924238 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/ test/repository/workspaces/indexing-test/
Date Wed, 17 Mar 2010 11:47:22 GMT
Author: mreutegg
Date: Wed Mar 17 11:47:22 2010
New Revision: 924238

URL: http://svn.apache.org/viewvc?rev=924238&view=rev
Log:
JCR-2575: Incorrect excerpt for index aggregates

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml

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=924238&r1=924237&r2=924238&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
Wed Mar 17 11:47:22 2010
@@ -22,6 +22,7 @@ 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;
@@ -1348,6 +1349,18 @@ public class SearchIndex extends Abstrac
                                 doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, aggregate.getNodeId().toString(),
Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                             }
                         }
+                        // make sure that fulltext fields are aligned properly
+                        // first all stored fields, then remaining
+                        List<Fieldable> fulltextFields = new ArrayList<Fieldable>();
+                        fulltextFields.addAll(removeFields(doc, FieldNames.FULLTEXT));
+                        Collections.sort(fulltextFields, new Comparator<Fieldable>()
{
+                            public int compare(Fieldable o1, Fieldable o2) {
+                                return Boolean.valueOf(o2.isStored()).compareTo(o1.isStored());
+                            }
+                        });
+                        for (Fieldable f : fulltextFields) {
+                            doc.add(f);
+                        }
                     }
                     // property includes
                     PropertyState[] propStates = aggregateRule.getAggregatedPropertyStates(state);
@@ -1397,6 +1410,22 @@ public class SearchIndex extends Abstrac
     }
 
     /**
+     * Removes the fields with the given <code>name</code> from the
+     * <code>document</code> and returns them in a collection.
+     *
+     * @param document the document.
+     * @param name     the name of the fields to remove.
+     * @return the removed fields.
+     */
+    protected final Collection<Fieldable> removeFields(Document document,
+                                                 String name) {
+        List<Fieldable> fields = new ArrayList<Fieldable>();
+        fields.addAll(Arrays.asList(document.getFieldables(name)));
+        document.removeFields(FieldNames.FULLTEXT);
+        return fields;
+    }
+
+    /**
      * Returns the relative path from <code>nodeState</code> to
      * <code>propState</code>.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java?rev=924238&r1=924237&r2=924238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
Wed Mar 17 11:47:22 2010
@@ -21,6 +21,7 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Value;
 import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
 import java.util.List;
 import java.util.ArrayList;
@@ -136,4 +137,51 @@ public class IndexingRuleTest extends Ab
         Value excerpt = result.getRows().nextRow().getValue("rep:excerpt(.)");
         assertNotNull("No excerpt created", excerpt);
     }
+
+    public void testUseInExcerptWithAggregate() throws RepositoryException {
+        Node node = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
+        node.setProperty("rule", "excerpt");
+        node.setProperty("title", "Apache Jackrabbit");
+        node.setProperty("text", "Jackrabbit is a JCR implementation");
+        Node aggregated = node.addNode("aggregated-node", NT_UNSTRUCTURED);
+        aggregated.setProperty("rule", "excerpt");
+        aggregated.setProperty("title", "Apache Jackrabbit");
+        aggregated.setProperty("text", "Jackrabbit is a JCR implementation");
+        testRootNode.save();
+
+        String stmt = "/jcr:root" + testRootNode.getPath() +
+                "/*[jcr:contains(., 'jackrabbit')]/rep:excerpt(.)";
+        RowIterator rows = executeQuery(stmt).getRows();
+        assertTrue("No results returned", rows.hasNext());
+        Value excerpt;
+        while (rows.hasNext()) {
+            excerpt = rows.nextRow().getValue("rep:excerpt(.)");
+            assertNotNull("No excerpt created", excerpt);
+            assertTrue("Title must not be present in excerpt",
+                    excerpt.getString().indexOf("Apache") == -1);
+            int idx = 0;
+            int numHighlights = 0;
+            for (;;) {
+                idx = excerpt.getString().indexOf("<strong>", idx);
+                if (idx == -1) {
+                    break;
+                }
+                numHighlights++;
+                int endIdx = excerpt.getString().indexOf("</strong>", idx);
+                assertEquals("wrong highlight", "Jackrabbit",
+                        excerpt.getString().substring(idx + "<strong>".length(), endIdx));
+                idx = endIdx;
+            }
+            assertTrue("Missing highlight", numHighlights > 0);
+        }
+
+        stmt = "/jcr:root" + testRootNode.getPath() +
+                "/*[jcr:contains(., 'apache')]/rep:excerpt(.)";
+        rows = executeQuery(stmt).getRows();
+        assertTrue("No results returned", rows.hasNext());
+        excerpt = rows.nextRow().getValue("rep:excerpt(.)");
+        assertNotNull("No excerpt created", excerpt);
+        assertTrue("Title must not be present in excerpt",
+                excerpt.getString().indexOf("Apache") == -1);
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml?rev=924238&r1=924237&r2=924238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/indexing-test/indexing-configuration.xml
Wed Mar 17 11:47:22 2010
@@ -48,6 +48,7 @@
     </aggregate>
 
     <aggregate primaryType="nt:unstructured">
+        <include>aggregated-node</include>
         <include-property>child/property</include-property>
     </aggregate>
 



Mime
View raw message