Index: src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java	(revision 1082945)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java	(working copy)
@@ -16,6 +16,19 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Executor;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
@@ -37,18 +50,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.NamespaceException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Executor;
-
 /**
  * Creates a lucene <code>Document</code> object from a {@link javax.jcr.Node}.
  */
@@ -217,8 +218,9 @@
             // parent UUID
             if (node.getParentId() == null) {
                 // root node
-                doc.add(new Field(FieldNames.PARENT, "", Field.Store.YES,
-                        Field.Index.NOT_ANALYZED_NO_NORMS));
+                doc.add(new Field(FieldNames.PARENT, false, "",
+                        Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS,
+                        Field.TermVector.NO));
                 addNodeName(doc, "", "");
             } else if (node.getSharedSet().isEmpty()) {
                 addParentChildRelation(doc, node.getParentId());
@@ -228,8 +230,9 @@
                     addParentChildRelation(doc, id);
                 }
                 // mark shareable nodes
-                doc.add(new Field(FieldNames.SHAREABLE_NODE, "",
-                        Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+                doc.add(new Field(FieldNames.SHAREABLE_NODE, false, "",
+                        Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
+                        Field.TermVector.NO));
             }
         } catch (NoSuchItemStateException e) {
             throwRepositoryException(e);
@@ -297,7 +300,8 @@
     protected void addMVPName(Document doc, Name name) {
         try {
             String propName = resolver.getJCRName(name);
-            doc.add(new Field(FieldNames.MVP, propName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
+            doc.add(new Field(FieldNames.MVP, false, propName, Field.Store.NO,
+                    Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
         } catch (NamespaceException e) {
             // will never happen, prefixes are created dynamically
         }
@@ -390,14 +394,35 @@
                     addDecimalValue(doc, fieldName, value.getDecimal());
                 }
                 break;
-
-
             default:
                 throw new IllegalArgumentException("illegal internal value type: " + value.getType());
         }
+        addValueProperty(doc, value, name, fieldName);
+    }
+    
+    /**
+     * Adds a property related value to the lucene Document. <br>
+     * 
+     * Like <code>length</code> for indexed fields.
+     * 
+     * @param doc
+     *            the document.
+     * @param value
+     *            the internal jackrabbit value.
+     * @param name
+     *            the name of the property.
+     */
+    protected void addValueProperty(Document doc, InternalValue value,
+            Name name, String fieldName) throws RepositoryException {
+
+        // skip this method if field is not indexed
+        if (!isIndexed(name)) {
+            return;
+        }
 
         // add length
-        if (indexFormatVersion.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+        if (indexFormatVersion.getVersion() >= IndexFormatVersion.V3
+                .getVersion()) {
             addLength(doc, fieldName, value);
         }
     }
@@ -415,7 +440,9 @@
         } catch (NamespaceException e) {
             // will never happen
         }
-        doc.add(new Field(FieldNames.PROPERTIES_SET, fieldName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+        doc.add(new Field(FieldNames.PROPERTIES_SET, false, fieldName,
+                Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
+                Field.TermVector.NO));
     }
 
     /**
@@ -519,7 +546,7 @@
             field.setOmitNorms(true);
             return field;
         } else {
-            return new Field(FieldNames.PROPERTIES,
+            return new Field(FieldNames.PROPERTIES, false,
                     FieldNames.createNamedValue(fieldName, internalValue),
                     Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
                     Field.TermVector.NO);
@@ -538,15 +565,14 @@
      * @param internalValue
      *            The value for the field to add to the document.
      */
-    protected void addCalendarValue(Document doc, String fieldName, Object internalValue) {
-        Calendar value = (Calendar) internalValue;
-        long millis = value.getTimeInMillis();
+    protected void addCalendarValue(Document doc, String fieldName, Calendar internalValue) {
+        long millis = internalValue.getTimeInMillis();
         try {
             doc.add(createFieldWithoutNorms(fieldName, DateField.timeToString(millis),
                     PropertyType.DATE));
         } catch (IllegalArgumentException e) {
             log.warn("'{}' is outside of supported date value range.",
-                    new Date(value.getTimeInMillis()));
+                    new Date(internalValue.getTimeInMillis()));
         }
     }
 
@@ -559,9 +585,8 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addDoubleValue(Document doc, String fieldName, Object internalValue) {
-        double doubleVal = (Double) internalValue;
-        doc.add(createFieldWithoutNorms(fieldName, DoubleField.doubleToString(doubleVal),
+    protected void addDoubleValue(Document doc, String fieldName, double internalValue) {
+        doc.add(createFieldWithoutNorms(fieldName, DoubleField.doubleToString(internalValue),
                 PropertyType.DOUBLE));
     }
 
@@ -574,9 +599,8 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addLongValue(Document doc, String fieldName, Object internalValue) {
-        long longVal = (Long) internalValue;
-        doc.add(createFieldWithoutNorms(fieldName, LongField.longToString(longVal),
+    protected void addLongValue(Document doc, String fieldName, long internalValue) {
+        doc.add(createFieldWithoutNorms(fieldName, LongField.longToString(internalValue),
                 PropertyType.LONG));
     }
 
@@ -589,9 +613,8 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addDecimalValue(Document doc, String fieldName, Object internalValue) {
-        BigDecimal decVal = (BigDecimal) internalValue;
-        doc.add(createFieldWithoutNorms(fieldName, DecimalField.decimalToString(decVal),
+    protected void addDecimalValue(Document doc, String fieldName, BigDecimal internalValue) {
+        doc.add(createFieldWithoutNorms(fieldName, DecimalField.decimalToString(internalValue),
                 PropertyType.DECIMAL));
     }
 
@@ -605,18 +628,19 @@
      * @param doc           The document to which to add the field
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
-     * @param weak          Flag indicating whether it's a WEAKREFERENCE (true) or a REFERENCE (flase)
+     * @param weak          Flag indicating whether it's a WEAKREFERENCE (true) or a REFERENCE (false)
      */
-    protected void addReferenceValue(Document doc, String fieldName, Object internalValue, boolean weak) {
+    protected void addReferenceValue(Document doc, String fieldName, NodeId internalValue, boolean weak) {
         String uuid = internalValue.toString();
         doc.add(createFieldWithoutNorms(fieldName, uuid,
                 weak ? PropertyType.WEAKREFERENCE : PropertyType.REFERENCE));
-        doc.add(new Field(FieldNames.PROPERTIES,
-                FieldNames.createNamedValue(fieldName, uuid),
-                Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
+        doc.add(new Field(FieldNames.PROPERTIES, false, FieldNames
+                .createNamedValue(fieldName, uuid), Field.Store.YES,
+                Field.Index.NO, Field.TermVector.NO));
         if (weak) {
-            doc.add(new Field(FieldNames.WEAK_REFS, uuid, Field.Store.NO,
-                    Field.Index.NOT_ANALYZED_NO_NORMS));
+            doc.add(new Field(FieldNames.WEAK_REFS, false, uuid,
+                    Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
+                    Field.TermVector.NO));
         }
     }
 
@@ -629,11 +653,10 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addPathValue(Document doc, String fieldName, Object internalValue) {
-        Path path = (Path) internalValue;
-        String pathString = path.toString();
+    protected void addPathValue(Document doc, String fieldName, Path internalValue) {
+        String pathString = internalValue.toString();
         try {
-            pathString = resolver.getJCRPath(path);
+            pathString = resolver.getJCRPath(internalValue);
         } catch (NamespaceException e) {
             // will never happen
         }
@@ -648,9 +671,8 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addURIValue(Document doc, String fieldName, Object internalValue) {
-        URI uri = (URI) internalValue;
-        doc.add(createFieldWithoutNorms(fieldName, uri.toString(),
+    protected void addURIValue(Document doc, String fieldName, URI internalValue) {
+        doc.add(createFieldWithoutNorms(fieldName, internalValue.toString(),
                 PropertyType.URI));
     }
 
@@ -664,7 +686,7 @@
      * @deprecated Use {@link #addStringValue(Document, String, Object, boolean)
      *             addStringValue(Document, String, Object, boolean)} instead.
      */
-    protected void addStringValue(Document doc, String fieldName, Object internalValue) {
+    protected void addStringValue(Document doc, String fieldName, String internalValue) {
         addStringValue(doc, fieldName, internalValue, true, true, DEFAULT_BOOST, true);
     }
 
@@ -680,7 +702,7 @@
      *                      and fulltext indexed.
      */
     protected void addStringValue(Document doc, String fieldName,
-                                  Object internalValue, boolean tokenized) {
+                                  String internalValue, boolean tokenized) {
         addStringValue(doc, fieldName, internalValue, tokenized, true, DEFAULT_BOOST, true);
     }
 
@@ -702,7 +724,7 @@
      * @deprecated use {@link #addStringValue(Document, String, Object, boolean, boolean, float, boolean)} instead.
      */
     protected void addStringValue(Document doc, String fieldName,
-                                  Object internalValue, boolean tokenized,
+                                  String internalValue, boolean tokenized,
                                   boolean includeInNodeIndex, float boost) {
         addStringValue(doc, fieldName, internalValue, tokenized, includeInNodeIndex, boost, true);
     }
@@ -726,33 +748,28 @@
      *                           an excerpt.
      */
     protected void addStringValue(Document doc, String fieldName,
-                                  Object internalValue, boolean tokenized,
+                                  String internalValue, boolean tokenized,
                                   boolean includeInNodeIndex, float boost,
                                   boolean useInExcerpt) {
-
-        // simple String
-        String stringValue = (String) internalValue;
-        doc.add(createFieldWithoutNorms(fieldName, stringValue,
+        doc.add(createFieldWithoutNorms(fieldName, internalValue,
                 PropertyType.STRING));
         if (tokenized) {
-            if (stringValue.length() == 0) {
+            if (internalValue.length() == 0) {
                 return;
             }
             // create fulltext index on property
             int idx = fieldName.indexOf(':');
             fieldName = fieldName.substring(0, idx + 1)
                     + FieldNames.FULLTEXT_PREFIX + fieldName.substring(idx + 1);
-            Field f = new Field(fieldName, stringValue,
-                    Field.Store.NO,
-                    Field.Index.ANALYZED,
-                    Field.TermVector.NO);
+            Field f = new Field(fieldName, true, internalValue, Field.Store.NO,
+                    Field.Index.ANALYZED, Field.TermVector.NO);
             f.setBoost(boost);
             doc.add(f);
 
             if (includeInNodeIndex) {
                 // also create fulltext index of this value
                 boolean store = supportHighlighting && useInExcerpt;
-                f = createFulltextField(stringValue, store, supportHighlighting);
+                f = createFulltextField(internalValue, store, supportHighlighting);
                 if (useInExcerpt) {
                     doc.add(f);
                 } else {
@@ -772,11 +789,10 @@
      * @param fieldName     The name of the field to add
      * @param internalValue The value for the field to add to the document.
      */
-    protected void addNameValue(Document doc, String fieldName, Object internalValue) {
+    protected void addNameValue(Document doc, String fieldName, Name internalValue) {
         try {
-            Name qualiName = (Name) internalValue;
-            String normValue = mappings.getPrefix(qualiName.getNamespaceURI())
-                    + ":" + qualiName.getLocalName();
+            String normValue = mappings.getPrefix(internalValue.getNamespaceURI())
+                    + ":" + internalValue.getLocalName();
             doc.add(createFieldWithoutNorms(fieldName, normValue,
                     PropertyType.NAME));
         } catch (NamespaceException e) {
@@ -816,10 +832,10 @@
             // 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, value, Field.Store.YES,
+            return new Field(FieldNames.FULLTEXT, false, value, Field.Store.YES,
                     Field.Index.ANALYZED, tv);
         } else {
-            return new Field(FieldNames.FULLTEXT, value,
+            return new Field(FieldNames.FULLTEXT, false, value,
                     Field.Store.NO, Field.Index.ANALYZED, tv);
         }
     }
@@ -924,9 +940,9 @@
                              InternalValue value) {
         long length = Util.getLength(value);
         if (length != -1) {
-            doc.add(new Field(FieldNames.PROPERTY_LENGTHS,
-                    FieldNames.createNamedLength(propertyName, length),
-                    Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+            doc.add(new Field(FieldNames.PROPERTY_LENGTHS, false, FieldNames
+                    .createNamedLength(propertyName, length), Field.Store.NO,
+                    Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
         }
     }
 
@@ -942,11 +958,16 @@
                                String namespaceURI,
                                String localName) throws NamespaceException {
         String name = mappings.getPrefix(namespaceURI) + ":" + localName;
-        doc.add(new Field(FieldNames.LABEL, name, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+        doc.add(new Field(FieldNames.LABEL, false, name, Field.Store.NO,
+                Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
         // as of version 3, also index combination of namespace URI and local name
         if (indexFormatVersion.getVersion() >= IndexFormatVersion.V3.getVersion()) {
-            doc.add(new Field(FieldNames.NAMESPACE_URI, namespaceURI, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
-            doc.add(new Field(FieldNames.LOCAL_NAME, localName, Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+            doc.add(new Field(FieldNames.NAMESPACE_URI, false, namespaceURI,
+                    Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
+                    Field.TermVector.NO));
+            doc.add(new Field(FieldNames.LOCAL_NAME, false, localName,
+                    Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS,
+                    Field.TermVector.NO));
         }
     }
 
@@ -962,9 +983,9 @@
     protected void addParentChildRelation(Document doc,
                                           NodeId parentId)
             throws ItemStateException, RepositoryException {
-        doc.add(new Field(
-                FieldNames.PARENT, parentId.toString(),
-                Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
+        doc.add(new Field(FieldNames.PARENT, false, parentId.toString(),
+                Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS,
+                Field.TermVector.NO));
         NodeState parent = (NodeState) stateProvider.getItemState(parentId);
         ChildNodeEntry child = parent.getChildNodeEntry(node.getNodeId());
         if (child == null) {
