jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1308833 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java test/java/org/apache/jackrabbit/core/query/IndexingRuleTest.java
Date Tue, 03 Apr 2012 12:06:13 GMT
Author: alexparvulescu
Date: Tue Apr  3 12:06:13 2012
New Revision: 1308833

URL: http://svn.apache.org/viewvc?rev=1308833&view=rev
Log:
JCR-3282 Optimize usage of norms

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

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?rev=1308833&r1=1308832&r2=1308833&view=diff
==============================================================================
--- 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
Tue Apr  3 12:06:13 2012
@@ -62,7 +62,7 @@ public class NodeIndexer {
     /**
      * The default boost for a lucene field: 1.0f.
      */
-    protected static final float DEFAULT_BOOST = 1.0f;
+    protected static final float DEFAULT_BOOST = IndexingConfiguration.DEFAULT_BOOST;
 
     /**
      * The <code>NodeState</code> of the node to index
@@ -733,15 +733,18 @@ public class NodeIndexer {
             int idx = fieldName.indexOf(':');
             fieldName = fieldName.substring(0, idx + 1)
                     + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx + 1);
+            boolean hasNorms = boost != DEFAULT_BOOST;
+            Field.Index indexType = hasNorms ? Field.Index.ANALYZED
+                    : Field.Index.ANALYZED_NO_NORMS;
             Field f = new Field(fieldName, true, internalValue, Field.Store.NO,
-                    Field.Index.ANALYZED, Field.TermVector.NO);
+                    indexType, Field.TermVector.NO);
             f.setBoost(boost);
             doc.add(f);
 
             if (includeInNodeIndex) {
                 // also create fulltext index of this value
                 boolean store = supportHighlighting && useInExcerpt;
-                f = createFulltextField(internalValue, store, supportHighlighting);
+                f = createFulltextField(internalValue, store, supportHighlighting, hasNorms);
                 if (useInExcerpt) {
                     doc.add(f);
                 } else {
@@ -777,7 +780,7 @@ public class NodeIndexer {
      *
      * @param value the string value.
      * @return a lucene field.
-     * @deprecated use {@link #createFulltextField(String, boolean, boolean)} instead.
+     * @deprecated use {@link #createFulltextField(String, boolean, boolean, boolean)} instead.
      */
     protected Field createFulltextField(String value) {
         return createFulltextField(value, supportHighlighting, supportHighlighting);
@@ -785,30 +788,53 @@ public class NodeIndexer {
 
     /**
      * Creates a fulltext field for the string <code>value</code>.
-     *
+     * 
      * @param value the string value.
      * @param store if the value of the field should be stored.
      * @param withOffsets if a term vector with offsets should be stored.
      * @return a lucene field.
+     * @deprecated use {@link #createFulltextField(String, boolean, boolean, boolean)} instead.
      */
     protected Field createFulltextField(String value,
                                         boolean store,
                                         boolean withOffsets) {
+        return createFulltextField(value, store, withOffsets, true);
+    }
+
+    /**
+     * Creates a fulltext field for the string <code>value</code>.
+     *
+     * @param value the string value.
+     * @param store if the value of the field should be stored.
+     * @param withOffsets if a term vector with offsets should be stored.
+     * @param withNorms if norm information should be added for this value
+     * @return a lucene field.
+     */
+    protected Field createFulltextField(String value,
+                                        boolean store,
+                                        boolean withOffsets,
+                                        boolean withNorms) {
         Field.TermVector tv;
         if (withOffsets) {
             tv = Field.TermVector.WITH_OFFSETS;
         } else {
             tv = Field.TermVector.NO;
         }
+        Field.Index index;
+        if (withNorms) {
+            index = Field.Index.ANALYZED;
+        } else {
+            index = Field.Index.ANALYZED_NO_NORMS;
+        }
         if (store) {
             // We would be able to store the field compressed or not depending
             // on a criterion but then we could not determine later is this field
             // has been compressed or not, so we choose to store it uncompressed
             return new Field(FieldNames.FULLTEXT, false, value, Field.Store.YES,
-                    Field.Index.ANALYZED, tv);
+                    index, tv);
         } else {
             return new Field(FieldNames.FULLTEXT, false, value,
-                    Field.Store.NO, Field.Index.ANALYZED, tv);
+                    Field.Store.NO, index, tv);
         }
     }
 

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=1308833&r1=1308832&r2=1308833&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
Tue Apr  3 12:06:13 2012
@@ -16,16 +16,11 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import javax.jcr.RepositoryException;
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
 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;
-import java.util.Arrays;
 
 /**
  * <code>IndexingRuleTest</code> performs indexing rule tests.
@@ -62,16 +57,11 @@ public class IndexingRuleTest extends Ab
         Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
         node3.setProperty("rule", "boost3");
         node3.setProperty("text", TEXT);
-        testRootNode.save();
-        String stmt = "/jcr:root" + testRootNode.getPath() +
-                "/*[jcr:contains(@text, 'quick')] order by @jcr:score descending";
-        List names = new ArrayList();
-        for (NodeIterator it = executeQuery(stmt).getNodes(); it.hasNext(); ) {
-            names.add(it.nextNode().getName());
-        }
-        assertEquals("Wrong sequence or number of results.",
-                Arrays.asList(new String[]{nodeName3, nodeName2, nodeName1}),
-                names);
+        testRootNode.getSession().save();
+        String stmt = "/jcr:root"
+                + testRootNode.getPath()
+                + "/*[jcr:contains(@text, 'quick')] order by @jcr:score descending";
+        executeXPathQuery(stmt, new Node[] { node3, node2, node1 });
     }
 
     public void testNodeScopeIndex() throws RepositoryException {



Mime
View raw message