You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by st...@apache.org on 2009/05/28 11:25:04 UTC

svn commit: r779504 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: DecimalField.java NodeIndexer.java SharedFieldCache.java

Author: stefan
Date: Thu May 28 09:24:59 2009
New Revision: 779504

URL: http://svn.apache.org/viewvc?rev=779504&view=rev
Log:
JCR-1609:  new Property Types (WIP...)



Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DecimalField.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DecimalField.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DecimalField.java?rev=779504&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DecimalField.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DecimalField.java Thu May 28 09:24:59 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query.lucene;
+
+import java.math.BigDecimal;
+
+/**
+ * The <code>DecimalField</code> class is a utility to convert <code>javas.math.BigDecimal</code>
+ * values into <code>String</code> values that are lexicographically ordered
+ * according to the decimal value.
+ *
+ * TODO lexicographical string representation of BigDecimal
+ * see e.g. http://www.mail-archive.com/java-user@lucene.apache.org/msg23632.html
+ */
+public class DecimalField {
+
+    private DecimalField() {
+    }
+
+    public static String decimalToString(BigDecimal value) {
+        // TODO implement
+        throw new UnsupportedOperationException("JCR-1609: new Property Types");
+    }
+
+    public static BigDecimal stringToDecimal(String value) {
+        // TODO implement
+        throw new UnsupportedOperationException("JCR-1609: new Property Types");
+    }
+}

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=779504&r1=779503&r2=779504&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 Thu May 28 09:24:59 2009
@@ -51,6 +51,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.net.URI;
+import java.math.BigDecimal;
 
 /**
  * Creates a lucene <code>Document</code> object from a {@link javax.jcr.Node}.
@@ -362,8 +363,12 @@
                     addNameValue(doc, fieldName, value.getQName());
                 }
                 break;
-            // TODO support indexing of BigDecimal (JCR-1609: new Property Types)
             case PropertyType.DECIMAL:
+                if (isIndexed(name)) {
+                    addDecimalValue(doc, fieldName, value.getDecimal());
+                }
+                break;
+
 
             default:
                 throw new IllegalArgumentException("illegal internal value type: " + value.getType());
@@ -556,6 +561,21 @@
     }
 
     /**
+     * Adds the long value to the document as the named field. The long
+     * value is converted to an indexable string value using the {@link LongField}
+     * class.
+     *
+     * @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.
+     */
+    protected void addDecimalValue(Document doc, String fieldName, Object internalValue) {
+        BigDecimal decVal = (BigDecimal) internalValue;
+        doc.add(createFieldWithoutNorms(fieldName, DecimalField.decimalToString(decVal),
+                PropertyType.DECIMAL));
+    }
+
+    /**
      * Adds the reference value to the document as the named field. The value's
      * string representation is added as the reference data. Additionally the
      * reference data is stored in the index.

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=779504&r1=779503&r2=779504&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java Thu May 28 09:24:59 2009
@@ -270,6 +270,8 @@
                 return new Long(LongField.stringToLong(value));
             case PropertyType.DOUBLE:
                 return new Double(DoubleField.stringToDouble(value));
+            case PropertyType.DECIMAL:
+                return DecimalField.stringToDecimal(value);
             default:
                 return value;
         }