[exo-jcr-commits] exo-jcr SVN: r931 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr: impl/core/query and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Dec 7 05:56:38 EST 2009


Author: skabashnyuk
Date: 2009-12-07 05:56:37 -0500 (Mon, 07 Dec 2009)
New Revision: 931

Added:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
Log:
EXOJCR-283: Added Changes filter

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java	2009-12-07 10:11:19 UTC (rev 930)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/config/QueryHandlerParams.java	2009-12-07 10:56:37 UTC (rev 931)
@@ -99,4 +99,7 @@
 
    public static final String PARAM_ANALYZER_CLASS = "analyzer";
 
+   public static final String PARAM_CHANGES_FILTER_CLASS = "changesfilter-class";
+
+   public static final String PARAM_CHANGES_FILTER_CONFIG_PATH = "changesfilter-config-path";
 }

Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java	2009-12-07 10:56:37 UTC (rev 931)
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query;
+
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.ItemStateChangesLog;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public class DefaultChangesFilter extends IndexerChangesFilter
+{
+   /**
+    * @param searchManager
+    * @param handler
+    * @param indexingTree
+    */
+   public DefaultChangesFilter(SearchManager searchManager, QueryHandlerEntry config, IndexingTree indexingTree)
+   {
+      super(searchManager, config, indexingTree);
+      // TODO Auto-generated constructor stub
+   }
+
+   /**
+    * Logger instance for this class
+    */
+   private static final Log log = ExoLogger.getLogger(DefaultChangesFilter.class);
+
+   /**
+    * @see org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener#onSaveItems(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
+    */
+   public void onSaveItems(ItemStateChangesLog itemStates)
+   {
+
+      long time = System.currentTimeMillis();
+
+      // nodes that need to be removed from the index.
+      final Set<String> removedNodes = new HashSet<String>();
+      // nodes that need to be added to the index.
+      final Set<String> addedNodes = new HashSet<String>();
+
+      final Map<String, List<ItemState>> updatedNodes = new HashMap<String, List<ItemState>>();
+
+      for (Iterator<ItemState> iter = itemStates.getAllStates().iterator(); iter.hasNext();)
+      {
+         ItemState itemState = iter.next();
+
+         if (!indexingTree.isExcluded(itemState))
+         {
+            String uuid =
+               itemState.isNode() ? itemState.getData().getIdentifier() : itemState.getData().getParentIdentifier();
+
+            if (itemState.isAdded())
+            {
+               if (itemState.isNode())
+               {
+                  addedNodes.add(uuid);
+               }
+               else
+               {
+                  if (!addedNodes.contains(uuid))
+                  {
+                     createNewOrAdd(uuid, itemState, updatedNodes);
+                  }
+               }
+            }
+            else if (itemState.isRenamed())
+            {
+               if (itemState.isNode())
+               {
+                  addedNodes.add(uuid);
+               }
+               else
+               {
+                  createNewOrAdd(uuid, itemState, updatedNodes);
+               }
+            }
+            else if (itemState.isUpdated())
+            {
+               createNewOrAdd(uuid, itemState, updatedNodes);
+            }
+            else if (itemState.isMixinChanged())
+            {
+               createNewOrAdd(uuid, itemState, updatedNodes);
+            }
+            else if (itemState.isDeleted())
+            {
+               if (itemState.isNode())
+               {
+                  if (addedNodes.contains(uuid))
+                  {
+                     addedNodes.remove(uuid);
+                     removedNodes.remove(uuid);
+                  }
+                  else
+                  {
+                     removedNodes.add(uuid);
+                  }
+                  // remove all changes after node remove
+                  updatedNodes.remove(uuid);
+               }
+               else
+               {
+                  if (!removedNodes.contains(uuid) && !addedNodes.contains(uuid))
+                  {
+                     createNewOrAdd(uuid, itemState, updatedNodes);
+                  }
+               }
+            }
+         }
+      }
+      // TODO make quick changes
+      for (String uuid : updatedNodes.keySet())
+      {
+         removedNodes.add(uuid);
+         addedNodes.add(uuid);
+      }
+
+      try
+      {
+         searchManager.updateIndex(removedNodes, addedNodes);
+      }
+      catch (RepositoryException e)
+      {
+         log.error("Error indexing changes " + e, e);
+      }
+      catch (IOException e)
+      {
+         log.error("Error indexing changes " + e, e);
+         try
+         {
+            handler.logErrorChanges(removedNodes, addedNodes);
+         }
+         catch (IOException ioe)
+         {
+            log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+         }
+      }
+
+      if (log.isDebugEnabled())
+      {
+         log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
+      }
+
+   }
+
+   public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
+   {
+      List<ItemState> list = updatedNodes.get(key);
+      if (list == null)
+      {
+         list = new ArrayList<ItemState>();
+         updatedNodes.put(key, list);
+      }
+      list.add(state);
+
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java	2009-12-07 10:56:37 UTC (rev 931)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.core.query;
+
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener;
+
+/**
+ * @author <a href="mailto:Sergey.Kabashnyuk at exoplatform.org">Sergey Kabashnyuk</a>
+ * @version $Id: exo-jboss-codetemplates.xml 34360 2009-07-22 23:58:59Z ksm $
+ *
+ */
+public abstract class IndexerChangesFilter implements ItemsPersistenceListener
+{
+   protected final SearchManager searchManager;
+
+   protected final QueryHandlerEntry config;
+
+   protected QueryHandler handler;
+
+   protected final IndexingTree indexingTree;
+
+   /**
+    * @param searchManager
+    * @param handler
+    * @param indexingTree
+    */
+   public IndexerChangesFilter(SearchManager searchManager, QueryHandlerEntry config, IndexingTree indexingTree)
+   {
+      super();
+      this.searchManager = searchManager;
+      this.config = config;
+
+      this.indexingTree = indexingTree;
+   }
+
+   /**
+    * @return the handler
+    */
+   public QueryHandler getHandler()
+   {
+      return handler;
+   }
+
+   /**
+    * @param handler the handler to set
+    */
+   public void setHandler(QueryHandler handler)
+   {
+      this.handler = handler;
+   }
+
+   /**
+    * @return the searchManager
+    */
+   public SearchManager getSearchManager()
+   {
+      return searchManager;
+   }
+
+   /**
+    * @return the indexingTree
+    */
+   public IndexingTree getIndexingTree()
+   {
+      return indexingTree;
+   }
+
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/IndexerChangesFilter.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2009-12-07 10:11:19 UTC (rev 930)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java	2009-12-07 10:56:37 UTC (rev 931)
@@ -64,7 +64,6 @@
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -107,6 +106,7 @@
    /**
     * QueryHandler where query execution is delegated to
     */
+
    protected QueryHandler handler;
 
    /**
@@ -140,6 +140,8 @@
 
    protected LuceneVirtualTableResolver virtualTableResolver;
 
+   private IndexerChangesFilter changesFilter;
+
    /**
     * Creates a new <code>SearchManager</code>.
     * 
@@ -183,6 +185,18 @@
       ((WorkspacePersistentDataManager)this.itemMgr).addItemPersistenceListener(this);
    }
 
+   public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
+   {
+      List<ItemState> list = updatedNodes.get(key);
+      if (list == null)
+      {
+         list = new ArrayList<ItemState>();
+         updatedNodes.put(key, list);
+      }
+      list.add(state);
+
+   }
+
    /**
     * Creates a query object from a node that can be executed on the workspace.
     * 
@@ -236,6 +250,45 @@
    }
 
    /**
+    * {@inheritDoc}
+    */
+   public Set<String> getFieldNames() throws IndexException
+   {
+      final Set<String> fildsSet = new HashSet<String>();
+      if (handler instanceof SearchIndex)
+      {
+         IndexReader reader = null;
+         try
+         {
+            reader = ((SearchIndex)handler).getIndexReader();
+            final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
+            for (final Object field : fields)
+            {
+               fildsSet.add((String)field);
+            }
+         }
+         catch (IOException e)
+         {
+            throw new IndexException(e.getLocalizedMessage(), e);
+         }
+         finally
+         {
+            try
+            {
+               if (reader != null)
+                  reader.close();
+            }
+            catch (IOException e)
+            {
+               throw new IndexException(e.getLocalizedMessage(), e);
+            }
+         }
+
+      }
+      return fildsSet;
+   }
+
+   /**
     * just for test use only
     */
    public QueryHandler getHandler()
@@ -244,6 +297,90 @@
       return handler;
    }
 
+   public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
+   {
+
+      return getNodes(virtualTableResolver.resolve(nodeType, true));
+   }
+
+   /**
+    * Return set of uuid of nodes. Contains in names prefixes maped to the
+    * given uri
+    * 
+    * @param prefix
+    * @return
+    * @throws RepositoryException
+    */
+   public Set<String> getNodesByUri(final String uri) throws RepositoryException
+   {
+      Set<String> result;
+      final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
+      try
+      {
+
+         // final LocationFactory locationFactory = new
+         // LocationFactory(this);
+         final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
+         BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
+         BooleanQuery query = new BooleanQuery();
+
+         final String prefix = nsReg.getNamespacePrefixByURI(uri);
+         query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
+         // name of the property
+         query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
+
+         result = getNodes(query);
+
+         // value of the property
+
+         try
+         {
+            final Set<String> props = getFieldNames();
+
+            query = new BooleanQuery();
+            for (final String fieldName : props)
+            {
+               if (!FieldNames.PROPERTIES_SET.equals(fieldName))
+               {
+                  query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
+               }
+            }
+         }
+         catch (final IndexException e)
+         {
+            throw new RepositoryException(e.getLocalizedMessage(), e);
+         }
+
+         final Set<String> propSet = getNodes(query);
+         // Manually check property values;
+         for (final String uuid : propSet)
+         {
+            if (isPrefixMatch(valueFactory, uuid, prefix))
+            {
+               result.add(uuid);
+            }
+         }
+      }
+      finally
+      {
+         BooleanQuery.setMaxClauseCount(defaultClauseCount);
+      }
+
+      return result;
+   }
+
+   /**
+    * @see org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener#onSaveItems(org.exoplatform.services.jcr.dataflow.ItemStateChangesLog)
+    */
+   public void onSaveItems(ItemStateChangesLog itemStates)
+   {
+      //Check if SearchManager started
+      if (changesFilter == null)
+         return;
+      changesFilter.onSaveItems(itemStates);
+
+   }
+
    public void onSaveItems(List<WriteCommand> modifications) throws RepositoryException
    {
       try
@@ -279,124 +416,96 @@
       }
    }
 
-   public void onSaveItems(ItemStateChangesLog changesLog)
+   public void start()
    {
-      //      Exception es = new Exception();
-      //      es.printStackTrace();
 
-      if (handler == null)
-         return;
-
-      long time = System.currentTimeMillis();
-
-      // nodes that need to be removed from the index.
-      final Set<String> removedNodes = new HashSet<String>();
-      // nodes that need to be added to the index.
-      final Set<String> addedNodes = new HashSet<String>();
-
-      final Map<String, List<ItemState>> updatedNodes = new HashMap<String, List<ItemState>>();
-
-      for (Iterator<ItemState> iter = changesLog.getAllStates().iterator(); iter.hasNext();)
+      if (log.isDebugEnabled())
+         log.debug("start");
+      try
       {
-         ItemState itemState = iter.next();
-
-         if (!indexingTree.isExcluded(itemState))
+         if (indexingTree == null)
          {
-            String uuid =
-               itemState.isNode() ? itemState.getData().getIdentifier() : itemState.getData().getParentIdentifier();
+            List<QPath> excludedPath = new ArrayList<QPath>();
+            // Calculating excluded node identifiers
+            excludedPath.add(Constants.JCR_SYSTEM_PATH);
 
-            if (itemState.isAdded())
+            //if (config.getExcludedNodeIdentifers() != null)
+            String excludedNodeIdentifer =
+               config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
+            if (excludedNodeIdentifer != null)
             {
-               if (itemState.isNode())
+               StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
+               while (stringTokenizer.hasMoreTokens())
                {
-                  addedNodes.add(uuid);
-               }
-               else
-               {
-                  if (!addedNodes.contains(uuid))
+
+                  try
                   {
-                     createNewOrAdd(uuid, itemState, updatedNodes);
+                     ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
+                     if (excludeData != null)
+                        excludedPath.add(excludeData.getQPath());
                   }
+                  catch (RepositoryException e)
+                  {
+                     log.warn(e.getLocalizedMessage());
+                  }
                }
             }
-            else if (itemState.isRenamed())
+
+            NodeData indexingRootData = null;
+            String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
+            if (rootNodeIdentifer != null)
             {
-               if (itemState.isNode())
+               try
                {
-                  addedNodes.add(uuid);
+                  ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
+                  if (indexingRootDataItem != null && indexingRootDataItem.isNode())
+                     indexingRootData = (NodeData)indexingRootDataItem;
                }
-               else
+               catch (RepositoryException e)
                {
-                  createNewOrAdd(uuid, itemState, updatedNodes);
+                  log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
+
                }
+
             }
-            else if (itemState.isUpdated())
+            else
             {
-               createNewOrAdd(uuid, itemState, updatedNodes);
-            }
-            else if (itemState.isMixinChanged())
-            {
-               createNewOrAdd(uuid, itemState, updatedNodes);
-            }
-            else if (itemState.isDeleted())
-            {
-               if (itemState.isNode())
+               try
                {
-                  if (addedNodes.contains(uuid))
-                  {
-                     addedNodes.remove(uuid);
-                     removedNodes.remove(uuid);
-                  }
-                  else
-                  {
-                     removedNodes.add(uuid);
-                  }
-                  // remove all changes after node remove
-                  updatedNodes.remove(uuid);
+                  indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
+                  //               indexingRootData =
+                  //                  new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+                  //                     new InternalQName[0], 0, null, new AccessControlList());
                }
-               else
+               catch (RepositoryException e)
                {
-                  if (!removedNodes.contains(uuid) && !addedNodes.contains(uuid))
-                  {
-                     createNewOrAdd(uuid, itemState, updatedNodes);
-                  }
+                  log.error("Fail to load root node data");
                }
             }
+
+            indexingTree = new IndexingTree(indexingRootData, excludedPath);
          }
+         initializeChangesFilter();
+         initializeQueryHandler();
       }
-      // TODO make quick changes
-      for (String uuid : updatedNodes.keySet())
-      {
-         removedNodes.add(uuid);
-         addedNodes.add(uuid);
-      }
-
-      try
-      {
-         updateIndex(removedNodes, addedNodes);
-      }
       catch (RepositoryException e)
       {
-         log.error("Error indexing changes " + e, e);
+         log.error(e.getLocalizedMessage());
+         handler = null;
+         throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
       }
-      catch (IOException e)
+      catch (RepositoryConfigurationException e)
       {
-         log.error("Error indexing changes " + e, e);
-         try
-         {
-            handler.logErrorChanges(removedNodes, addedNodes);
-         }
-         catch (IOException ioe)
-         {
-            log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
-         }
+         log.error(e.getLocalizedMessage());
+         handler = null;
+         throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
       }
+   }
 
-      if (log.isDebugEnabled())
-      {
-         log.debug("onEvent: indexing finished in " + String.valueOf(System.currentTimeMillis() - time) + " ms.");
-      }
-
+   public void stop()
+   {
+      handler.close();
+      log.info("Search manager stopped");
    }
 
    /**
@@ -491,141 +600,46 @@
 
    }
 
-   public void createNewOrAdd(String key, ItemState state, Map<String, List<ItemState>> updatedNodes)
+   protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
+      throws RepositoryConfigurationException
    {
-      List<ItemState> list = updatedNodes.get(key);
-      if (list == null)
-      {
-         list = new ArrayList<ItemState>();
-         updatedNodes.put(key, list);
-      }
-      list.add(state);
 
+      QueryHandlerContext context =
+         new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
+            extractor, true, virtualTableResolver);
+      return context;
    }
 
-   public void start()
+   /**
+    * 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
    {
-
-      if (log.isDebugEnabled())
-         log.debug("start");
       try
       {
-         if (indexingTree == null)
+         String queryImplClassName = handler.getQueryClass();
+         Object obj = Class.forName(queryImplClassName).newInstance();
+         if (obj instanceof AbstractQueryImpl)
          {
-            List<QPath> excludedPath = new ArrayList<QPath>();
-            // Calculating excluded node identifiers
-            excludedPath.add(Constants.JCR_SYSTEM_PATH);
-
-            //if (config.getExcludedNodeIdentifers() != null)
-            String excludedNodeIdentifer =
-               config.getParameterValue(QueryHandlerParams.PARAM_EXCLUDED_NODE_IDENTIFERS, null);
-            if (excludedNodeIdentifer != null)
-            {
-               StringTokenizer stringTokenizer = new StringTokenizer(excludedNodeIdentifer);
-               while (stringTokenizer.hasMoreTokens())
-               {
-
-                  try
-                  {
-                     ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
-                     if (excludeData != null)
-                        excludedPath.add(excludeData.getQPath());
-                  }
-                  catch (RepositoryException e)
-                  {
-                     log.warn(e.getLocalizedMessage());
-                  }
-               }
-            }
-
-            NodeData indexingRootData = null;
-            String rootNodeIdentifer = config.getParameterValue(QueryHandlerParams.PARAM_ROOT_NODE_ID, null);
-            if (rootNodeIdentifer != null)
-            {
-               try
-               {
-                  ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
-                  if (indexingRootDataItem != null && indexingRootDataItem.isNode())
-                     indexingRootData = (NodeData)indexingRootDataItem;
-               }
-               catch (RepositoryException e)
-               {
-                  log.warn(e.getLocalizedMessage() + " Indexing root set to " + Constants.ROOT_PATH.getAsString());
-
-               }
-
-            }
-            else
-            {
-               try
-               {
-                  indexingRootData = (NodeData)itemMgr.getItemData(Constants.ROOT_UUID);
-                  //               indexingRootData =
-                  //                  new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
-                  //                     new InternalQName[0], 0, null, new AccessControlList());
-               }
-               catch (RepositoryException e)
-               {
-                  log.error("Fail to load root node data");
-               }
-            }
-
-            indexingTree = new IndexingTree(indexingRootData, excludedPath);
+            return (AbstractQueryImpl)obj;
          }
-
-         initializeQueryHandler();
+         else
+         {
+            throw new IllegalArgumentException(queryImplClassName + " is not of type "
+               + AbstractQueryImpl.class.getName());
+         }
       }
-      catch (RepositoryException e)
+      catch (Throwable t)
       {
-         log.error(e.getLocalizedMessage());
-         handler = null;
-         throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
+         throw new RepositoryException("Unable to create query: " + t.toString(), t);
       }
-      catch (RepositoryConfigurationException e)
-      {
-         log.error(e.getLocalizedMessage());
-         handler = null;
-         throw new RuntimeException(e.getLocalizedMessage(), e.getCause());
-      }
    }
 
-   public void stop()
-   {
-      handler.close();
-      log.info("Search manager stopped");
-   }
-
-   // /**
-   // * Checks if the given event should be excluded based on the
-   // * {@link #excludePath} setting.
-   // *
-   // * @param event
-   // * observation event
-   // * @return <code>true</code> if the event should be excluded,
-   // * <code>false</code> otherwise
-   // */
-   // protected boolean isExcluded(ItemState event) {
-   //
-   // for (QPath excludedPath : excludedPaths) {
-   // if (event.getData().getQPath().isDescendantOf(excludedPath)
-   // || event.getData().getQPath().equals(excludedPath))
-   // return true;
-   // }
-   //
-   // return !event.getData().getQPath().isDescendantOf(indexingRoot)
-   // && !event.getData().getQPath().equals(indexingRoot);
-   // }
-
-   protected QueryHandlerContext createQueryHandlerContext(QueryHandler parentHandler)
-      throws RepositoryConfigurationException
-   {
-
-      QueryHandlerContext context =
-         new QueryHandlerContext(itemMgr, indexingTree, nodeTypeDataManager, nsReg, parentHandler, getIndexDir(),
-            extractor, true, virtualTableResolver);
-      return context;
-   }
-
    protected String getIndexDir() throws RepositoryConfigurationException
    {
       String dir = config.getParameterValue(QueryHandlerParams.PARAM_INDEX_DIR, null);
@@ -639,6 +653,61 @@
    }
 
    /**
+    * Initialize changes filter.
+    * @throws RepositoryException
+    * @throws RepositoryConfigurationException
+    * @throws ClassNotFoundException 
+    * @throws NoSuchMethodException 
+    * @throws SecurityException 
+    */
+   protected void initializeChangesFilter() throws RepositoryException, RepositoryConfigurationException
+
+   {
+      Class<? extends IndexerChangesFilter> changesFilterClass = DefaultChangesFilter.class;
+      String changesFilterClassName = config.getParameterValue(QueryHandlerParams.PARAM_CHANGES_FILTER_CLASS, null);
+      try
+      {
+         if (changesFilterClassName != null)
+         {
+            changesFilterClass =
+               (Class<? extends IndexerChangesFilter>)Class.forName(changesFilterClassName, true, this.getClass()
+                  .getClassLoader());
+         }
+         Constructor<? extends IndexerChangesFilter> constuctor =
+            changesFilterClass.getConstructor(SearchManager.class, QueryHandlerEntry.class, IndexingTree.class);
+         changesFilter = constuctor.newInstance(this, config, indexingTree);
+      }
+      catch (SecurityException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (IllegalArgumentException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (NoSuchMethodException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (InstantiationException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (IllegalAccessException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+      catch (InvocationTargetException e)
+      {
+         throw new RepositoryException(e.getMessage(), e);
+      }
+   }
+
+   /**
     * Initializes the query handler.
     * 
     * @throws RepositoryException
@@ -661,6 +730,7 @@
          QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
          QueryHandlerContext context = createQueryHandlerContext(parentHandler);
          handler.init(context);
+         changesFilter.setHandler(handler);
       }
       catch (SecurityException e)
       {
@@ -697,143 +767,29 @@
    }
 
    /**
-    * 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
-      {
-         String queryImplClassName = handler.getQueryClass();
-         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(), t);
-      }
-   }
-
-   /**
-    * {@inheritDoc}
-    */
-   public Set<String> getFieldNames() throws IndexException
-   {
-      final Set<String> fildsSet = new HashSet<String>();
-      if (handler instanceof SearchIndex)
-      {
-         IndexReader reader = null;
-         try
-         {
-            reader = ((SearchIndex)handler).getIndexReader();
-            final Collection fields = reader.getFieldNames(IndexReader.FieldOption.ALL);
-            for (final Object field : fields)
-            {
-               fildsSet.add((String)field);
-            }
-         }
-         catch (IOException e)
-         {
-            throw new IndexException(e.getLocalizedMessage(), e);
-         }
-         finally
-         {
-            try
-            {
-               if (reader != null)
-                  reader.close();
-            }
-            catch (IOException e)
-            {
-               throw new IndexException(e.getLocalizedMessage(), e);
-            }
-         }
-
-      }
-      return fildsSet;
-   }
-
-   public Set<String> getNodesByNodeType(final InternalQName nodeType) throws RepositoryException
-   {
-
-      return getNodes(virtualTableResolver.resolve(nodeType, true));
-   }
-
-   /**
-    * Return set of uuid of nodes. Contains in names prefixes maped to the
-    * given uri
-    * 
-    * @param prefix
+    * @param query
     * @return
     * @throws RepositoryException
     */
-   public Set<String> getNodesByUri(final String uri) throws RepositoryException
+   private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
    {
-      Set<String> result;
-      final int defaultClauseCount = BooleanQuery.getMaxClauseCount();
+      Set<String> result = new HashSet<String>();
       try
       {
+         QueryHits hits = handler.executeQuery(query);
 
-         // final LocationFactory locationFactory = new
-         // LocationFactory(this);
-         final ValueFactoryImpl valueFactory = new ValueFactoryImpl(new LocationFactory(nsReg));
-         BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
-         BooleanQuery query = new BooleanQuery();
+         ScoreNode sn;
 
-         final String prefix = nsReg.getNamespacePrefixByURI(uri);
-         query.add(new WildcardQuery(new Term(FieldNames.LABEL, prefix + ":*")), Occur.SHOULD);
-         // name of the property
-         query.add(new WildcardQuery(new Term(FieldNames.PROPERTIES_SET, prefix + ":*")), Occur.SHOULD);
-
-         result = getNodes(query);
-
-         // value of the property
-
-         try
+         while ((sn = hits.nextScoreNode()) != null)
          {
-            final Set<String> props = getFieldNames();
-
-            query = new BooleanQuery();
-            for (final String fieldName : props)
-            {
-               if (!FieldNames.PROPERTIES_SET.equals(fieldName))
-               {
-                  query.add(new WildcardQuery(new Term(fieldName, "*" + prefix + ":*")), Occur.SHOULD);
-               }
-            }
+            // Node node = session.getNodeById(sn.getNodeId());
+            result.add(sn.getNodeId());
          }
-         catch (final IndexException e)
-         {
-            throw new RepositoryException(e.getLocalizedMessage(), e);
-         }
-
-         final Set<String> propSet = getNodes(query);
-         // Manually check property values;
-         for (final String uuid : propSet)
-         {
-            if (isPrefixMatch(valueFactory, uuid, prefix))
-            {
-               result.add(uuid);
-            }
-         }
       }
-      finally
+      catch (IOException e)
       {
-         BooleanQuery.setMaxClauseCount(defaultClauseCount);
+         throw new RepositoryException(e.getLocalizedMessage(), e);
       }
-
       return result;
    }
 
@@ -898,31 +854,4 @@
       return false;
    }
 
-   /**
-    * @param query
-    * @return
-    * @throws RepositoryException
-    */
-   private Set<String> getNodes(final org.apache.lucene.search.Query query) throws RepositoryException
-   {
-      Set<String> result = new HashSet<String>();
-      try
-      {
-         QueryHits hits = handler.executeQuery(query);
-
-         ScoreNode sn;
-
-         while ((sn = hits.nextScoreNode()) != null)
-         {
-            // Node node = session.getNodeById(sn.getNodeId());
-            result.add(sn.getNodeId());
-         }
-      }
-      catch (IOException e)
-      {
-         throw new RepositoryException(e.getLocalizedMessage(), e);
-      }
-      return result;
-   }
-
 }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java	2009-12-07 10:11:19 UTC (rev 930)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java	2009-12-07 10:56:37 UTC (rev 931)
@@ -103,6 +103,7 @@
 
             indexingTree = new IndexingTree(indexingRootNodeData, excludedPaths);
          }
+         initializeChangesFilter();
          initializeQueryHandler();
 
       }



More information about the exo-jcr-commits mailing list