jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r350022 - in /incubator/jackrabbit/trunk/jackrabbit/src/main: config/ java/org/apache/jackrabbit/core/ java/org/apache/jackrabbit/core/query/ java/org/apache/jackrabbit/core/query/lucene/
Date Wed, 30 Nov 2005 19:12:02 GMT
Author: mreutegg
Date: Wed Nov 30 11:11:47 2005
New Revision: 350022

URL: http://svn.apache.org/viewcvs?rev=350022&view=rev
Log:
Open up some access modifiers to allow for better extension of the default query handler.

Added:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHits.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml (original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/config/repository.xml Wed Nov 30 11:11:47
2005
@@ -212,6 +212,8 @@
             - autoRepair: errors detected by a consistency check are automatically
               repaired. If false, errors are only written to the log.
             - analyzer: class name of a lucene analyzer to use for fulltext indexing of text.
+            - queryClass: class name that implements the javax.jcr.query.Query interface.
+              this class must extend the class: org.apache.jackrabbit.core.query.AbstractQueryImpl
 
             Note: all parameters (except path) in this SearchIndex config are default
             values and can be omitted.
@@ -228,6 +230,7 @@
             <param name="forceConsistencyCheck" value="false"/>
             <param name="autoRepair" value="true"/>
             <param name="analyzer" value="org.apache.lucene.analysis.standard.StandardAnalyzer"/>
+            <param name="queryClass" value="org.apache.jackrabbit.core.query.QueryImpl"/>
         </SearchIndex>
     </Workspace>
 

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Wed Nov 30 11:11:47 2005
@@ -26,6 +26,7 @@
 import org.apache.jackrabbit.core.query.QueryHandler;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.QueryImpl;
+import org.apache.jackrabbit.core.query.AbstractQueryImpl;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.ItemState;
@@ -71,6 +72,16 @@
     public static final String NS_XS_URI = "http://www.w3.org/2001/XMLSchema";
 
     /**
+     * Name of the parameter that indicates the query implementation class.
+     */
+    private static final String PARAM_QUERY_IMPL = "queryClass";
+
+    /**
+     * Name of the default query implementation class.
+     */
+    private static final String DEFAULT_QUERY_IMPL_CLASS = QueryImpl.class.getName();
+
+    /**
      * The shared item state manager instance for the workspace.
      */
     private final ItemStateManager itemMgr;
@@ -86,6 +97,12 @@
     private final QueryHandler handler;
 
     /**
+     * Fully qualified name of the query implementation class.
+     * This class must extend {@link org.apache.jackrabbit.core.query.AbstractQueryImpl}!
+     */
+    private final String queryImplClassName;
+
+    /**
      * Creates a new <code>SearchManager</code>.
      * @param session the system session.
      * @param config the search configuration.
@@ -115,6 +132,8 @@
             nsReg.registerNamespace(NS_FN_PREFIX, NS_FN_URI);
         }
 
+        queryImplClassName = config.getParameters().getProperty(PARAM_QUERY_IMPL, DEFAULT_QUERY_IMPL_CLASS);
+
         // initialize query handler
         try {
             handler = (QueryHandler) config.newInstance();
@@ -162,7 +181,9 @@
                              String statement,
                              String language)
             throws InvalidQueryException, RepositoryException {
-        return new QueryImpl(session, itemMgr, handler, statement, language);
+        AbstractQueryImpl query = createQueryInstance();
+        query.init(session, itemMgr, handler, statement, language);
+        return query;
     }
 
     /**
@@ -181,7 +202,9 @@
                              ItemManager itemMgr,
                              Node node)
             throws InvalidQueryException, RepositoryException {
-        return new QueryImpl(session, itemMgr, handler, node);
+        AbstractQueryImpl query = createQueryInstance();
+        query.init(session, itemMgr, handler, node);
+        return query;
     }
 
     //---------------< EventListener interface >--------------------------------
@@ -259,4 +282,25 @@
         }
     }
 
+    /**
+     * Creates a new instance of an {@link AbstractQueryImpl} which is not
+     * initialized.
+     *
+     * @return an new query instance.
+     * @throws RepositoryException if an error occurs while creating a new query
+     *                             instance.
+     */
+    protected AbstractQueryImpl createQueryInstance() throws RepositoryException {
+        try {
+            Object obj = Class.forName(queryImplClassName).newInstance();
+            if (obj instanceof AbstractQueryImpl) {
+                return (AbstractQueryImpl) obj;
+            } else {
+                throw new IllegalArgumentException(queryImplClassName +
+                        " is not of type " + AbstractQueryImpl.class.getName());
+            }
+        } catch (Throwable t) {
+            throw new RepositoryException("Unable to create query: " + t.toString());
+        }
+    }
 }

