jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: rev 56683 - in incubator/jackrabbit/trunk: applications/test src/conf src/java/org/apache/jackrabbit/core src/java/org/apache/jackrabbit/core/config src/java/org/apache/jackrabbit/core/search src/java/org/apache/jackrabbit/core/search/lucene
Date Fri, 05 Nov 2004 16:47:44 GMT
Author: mreutegg
Date: Fri Nov  5 08:47:43 2004
New Revision: 56683

Modified:
   incubator/jackrabbit/trunk/applications/test/repository.xml
   incubator/jackrabbit/trunk/src/conf/repository.xml
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/NamespaceMappings.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
   incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
Log:
Enhanced workspace configuration to support independent FileSystem for SearchIndex

Modified: incubator/jackrabbit/trunk/applications/test/repository.xml
==============================================================================
--- incubator/jackrabbit/trunk/applications/test/repository.xml	(original)
+++ incubator/jackrabbit/trunk/applications/test/repository.xml	Fri Nov  5 08:47:43 2004
@@ -74,9 +74,7 @@
         the SearchIndex element specifies the locaction of the search index
         (used by the QueryManager)
     -->
-    <!ELEMENT SearchIndex EMPTY>
-    <!ATTLIST SearchIndex
-      path CDATA #REQUIRED>
+    <!ELEMENT SearchIndex (FileSystem)>
 ]>
 <Repository>
     <!--
@@ -84,12 +82,12 @@
         (e.g. registered namespaces, custom node types, etc.)
     -->
     <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
-    	<param name="path" value="${rep.home}/repository"/>
+        <param name="path" value="${rep.home}/repository"/>
     </FileSystem>
     <!--
         location of workspaces root directory and name of default workspace
     -->
-    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" />
+    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
     <!--
         workspace configuration template:
         used to create the initial workspace if there's no workspace yet
@@ -106,9 +104,16 @@
             persistence of the workspace:
             class: FQN of class implementing PersistenceManager interface
         -->
-        <PersistenceManager class="org.apache.jackrabbit.core.state.xml.XMLPersistenceManager">
+        <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager">
             <!-- <param name="someParam" value="someValue"/> -->
         </PersistenceManager>
-        <SearchIndex path="/index"/>
+        <!--
+            Search index and the file system it uses.
+        -->
+        <SearchIndex>
+            <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+                <param name="path" value="${wsp.home}/index"/>
+            </FileSystem>
+        </SearchIndex>
     </Workspace>
-</Repository>
\ No newline at end of file
+</Repository>

Modified: incubator/jackrabbit/trunk/src/conf/repository.xml
==============================================================================
--- incubator/jackrabbit/trunk/src/conf/repository.xml	(original)
+++ incubator/jackrabbit/trunk/src/conf/repository.xml	Fri Nov  5 08:47:43 2004
@@ -74,9 +74,7 @@
         the SearchIndex element specifies the locaction of the search index
         (used by the QueryManager)
     -->
-    <!ELEMENT SearchIndex EMPTY>
-    <!ATTLIST SearchIndex
-      path CDATA #REQUIRED>
+    <!ELEMENT SearchIndex (FileSystem)>
 ]>
 <!-- Example Repository Configuration File -->
 <Repository>
@@ -120,6 +118,13 @@
         <PersistenceManager class="org.apache.jackrabbit.core.state.obj.ObjectPersistenceManager">
             <!-- <param name="someParam" value="someValue"/> -->
         </PersistenceManager>
-        <SearchIndex path="/index"/>
+        <!--
+            Search index and the file system it uses.
+        -->
+        <SearchIndex>
+            <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+                <param name="path" value="${wsp.home}/index"/>
+            </FileSystem>
+        </SearchIndex>
     </Workspace>
