You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2011/04/05 16:05:46 UTC
svn commit: r1089053 -
/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
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. <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()) {
@@ -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) {