Added: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java?rev=350022&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
(added)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
Wed Nov 30 11:11:47 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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;
+
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.ItemManager;
+
+import javax.jcr.query.Query;
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+/**
+ * Defines common initialization methods for all query implementations.
+ */
+public abstract class AbstractQueryImpl implements Query {
+
+    /**
+     * Initializes a query instance from a query string.
+     *
+     * @param session   the session of the user executing this query.
+     * @param itemMgr   the item manager of the session executing this query.
+     * @param handler   the query handler of the search index.
+     * @param statement the query statement.
+     * @param language  the syntax of the query statement.
+     * @throws InvalidQueryException if the query statement is invalid according
+     *                               to the specified <code>language</code>.
+     */
+    public abstract void init(SessionImpl session,
+                              ItemManager itemMgr,
+                              QueryHandler handler,
+                              String statement,
+                              String language) throws InvalidQueryException;
+
+    /**
+     * Initializes a query instance from a nt:query node.
+     *
+     * @param session the session of the user executing this query.
+     * @param itemMgr the item manager of the session executing this query.
+     * @param handler the query handler of the search index.
+     * @param node    a node of type <code>nt:query</code>.
+     * @throws InvalidQueryException If <code>node</code> is not a valid persisted
query
+     *                               (that is, a node of type <code>nt:query</code>).
+     * @throws RepositoryException   if another error occurs
+     */
+    public abstract void init(SessionImpl session,
+                              ItemManager itemMgr,
+                              QueryHandler handler,
+                              Node node)
+            throws InvalidQueryException, RepositoryException;
+}

Propchange: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
Wed Nov 30 11:11:47 2005
@@ -33,82 +33,79 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.InvalidQueryException;
-import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 import javax.jcr.version.VersionException;
 
 /**
- * Implements the {@link Query} interface.
+ * Provides the default implementation for a JCR query.
  */