-</Repository>
\ No newline at end of file
+</Repository>

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/RepositoryImpl.java	Fri
Nov  5 08:47:43 2004
@@ -488,14 +488,14 @@
                 = (SearchManager) wspSearchMgrs.get(workspaceName);
         if (searchMgr == null) {
             try {
-                if (wspConfig.getSearchIndexDir() == null) {
-                    // no search index location configured
+                if (wspConfig.getSearchIndexFS() == null) {
+                    // no search index configured
                     return null;
                 }
                 ItemStateProvider stateProvider = getWorkspaceStateManager(workspaceName);
                 SystemSession s = getSystemSession(workspaceName);
                 searchMgr = new SearchManager(stateProvider, s.getHierarchyManager(), s,
-                        wspConfig.getFileSystem(), wspConfig.getSearchIndexDir());
+                        wspConfig.getSearchIndexFS());
             } catch (IOException e) {
                 throw new RepositoryException("Exception opening search index.", e);
             }

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java	(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SearchManager.java	Fri
Nov  5 08:47:43 2004
@@ -46,6 +46,8 @@
 
     private static final Logger log = Logger.getLogger(SearchManager.class);
 
+    private static final String NS_MAPPING_FILE = "ns_mappings.properties";
+
     private final SearchIndex index;
 
     private final ItemStateProvider stateProvider;
@@ -59,14 +61,12 @@
     public SearchManager(ItemStateProvider stateProvider,
                          HierarchyManager hmgr,
                          SessionImpl session,
-                         FileSystem fs,
-                         String indexPath) throws IOException {
+                         FileSystem fs) throws IOException {
         this.stateProvider = stateProvider;
         this.hmgr = hmgr;
         this.session = session;
-        index = new SearchIndex(fs, indexPath, new StandardAnalyzer());
-        String mapFileName = indexPath + FileSystem.SEPARATOR + "ns_mappings.properties";
-        FileSystemResource mapFile = new FileSystemResource(fs, mapFileName);
+        index = new SearchIndex(fs, new StandardAnalyzer());
+        FileSystemResource mapFile = new FileSystemResource(fs, NS_MAPPING_FILE);
         nsMappings = new NamespaceMappings(mapFile);
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/config/WorkspaceConfig.java
Fri Nov  5 08:47:43 2004
@@ -81,9 +81,9 @@
     private PersistenceManager persistMgr;
 
     /**
-     * search index direcorty
+     * virtual file system where the workspace stores the search index
      */
-    private String searchIndexDir;
+    private FileSystem searchIndexFS;
 
     /**
      * private constructor.
@@ -120,13 +120,11 @@
         Element fsConfig = wspElem.getChild(FILE_SYSTEM_ELEMENT);
         wspFS = createFileSystem(fsConfig, vars);
 
-        // search index directory
+        // search index
         Element searchConfig = wspElem.getChild(SEARCH_INDEX_ELEMENT);
         if (searchConfig != null) {
-            String pathAttr = searchConfig.getAttributeValue(PATH_ATTRIB);
-            if (pathAttr != null && pathAttr.length() > 0) {
-                searchIndexDir = replaceVars(pathAttr, vars);
-            }
+            Element indexFS = searchConfig.getChild(FILE_SYSTEM_ELEMENT);
+            searchIndexFS = createFileSystem(indexFS, vars);
         }
 
         // persistence manager
@@ -236,12 +234,13 @@
     }
 
     /**
-     * Returns the search index directory
+     * Returns virtual file system where the search index is stored.
+     * Returns <code>null</code> if no search index is configured.
      *
-     * @return the search index directory
+     * @return virtual file system where the search index is stored.
      */
-    public String getSearchIndexDir() {
-        return searchIndexDir;
+    public FileSystem getSearchIndexFS() {
+        return searchIndexFS;
     }
 
     //------------------------------------------------------< EntityResolver >

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/NamespaceMappings.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/NamespaceMappings.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/NamespaceMappings.java
Fri Nov  5 08:47:43 2004
@@ -15,10 +15,11 @@
  */
 package org.apache.jackrabbit.core.search;
 
-import org.apache.jackrabbit.core.MalformedPathException;
 import org.apache.jackrabbit.core.NamespaceResolver;
 import org.apache.jackrabbit.core.NoPrefixDeclaredException;
-import org.apache.jackrabbit.core.Path;
+import org.apache.jackrabbit.core.QName;
+import org.apache.jackrabbit.core.IllegalNameException;
+import org.apache.jackrabbit.core.UnknownPrefixException;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.FileSystemResource;
 import org.apache.log4j.Logger;
@@ -137,14 +138,14 @@
      * @return the translated property name
      */
     public String translatePropertyName(String name, NamespaceResolver resolver)
-            throws MalformedPathException {
-        Path path = Path.create(name, resolver, false);
+            throws IllegalNameException, UnknownPrefixException {
+        QName qName = QName.fromJCRName(name, resolver);
         try {
-            return path.toJCRPath(this);
+            return qName.toJCRName(this);
         } catch (NoPrefixDeclaredException e) {
             // should never happen actually, because we create yet unknown
             // uri mappings on the fly.
-            throw new MalformedPathException(e.toString());
+            throw new IllegalNameException("Internal error.", e);
         }
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/LuceneQueryBuilder.java
Fri Nov  5 08:47:43 2004
@@ -18,6 +18,8 @@
 import org.apache.jackrabbit.core.MalformedPathException;
 import org.apache.jackrabbit.core.Path;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.IllegalNameException;
+import org.apache.jackrabbit.core.UnknownPrefixException;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.search.*;
 import org.apache.log4j.Logger;
@@ -29,11 +31,14 @@
 import org.apache.lucene.search.RangeQuery;
 import org.apache.lucene.search.TermQuery;
 
-import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.NodeTypeIterator;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Arrays;
 
 /**
  */
@@ -97,7 +102,9 @@
             String prop = props[i];
             try {
                 prop = nsMappings.translatePropertyName(prop, session.getNamespaceResolver());
-            } catch (MalformedPathException e) {
+            } catch (IllegalNameException e) {
+                exceptions.add(e);
+            } catch (UnknownPrefixException e) {
                 exceptions.add(e);
             }
             root.add(new MatchAllQuery(prop), true, false);
@@ -157,7 +164,9 @@
         try {
             field = nsMappings.translatePropertyName(node.getPropertyName(),
                     session.getNamespaceResolver());
-        } catch (MalformedPathException e) {
+        } catch (IllegalNameException e) {
+            exceptions.add(e);
+        } catch (UnknownPrefixException e) {
             exceptions.add(e);
         }
         String value = node.getValue();
@@ -166,19 +175,43 @@
 
     public Object visit(NodeTypeQueryNode node, Object data) {
         String field = node.getPropertyName();
-        String value = node.getValue();
+        List values = new ArrayList();
         try {
             field = nsMappings.getPrefix(NodeTypeRegistry.JCR_PRIMARY_TYPE.getNamespaceURI())
                     + ":" + NodeTypeRegistry.JCR_PRIMARY_TYPE.getLocalName();
-            value = nsMappings.translatePropertyName(node.getValue(),
-                    session.getNamespaceResolver());
-        } catch (NamespaceException e) {
-            // will never happen
-            log.error(e.toString());
-        } catch (MalformedPathException e) {
+
+            values.add(nsMappings.translatePropertyName(node.getValue(),
+                    session.getNamespaceResolver()));
+            NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
+            NodeType base = ntMgr.getNodeType(node.getValue());
+            NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
+            while (allTypes.hasNext()) {
+                NodeType nt = allTypes.nextNodeType();
+                NodeType[] superTypes = nt.getSupertypes();
+                if (Arrays.asList(superTypes).contains(base)) {
+                    values.add(nsMappings.translatePropertyName(nt.getName(),
+                            session.getNamespaceResolver()));
+                }
+            }
+        } catch (IllegalNameException e) {
+            exceptions.add(e);
+        } catch (UnknownPrefixException e) {
+            exceptions.add(e);
+        } catch (RepositoryException e) {
             exceptions.add(e);
         }
-        return new TermQuery(new Term(field, value));
+        if (values.size() == 0) {
+            // exception occured
+            return new BooleanQuery();
+        } else if (values.size() == 1) {
+            return new TermQuery(new Term(field, (String) values.get(0)));
+        } else {
+            BooleanQuery b = new BooleanQuery();
+            for (Iterator it = values.iterator(); it.hasNext();) {
+                b.add(new TermQuery(new Term(field, (String)it.next())), false, false);
+            }
+            return b;
+        }
     }
 
     public Object visit(RangeQueryNode node, Object data) {
@@ -269,7 +302,9 @@
         try {
             field = nsMappings.translatePropertyName(node.getProperty(),
                     session.getNamespaceResolver());
-        } catch (MalformedPathException e) {
+        } catch (IllegalNameException e) {
+            exceptions.add(e);
+        } catch (UnknownPrefixException e) {
             exceptions.add(e);
         }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/search/lucene/SearchIndex.java
==============================================================================
--- 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
Fri Nov  5 08:47:43 2004
@@ -16,7 +16,6 @@
 package org.apache.jackrabbit.core.search.lucene;
 
 import EDU.oswego.cs.dl.util.concurrent.FIFOReadWriteLock;
-import org.apache.jackrabbit.core.fs.BasedFileSystem;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.log4j.Logger;
@@ -47,23 +46,16 @@
 
     private final Analyzer analyzer;
 
-    private final String location;
-
     private final FIFOReadWriteLock readWriteLock = new FIFOReadWriteLock();
 
-    public SearchIndex(FileSystem fs, String location, Analyzer analyzer)
+    public SearchIndex(FileSystem fs, Analyzer analyzer)
             throws IOException {
         //volatileIndex = new VolatileIndex(analyzer);
         boolean create;
         try {
-            if (!fs.exists(location)) {
-                fs.createFolder(location);
-            }
-            FileSystem indexFS = new BasedFileSystem(fs, location);
-            create = !indexFS.exists("segments");
-            persistentIndex = new PersistentIndex(indexFS, create, analyzer);
+            create = !fs.exists("segments");
+            persistentIndex = new PersistentIndex(fs, create, analyzer);
             persistentIndex.setUseCompoundFile(true);
-            this.location = location;
             this.analyzer = analyzer;
         } catch (FileSystemException e) {
             throw new IOException(e.getMessage());
@@ -120,7 +112,7 @@
         }
         volatileIndex.close();
         */
-        log.info("Closing index: " + location);
+        log.info("Closing search index.");
         persistentIndex.close();
     }
 

Mime
View raw message