jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158471 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene: DoubleField.java FieldNames.java LongField.java NamespaceMappings.java NodeIndexer.java SearchIndex.java
Date Mon, 21 Mar 2005 15:53:02 GMT
Author: mreutegg
Date: Mon Mar 21 07:53:00 2005
New Revision: 158471

URL: http://svn.apache.org/viewcvs?view=rev&rev=158471
Log:
- Redesign jackrabbit query handler to allow for better reuse / extension of existing classes.

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/DoubleField.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LongField.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NamespaceMappings.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/DoubleField.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/DoubleField.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/DoubleField.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/DoubleField.java
Mon Mar 21 07:53:00 2005
@@ -21,7 +21,7 @@
  * values into <code>String</code> values that are lexicographically ordered
  * according to the double value.
  */
-class DoubleField {
+public class DoubleField {
 
     private static final long SIGN_MASK = 0x8000000000000000L;
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/FieldNames.java
Mon Mar 21 07:53:00 2005
@@ -20,7 +20,7 @@
  * Defines field names that are used internally to store UUID, etc in the
  * search index.
  */
-class FieldNames {
+public class FieldNames {
 
     /**
      * Name of the field that contains the UUID of the node. Terms are stored

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LongField.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LongField.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LongField.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LongField.java
Mon Mar 21 07:53:00 2005
@@ -18,7 +18,7 @@
 
 /**
  */
-class LongField {
+public class LongField {
 
     private static final int STRING_LONG_LEN
             = Long.toString(Long.MAX_VALUE, Character.MAX_RADIX).length() + 1;
@@ -27,7 +27,7 @@
 
     }
 
-    static String longToString(long value) {
+    public static String longToString(long value) {
         StringBuffer sb = new StringBuffer(STRING_LONG_LEN);
         if (value < 0) {
             // shift value
@@ -58,7 +58,7 @@
         return sb.toString();
     }
 
-    static long stringToLong(String value) {
+    public static long stringToLong(String value) {
         if (value.charAt(0) == '1') {
             // positive
             return Long.parseLong(value.substring(1), Character.MAX_RADIX);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NamespaceMappings.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NamespaceMappings.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NamespaceMappings.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NamespaceMappings.java
Mon Mar 21 07:53:00 2005
@@ -45,7 +45,7 @@
  * prefix is created on the fly and associated with the namespace. Known
  * namespace mappings are stored in a properties file.
  */
-class NamespaceMappings implements NamespaceResolver {
+public class NamespaceMappings implements NamespaceResolver {
 
     /**
      * Default logger instance for this class

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/NodeIndexer.java
Mon Mar 21 07:53:00 2005
@@ -42,22 +42,22 @@
  *
  * todo add support for indexing of nt:resource. e.g. when mime type is text/*
  */
-class NodeIndexer {
+public class NodeIndexer {
 
     /**
      * The <code>NodeState</code> of the node to index
      */
-    private final NodeState node;
+    protected final NodeState node;
     /**
      * The persistent item state provider
      */
-    private final ItemStateManager stateProvider;
+    protected final ItemStateManager stateProvider;
 
     /**
      * Namespace mappings to use for indexing. This is the internal
      * namespace mapping.
      */
-    private final NamespaceMappings mappings;
+    protected final NamespaceMappings mappings;
 
     /**
      * Creates a new node indexer.
@@ -66,7 +66,7 @@
      * @param stateProvider the persistent item state manager to retrieve properties.
      * @param mappings      internal namespace mappings.
      */
-    private NodeIndexer(NodeState node,
+    protected NodeIndexer(NodeState node,
                         ItemStateManager stateProvider,
                         NamespaceMappings mappings) {
         this.node = node;
@@ -99,7 +99,7 @@
      * @throws RepositoryException if an error occurs while reading property
      *                             values from the <code>ItemStateProvider</code>.
      */
-    private Document createDoc() throws RepositoryException {
+    protected Document createDoc() throws RepositoryException {
         Document doc = new Document();
 
         // special fields
@@ -188,93 +188,211 @@
         Object internalValue = value.internalValue();
         switch (value.getType()) {
             case PropertyType.BINARY:
-                // don't know how to index -> ignore
+                addBinaryValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.BOOLEAN:
-                doc.add(new Field(fieldName,
-                        internalValue.toString(),
-                        false,
-                        true,
-                        false));
+                addBooleanValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.DATE:
-                long millis = ((Calendar) internalValue).getTimeInMillis();
-                doc.add(new Field(fieldName,
-                        DateField.timeToString(millis),
-                        false,
-                        true,
-                        false));
+                addCalendarValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.DOUBLE:
-                double doubleVal = ((Double) internalValue).doubleValue();
-                doc.add(new Field(fieldName,
-                        DoubleField.doubleToString(doubleVal),
-                        false,
-                        true,
-                        false));
+                addDoubleValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.LONG:
-                long longVal = ((Long) internalValue).longValue();
-                doc.add(new Field(fieldName,
-                        LongField.longToString(longVal),
-                        false,
-                        true,
-                        false));
+                addLongValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.REFERENCE:
-                String uuid = internalValue.toString();
-                doc.add(new Field(fieldName,
-                        uuid,
-                        true, // store
-                        true,
-                        false));
+                addReferenceValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.PATH:
-                Path path = (Path) internalValue;
-                String pathString = path.toString();
-                try {
-                    pathString = path.toJCRPath(mappings);
-                } catch (NoPrefixDeclaredException e) {
-                    // will never happen
-                }
-                doc.add(new Field(fieldName,
-                        pathString,
-                        false,
-                        true,
-                        false));
+                addPathValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.STRING:
-                // simple String
-                doc.add(new Field(fieldName,
-                        internalValue.toString(),
-                        false,
-                        true,
-                        false));
-                // also create fulltext index of this value
-                doc.add(new Field(FieldNames.FULLTEXT,
-                        internalValue.toString(),
-                        false,
-                        true,
-                        true));
+                addStringValue(doc, fieldName, internalValue);
                 break;
             case PropertyType.NAME:
-                QName qualiName = (QName) internalValue;
-                String normValue = internalValue.toString();
-                try {
-                    normValue = mappings.getPrefix(qualiName.getNamespaceURI())
-                            + ":" + qualiName.getLocalName();
-                } catch (NamespaceException e) {
-                    // will never happen
-                }
-                doc.add(new Field(fieldName,
-                        normValue,
-                        false,
-                        true,
-                        false));
+                addNameValue(doc, fieldName, internalValue);
                 break;
             default:
                 throw new IllegalArgumentException("illegal internal value type");
         }
     }
 
+    /**
+     * Adds the binary value to the document as the named field.
+     * <p>
+     * This implementation does nothing as binary indexing is not implemented
+     * here.
+     * 
+     * @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 addBinaryValue(Document doc, String fieldName, Object internalValue) {
+        // don't know how to index -> ignore
+    }
+    
+    /**
+     * Adds the string representation of the boolean value to the document as
+     * the named field.
+     * 
+     * @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 addBooleanValue(Document doc, String fieldName, Object internalValue)
{
+        doc.add(new Field(fieldName,
+            internalValue.toString(),
+            false,
+            true,
+            false));
+    }
+
+    /**
+     * Adds the calendar value to the document as the named field. The calendar
+     * value is converted to an indexable string value using the {@link DateField}
+     * 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 addCalendarValue(Document doc, String fieldName, Object internalValue)
{
+        long millis = ((Calendar) internalValue).getTimeInMillis();
+        doc.add(new Field(fieldName,
+                DateField.timeToString(millis),
+                false,
+                true,
+                false));
+    }
+    
+    /**
+     * Adds the double value to the document as the named field. The double
+     * value is converted to an indexable string value using the
+     * {@link DoubleField} 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 addDoubleValue(Document doc, String fieldName, Object internalValue) {
+        double doubleVal = ((Double) internalValue).doubleValue();
+        doc.add(new Field(fieldName,
+                DoubleField.doubleToString(doubleVal),
+                false,
+                true,
+                false));
+    }
+    
+    /**
+     * 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 addLongValue(Document doc, String fieldName, Object internalValue) {
+        long longVal = ((Long) internalValue).longValue();
+        doc.add(new Field(fieldName,
+                LongField.longToString(longVal),
+                false,
+                true,
+                false));
+    }
+    
+    /**
+     * 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.
+     * 
+     * @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 addReferenceValue(Document doc, String fieldName, Object internalValue)
{
+        String uuid = internalValue.toString();
+        doc.add(new Field(fieldName,
+                uuid,
+                true, // store
+                true,
+                false));
+    }
+    
+    /**
+     * Adds the path value to the document as the named field. The path
+     * value is converted to an indexable string value using the name space
+     * mappings with which this class has been created.
+     * 
+     * @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 addPathValue(Document doc, String fieldName, Object internalValue) {
+        Path path = (Path) internalValue;
+        String pathString = path.toString();
+        try {
+            pathString = path.toJCRPath(mappings);
+        } catch (NoPrefixDeclaredException e) {
+            // will never happen
+        }
+        doc.add(new Field(fieldName,
+                pathString,
+                false,
+                true,
+                false));
+    }
+
+    /**
+     * Adds the string value to the document both as the named field and for
+     * full text indexing.
+     * 
+     * @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 addStringValue(Document doc, String fieldName, Object internalValue) {
+        String stringValue = String.valueOf(internalValue);
+        
+        // simple String
+        doc.add(new Field(fieldName,
+                stringValue,
+                false,
+                true,
+                false));
+        // also create fulltext index of this value
+        doc.add(new Field(FieldNames.FULLTEXT,
+                stringValue,
+                false,
+                true,
+                true));
+    }
+    
+    /**
+     * Adds the name value to the document as the named field. The name
+     * value is converted to an indexable string treating the internal value
+     * as a qualified name and mapping the name space using the name space
+     * mappings with which this class has been created.
+     * 
+     * @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 addNameValue(Document doc, String fieldName, Object internalValue) {
+        QName qualiName = (QName) internalValue;
+        String normValue = internalValue.toString();
+        try {
+            normValue = mappings.getPrefix(qualiName.getNamespaceURI())
+                    + ":" + qualiName.getLocalName();
+        } catch (NamespaceException e) {
+            // will never happen
+        }
+        doc.add(new Field(fieldName,
+                normValue,
+                false,
+                true,
+                false));
+    }
 }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java?view=diff&r1=158470&r2=158471
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
Mon Mar 21 07:53:00 2005
@@ -180,7 +180,7 @@
      * @throws IOException if an error occurs while adding the node to the index.
      */
     public void addNode(NodeState node) throws RepositoryException, IOException {
-        Document doc = NodeIndexer.createDocument(node, getItemStateProvider(), nsMappings);
+        Document doc = createDocument(node, nsMappings);
         try {
             readWriteLock.writeLock().acquire();
         } catch (InterruptedException e) {
@@ -374,7 +374,7 @@
      */
     private void addNodePersistent(NodeState node)
             throws IOException, RepositoryException {
-        Document doc = NodeIndexer.createDocument(node, getItemStateProvider(), nsMappings);
+        Document doc = createDocument(node, nsMappings);
         persistentIndex.addDocument(doc);
     }
 
@@ -389,6 +389,21 @@
         persistentIndex.removeDocument(idTerm);
     }
 
+    /**
+     * Creates a lucene <code>Document</code> from a node state using the
+     * namespace mappings <code>nsMappings</code>.
+     * @param node the node state to index.
+     * @param nsMappings the namespace mappings of the search index.
+     * @return a lucene <code>Document</code> that contains all properties
+     *  of <code>node</code>.
+     * @throws RepositoryException if an error occurs while indexing the 
+     *  <code>node</code>.
+     */
+    protected Document createDocument(NodeState node, NamespaceMappings nsMappings)
+            throws RepositoryException {
+        return NodeIndexer.createDocument(node, getItemStateProvider(), nsMappings);
+    }
+    
     //--------------------------< properties >----------------------------------
 
     public void setUseCompoundFile(boolean b) {



Mime
View raw message