-public class QueryImpl implements Query {
+public class QueryImpl extends AbstractQueryImpl {
 
     /**
      * The session of the user executing this query
      */
-    private final SessionImpl session;
+    protected SessionImpl session;
 
     /**
      * The query statement
      */
-    private final String statement;
+    protected String statement;
 
     /**
      * The syntax of the query statement
      */
-    private final String language;
+    protected String language;
 
     /**
      * The actual query implementation that can be executed
      */
-    private final ExecutableQuery query;
+    protected ExecutableQuery query;
 
     /**
      * The node where this query is persisted. Only set when this is a persisted
      * query.
      */
-    private Node node;
+    protected Node node;
 
     /**
-     * Creates a new query instance from a query string.
-     *
-     * @param session   the session of the user executing this query.
-     * @param itemMgr   the item manager of the session executing this query.
-     * @param handler   the query handler of the search index.
-     * @param statement the query statement.
-     * @param language  the syntax of the query statement.
-     * @throws InvalidQueryException if the query statement is invalid according
-     *                               to the specified <code>language</code>.
+     * The query handler for this query.
      */
-    public QueryImpl(SessionImpl session,
+    protected QueryHandler handler;
+
+    /**
+     * Flag indicating whether this query is initialized.
+     */
+    private boolean initialized = false;
+
+    /**
+     * @inheritDoc
+     */
+    public void init(SessionImpl session,
                      ItemManager itemMgr,
                      QueryHandler handler,
                      String statement,
                      String language) throws InvalidQueryException {
+        checkNotInitialized();
         this.session = session;
         this.statement = statement;
         this.language = language;
+        this.handler = handler;
         this.query = handler.createExecutableQuery(session, itemMgr, statement, language);
+        initialized = true;
     }
 
     /**
-     * Create a new query instance from a nt:query node.
-     *
-     * @param session the session of the user executing this query.
-     * @param itemMgr the item manager of the session executing this query.
-     * @param handler the query handler of the search index.
-     * @param node    a node of type <code>nt:query</code>.
-     * @throws InvalidQueryException If <code>node</code> is not a valid persisted
query
-     *                               (that is, a node of type <code>nt:query</code>).
-     * @throws RepositoryException   if another error occurs
+     * @inheritDoc
      */
-    public QueryImpl(SessionImpl session,
+    public void init(SessionImpl session,
                      ItemManager itemMgr,
                      QueryHandler handler,
                      Node node)
             throws InvalidQueryException, RepositoryException {
-
+        checkNotInitialized();
         this.session = session;
         this.node = node;
+        this.handler = handler;
 
         try {
             if (!node.isNodeType(QName.NT_QUERY.toJCRName(session.getNamespaceResolver())))
{
@@ -120,6 +117,7 @@
         } catch (NoPrefixDeclaredException e) {
             throw new RepositoryException(e.getMessage(), e);
         }
+        initialized = true;
     }
 
     /**
@@ -129,6 +127,7 @@
      * {@inheritDoc}
      */
     public QueryResult execute() throws RepositoryException {
+        checkInitialized();
         return query.execute();
     }
 
@@ -136,6 +135,7 @@
      * {@inheritDoc}
      */
     public String getStatement() {
+        checkInitialized();
         return statement;
     }
 
@@ -143,6 +143,7 @@
      * {@inheritDoc}
      */
     public String getLanguage() {
+        checkInitialized();
         return language;
     }
 
@@ -151,6 +152,7 @@
      */
     public String getStoredQueryPath()
             throws ItemNotFoundException, RepositoryException {
+        checkInitialized();
         if (node == null) {
             throw new ItemNotFoundException("not a persistent query");
         }
@@ -168,6 +170,8 @@
             LockException,
             UnsupportedRepositoryOperationException,
             RepositoryException {
+
+        checkInitialized();
         try {
             NamespaceResolver resolver = session.getNamespaceResolver();
             Path p = Path.create(absPath, resolver, true);
@@ -192,6 +196,28 @@
             throw new RepositoryException(e.getMessage(), e);
         } catch (NoPrefixDeclaredException e) {
             throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    //-----------------------------< internal >---------------------------------
+
+    /**
+     * Checks if this query is not yet initialized and throws an
+     * <code>IllegalStateException</code> if it is already initialized.
+     */
+    protected void checkNotInitialized() {
+        if (initialized) {
+            throw new IllegalStateException("already initialized");
+        }
+    }
+
+    /**
+     * Checks if this query is initialized and throws an
+     * <code>IllegalStateException</code> if it is not yet initialized.
+     */
+    protected void checkInitialized() {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
         }
     }
 }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Wed Nov 30 11:11:47 2005
@@ -70,7 +70,7 @@
  * on an index.
  * todo introduce a node type hierarchy for efficient translation of NodeTypeQueryNode
  */
-class LuceneQueryBuilder implements QueryNodeVisitor {
+public class LuceneQueryBuilder implements QueryNodeVisitor {
 
     /**
      * Logger for this class

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Wed Nov 30 11:11:47 2005
@@ -69,7 +69,7 @@
  * thread and reader threads is done using {@link #updateMonitor} and
  * {@link #updateInProgress}.
  */
-class MultiIndex {
+public class MultiIndex {
 
     /**
      * The logger instance for this class
@@ -531,7 +531,7 @@
      * @return an <code>IndexReader</code>.
      * @throws IOException if an error occurs constructing the <code>IndexReader</code>.
      */
-    IndexReader getIndexReader() throws IOException {
+    public IndexReader getIndexReader() throws IOException {
         synchronized (updateMonitor) {
             if (multiReader != null) {
                 multiReader.incrementRefCount();

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHits.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHits.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHits.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHits.java
Wed Nov 30 11:11:47 2005
@@ -27,7 +27,7 @@
  * to release resources after a query has been executed and the results have
  * been read completely.
  */
-class QueryHits {
+public class QueryHits {
 
     /**
      * The lucene hits we wrap.
@@ -49,7 +49,7 @@
      * @param hits the lucene hits.
      * @param reader the IndexReader in use by <code>hits</code>.
      */
-    QueryHits(Hits hits, IndexReader reader) {
+    public QueryHits(Hits hits, IndexReader reader) {
         this.hits = hits;
         this.reader = reader;
         this.length = hits.length();

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
Wed Nov 30 11:11:47 2005
@@ -48,7 +48,7 @@
 /**
  * Implements the {@link ExecutableQuery} interface.
  */
-class QueryImpl implements ExecutableQuery {
+public class QueryImpl implements ExecutableQuery {
 
     /**
      * The logger instance for this class
@@ -58,7 +58,7 @@
     /**
      * Represents a query that selects all nodes. E.g. in XPath: //*
      */
-    private static final QueryRootNode ALL_NODES = new QueryRootNode();
+    protected static final QueryRootNode ALL_NODES = new QueryRootNode();
 
     static {
         PathQueryNode pathNode = new PathQueryNode(ALL_NODES);
@@ -70,27 +70,27 @@
     /**
      * The root node of the query tree
      */
-    private final QueryRootNode root;
+    protected final QueryRootNode root;
 
     /**
      * The session of the user executing this query
      */
-    private final SessionImpl session;
+    protected final SessionImpl session;
 
     /**
      * The item manager of the user executing this query
      */
-    private final ItemManager itemMgr;
+    protected final ItemManager itemMgr;
 
     /**
      * The actual search index
      */
-    private final SearchIndex index;
+    protected final SearchIndex index;
 
     /**
      * The property type registry for type lookup.
      */
-    private final PropertyTypeRegistry propReg;
+    protected final PropertyTypeRegistry propReg;
 
     /**
      * If <code>true</code> the default ordering of the result nodes is in
@@ -171,7 +171,7 @@
         // execute it
         QueryHits result = null;
         try {
-            result = index.executeQuery(query, orderProperties, ascSpecs);
+            result = index.executeQuery(this, query, orderProperties, ascSpecs);
             uuids = new ArrayList(result.length());
             scores = new ArrayList(result.length());
 
@@ -197,6 +197,49 @@
             }
         }
 
+        // return QueryResult
+        return new QueryResultImpl(itemMgr,
+                (String[]) uuids.toArray(new String[uuids.size()]),
+                (Float[]) scores.toArray(new Float[scores.size()]),
+                getSelectProperties(),
+                session.getNamespaceResolver(),
+                orderNode == null && documentOrder);
+    }
+
+    /**
+     * If set <code>true</code> the result nodes will be in document order
+     * per default (if no order by clause is specified). If set to
+     * <code>false</code> the result nodes are returned in whatever sequence
+     * the index has stored the nodes. That sequence is stable over multiple
+     * invocations of the same query, but will change when nodes get added or
+     * removed from the index.
+     * <p/>
+     * The default value for this property is <code>true</code>.
+     * @return the current value of this property.
+     */
+    public boolean getRespectDocumentOrder() {
+        return documentOrder;
+    }
+
+    /**
+     * Sets a new value for this property.
+     *
+     * @param documentOrder if <code>true</code> the result nodes are in
+     * document order per default.
+     *
+     * @see #getRespectDocumentOrder()
+     */
+    public void setRespectDocumentOrder(boolean documentOrder) {
+        this.documentOrder = documentOrder;
+    }
+
+    /**
+     * Returns the select properties for this query.
+     *
+     * @return array of select property names.
+     * @throws RepositoryException if an error occurs.
+     */
+    protected QName[] getSelectProperties() throws RepositoryException {
         // get select properties
         List selectProps = new ArrayList();
         selectProps.addAll(Arrays.asList(root.getSelectProperties()));
@@ -231,39 +274,6 @@
             selectProps.add(QName.JCR_SCORE);
         }
 
-        // return QueryResult
-        return new QueryResultImpl(itemMgr,
-                (String[]) uuids.toArray(new String[uuids.size()]),
-                (Float[]) scores.toArray(new Float[scores.size()]),
-                (QName[]) selectProps.toArray(new QName[selectProps.size()]),
-                session.getNamespaceResolver(),
-                orderNode == null && documentOrder);
-    }
-
-    /**
-     * If set <code>true</code> the result nodes will be in document order
-     * per default (if no order by clause is specified). If set to
-     * <code>false</code> the result nodes are returned in whatever sequence
-     * the index has stored the nodes. That sequence is stable over multiple
-     * invocations of the same query, but will change when nodes get added or
-     * removed from the index.
-     * <p/>
-     * The default value for this property is <code>true</code>.
-     * @return the current value of this property.
-     */
-    public boolean getRespectDocumentOrder() {
-        return documentOrder;
-    }
-
-    /**
-     * Sets a new value for this property.
-     *
-     * @param documentOrder if <code>true</code> the result nodes are in
-     * document order per default.
-     *
-     * @see #getRespectDocumentOrder()
-     */
-    public void setRespectDocumentOrder(boolean documentOrder) {
-        this.documentOrder = documentOrder;
+        return (QName[]) selectProps.toArray(new QName[selectProps.size()]);
     }
 }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Wed Nov 30 11:11:47 2005
@@ -298,6 +298,7 @@
 
     /**
      * Executes the query on the search index.
+     * @param queryImpl the query impl.
      * @param query the lucene query.
      * @param orderProps name of the properties for sort order.
      * @param orderSpecs the order specs for the sort order properties.
@@ -306,27 +307,11 @@
      * @return the lucene Hits object.
      * @throws IOException if an error occurs while searching the index.
      */
-    QueryHits executeQuery(Query query,
-                             QName[] orderProps,
-                             boolean[] orderSpecs) throws IOException {
-        SortField[] sortFields = new SortField[orderProps.length];
-        for (int i = 0; i < orderProps.length; i++) {
-            String prop = null;
-            if (QName.JCR_SCORE.equals(orderProps[i])) {
-                // order on jcr:score does not use the natural order as
-                // implemented in lucene. score ascending in lucene means that
-                // higher scores are first. JCR specs that lower score values
-                // are first.
-                sortFields[i] = new SortField(null, SortField.SCORE, orderSpecs[i]);
-            } else {
-                try {
-                    prop = orderProps[i].toJCRName(getNamespaceMappings());
-                } catch (NoPrefixDeclaredException e) {
-                    // will never happen
-                }
-                sortFields[i] = new SortField(prop, SharedFieldSortComparator.PROPERTIES,
!orderSpecs[i]);
-            }
-        }
+    public QueryHits executeQuery(QueryImpl queryImpl,
+                                  Query query,
+                                  QName[] orderProps,
+                                  boolean[] orderSpecs) throws IOException {
+        SortField[] sortFields = createSortFields(orderProps, orderSpecs);
 
         IndexReader reader = index.getIndexReader();
         IndexSearcher searcher = new IndexSearcher(reader);
@@ -343,7 +328,7 @@
      * Returns the analyzer in use for indexing.
      * @return the analyzer in use for indexing.
      */
-    Analyzer getTextAnalyzer() {
+    public Analyzer getTextAnalyzer() {
         return analyzer;
     }
 
@@ -361,11 +346,41 @@
      * Returns the namespace mappings for the internal representation.
      * @return the namespace mappings for the internal representation.
      */
-    NamespaceMappings getNamespaceMappings() {
+    public NamespaceMappings getNamespaceMappings() {
         return index.getNamespaceMappings();
     }
 
     /**
+     * Creates the SortFields for the order properties.
+     *
+     * @param orderProps the order properties.
+     * @param orderSpecs the order specs for the properties.
+     * @return an array of sort fields
+     */
+    protected SortField[] createSortFields(QName[] orderProps,
+                                           boolean[] orderSpecs) {
+        List sortFields = new ArrayList();
+        for (int i = 0; i < orderProps.length; i++) {
+            String prop = null;
+            if (QName.JCR_SCORE.equals(orderProps[i])) {
+                // order on jcr:score does not use the natural order as
+                // implemented in lucene. score ascending in lucene means that
+                // higher scores are first. JCR specs that lower score values
+                // are first.
+                sortFields.add(new SortField(null, SortField.SCORE, orderSpecs[i]));
+            } else {
+                try {
+                    prop = orderProps[i].toJCRName(getNamespaceMappings());
+                } catch (NoPrefixDeclaredException e) {
+                    // will never happen
+                }
+                sortFields.add(new SortField(prop, SharedFieldSortComparator.PROPERTIES,
!orderSpecs[i]));
+            }
+        }
+        return (SortField[]) sortFields.toArray(new SortField[sortFields.size()]);
+    }
+
+    /**
      * Creates a lucene <code>Document</code> from a node state using the
      * namespace mappings <code>nsMappings</code>.
      * @param node the node state to index.
@@ -379,6 +394,15 @@
             throws RepositoryException {
         return NodeIndexer.createDocument(node, getContext().getItemStateManager(),
                 nsMappings, textFilters);
+    }
+
+    /**
+     * Returns the actual index.
+     *
+     * @return the actual index.
+     */
+    protected MultiIndex getIndex() {
+        return index;
     }
 
     //--------------------------< properties >----------------------------------

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
Wed Nov 30 11:11:47 2005
@@ -27,6 +27,8 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
  * Implements a variant of the lucene class <code>org.apache.lucene.search.FieldCacheImpl</code>.
@@ -65,6 +67,7 @@
      * @param field      name of the shared field.
      * @param prefix     the property name, will be used as term prefix.
      * @param comparator the sort comparator instance.
+     * @param includeLookup if <code>true</code> provides term lookup in StringIndex.
      * @return a StringIndex that contains the field values and order
      *         information.
      * @throws IOException if an error occurs while reading from the index.
@@ -72,18 +75,26 @@
     public FieldCache.StringIndex getStringIndex(IndexReader reader,
                                                  String field,
                                                  String prefix,
-                                                 SortComparator comparator)
+                                                 SortComparator comparator,
+                                                 boolean includeLookup)
             throws IOException {
         field = field.intern();
         FieldCache.StringIndex ret = lookup(reader, field, prefix, comparator);
         if (ret == null) {
             final int[] retArray = new int[reader.maxDoc()];
+            List mterms = null;
+            if (includeLookup) {
+                mterms = new ArrayList();
+            }
             if (retArray.length > 0) {
                 TermDocs termDocs = reader.termDocs();
                 TermEnum termEnum = reader.terms(new Term(field, prefix));
                 // documents without a term will have a term number = 0
                 // thus will be at the top, this needs to be in sync with
                 // the implementation of FieldDocSortedHitQueue
+                if (includeLookup) {
+                    mterms.add(null); // for documents with term number 0
+                }
                 int t = 1;  // current term number
 
                 try {
@@ -96,6 +107,11 @@
                             break;
                         }
 
+                        // store term text
+                        if (includeLookup) {
+                            mterms.add(term.text().substring(prefix.length()));
+                        }
+
                         termDocs.seek(termEnum);
                         while (termDocs.next()) {
                             retArray[termDocs.doc()] = t;
@@ -108,7 +124,11 @@
                     termEnum.close();
                 }
             }
-            FieldCache.StringIndex value = new FieldCache.StringIndex(retArray, null);
+            String[] lookup = null;
+            if (includeLookup) {
+                lookup = (String[]) mterms.toArray(new String[mterms.size()]);
+            }
+            FieldCache.StringIndex value = new FieldCache.StringIndex(retArray, lookup);
             store(reader, field, prefix, comparator, value);
             return value;
         }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
Wed Nov 30 11:11:47 2005
@@ -20,7 +20,7 @@
  * are executed with a <code>MultiSearcher</code>, which is currently not the
  * case in Jackrabbit.
  */
-class SharedFieldSortComparator extends SortComparator {
+public class SharedFieldSortComparator extends SortComparator {
 
     /**
      * A <code>SharedFieldSortComparator</code> that is based on
@@ -34,12 +34,34 @@
     private final String field;
 
     /**
+     * If <code>true</code> <code>ScoreDocComparator</code> will
returns term
+     * values when {@link org.apache.lucene.search.ScoreDocComparator#sortValue(org.apache.lucene.search.ScoreDoc)}
+     * is called, otherwise only a dummy value is returned.
+     */
+    private final boolean createComparatorValues;
+
+    /**
      * Creates a new <code>SharedFieldSortComparator</code> for a given shared
      * field.
+     *
      * @param fieldname the shared field.
      */
     public SharedFieldSortComparator(String fieldname) {
+        this(fieldname, false);
+    }
+
+    /**
+     * Creates a new <code>SharedFieldSortComparator</code> for a given shared
+     * field.
+     *
+     * @param fieldname              the shared field.
+     * @param createComparatorValues if <code>true</code> creates values
+     * for the <code>ScoreDocComparator</code>s.
+     * @see #createComparatorValues
+     */
+    public SharedFieldSortComparator(String fieldname, boolean createComparatorValues) {
         this.field = fieldname;
+        this.createComparatorValues = createComparatorValues;
     }
 
     /**
@@ -55,7 +77,9 @@
         // get the StringIndex for propertyName
         final FieldCache.StringIndex index
                 = SharedFieldCache.INSTANCE.getStringIndex(reader, field,
-                        propertyName, SharedFieldSortComparator.this);
+                        FieldNames.createNamedValue(propertyName, ""),
+                        SharedFieldSortComparator.this,
+                        createComparatorValues);
 
         return new ScoreDocComparator() {
             public final int compare(final ScoreDoc i, final ScoreDoc j) {
@@ -71,13 +95,19 @@
             }
 
             /**
-             * Always returns an empty String.
+             * Returns an empty if no lookup table is available otherwise
+             * the index term for the score doc <code>i</code>.
+             *
              * @param i the score doc.
-             * @return an empty String.
+             * @return the sort value if available.
              */
             public Comparable sortValue(final ScoreDoc i) {
-                // return dummy value
-                return "";
+                if (index.lookup != null) {
+                    return index.lookup[index.order[i.doc]];
+                } else {
+                    // return dummy value
+                    return "";
+                }
             }
 
             public int sortType() {

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java?rev=350022&r1=350021&r2=350022&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
Wed Nov 30 11:11:47 2005
@@ -38,7 +38,7 @@
  * Implements a query result that traverses the whole workspace and returns
  * the nodes in document order.
  */
-class WorkspaceTraversalResult implements QueryResult {
+public class WorkspaceTraversalResult implements QueryResult {
 
     /**
      * The session that issued the query.
@@ -62,7 +62,7 @@
      * @param properties the select properties.
      * @param resolver   the namespace resolver of the session.
      */
-    WorkspaceTraversalResult(Session session,
+    public WorkspaceTraversalResult(Session session,
                              QName[] properties,
                              NamespaceResolver resolver) {
         this.session = session;



Mime
View raw message