From commits-return-11002-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Tue Apr 05 14:06:12 2011 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 43539 invoked from network); 5 Apr 2011 14:06:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Apr 2011 14:06:12 -0000 Received: (qmail 23076 invoked by uid 500); 5 Apr 2011 14:06:12 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 22997 invoked by uid 500); 5 Apr 2011 14:06:12 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 22990 invoked by uid 99); 5 Apr 2011 14:06:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Apr 2011 14:06:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Apr 2011 14:06:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0BB1F2388A1C; Tue, 5 Apr 2011 14:05:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1089053 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java Date: Tue, 05 Apr 2011 14:05:46 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110405140547.0BB1F2388A1C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Tue Apr 5 14:05:46 2011 New Revision: 1089053 URL: http://svn.apache.org/viewvc?rev=1089053&view=rev Log: JCR-2917: Indexing configuration ignored when indexing length Patch by Alex Parvulescu Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.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=1089053&r1=1089052&r2=1089053&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 5 14:05:46 2011 @@ -20,7 +20,6 @@ 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; @@ -394,11 +393,31 @@ public class NodeIndexer { 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.
+ * + * Like length 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()) { @@ -544,15 +563,14 @@ public class NodeIndexer { * @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) { try { - doc.add(createFieldWithoutNorms(fieldName, DateField.timeToString(millis), + doc.add(createFieldWithoutNorms(fieldName, + DateField.timeToString(internalValue.getTimeInMillis()), PropertyType.DATE)); } catch (IllegalArgumentException e) { log.warn("'{}' is outside of supported date value range.", - new Date(value.getTimeInMillis())); + internalValue); } } @@ -565,9 +583,8 @@ public class NodeIndexer { * @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)); } @@ -580,9 +597,8 @@ public class NodeIndexer { * @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)); } @@ -595,9 +611,8 @@ public class NodeIndexer { * @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)); } @@ -613,7 +628,7 @@ public class NodeIndexer { * @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) */ - 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)); @@ -636,11 +651,10 @@ public class NodeIndexer { * @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 } @@ -655,9 +669,8 @@ public class NodeIndexer { * @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)); } @@ -671,7 +684,7 @@ public class NodeIndexer { * @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); } @@ -687,7 +700,7 @@ public class NodeIndexer { * 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); } @@ -709,7 +722,7 @@ public class NodeIndexer { * @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); } @@ -733,23 +746,22 @@ public class NodeIndexer { * 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, true, stringValue, Field.Store.NO, + Field f = new Field(fieldName, true, internalValue, Field.Store.NO, Field.Index.ANALYZED, Field.TermVector.NO); f.setBoost(boost); doc.add(f); @@ -757,7 +769,7 @@ public class NodeIndexer { 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 { @@ -777,11 +789,10 @@ public class NodeIndexer { * @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) {