Author: nzamosenchuk
Date: 2010-06-16 09:20:35 -0400 (Wed, 16 Jun 2010)
New Revision: 2633
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-758: indexer updated
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-06-16
12:54:31 UTC (rev 2632)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-06-16
13:20:35 UTC (rev 2633)
@@ -16,8 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import java.io.IOException;
-
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -26,116 +24,128 @@
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.query.lucene.constraint.EvaluationContext;
+import org.exoplatform.services.jcr.impl.util.SecurityHelper;
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+
/**
* <code>JackrabbitIndexSearcher</code> implements an index searcher with
* jackrabbit specific optimizations.
*/
-public class JcrIndexSearcher
- extends IndexSearcher
- implements EvaluationContext {
+public class JcrIndexSearcher extends IndexSearcher implements EvaluationContext
+{
- /**
- * The session that executes the query.
- */
- private final SessionImpl session;
+ /**
+ * The session that executes the query.
+ */
+ private final SessionImpl session;
- /**
- * The underlying index reader.
- */
- private final IndexReader reader;
+ /**
+ * The underlying index reader.
+ */
+ private final IndexReader reader;
- /**
- * The item state manager of the workspace.
- */
- private final ItemDataConsumer ism;
+ /**
+ * The item state manager of the workspace.
+ */
+ private final ItemDataConsumer ism;
- /**
- * Creates a new jackrabbit index searcher.
- *
- * @param s the session that executes the query.
- * @param r the index reader.
- * @param ism the shared item state manager.
- */
- public JcrIndexSearcher(SessionImpl s,
- IndexReader r,
- ItemDataConsumer ism) {
- super(r);
- this.session = s;
- this.reader = r;
- this.ism = ism;
- }
+ /**
+ * Creates a new jackrabbit index searcher.
+ *
+ * @param s the session that executes the query.
+ * @param r the index reader.
+ * @param ism the shared item state manager.
+ */
+ public JcrIndexSearcher(SessionImpl s, IndexReader r, ItemDataConsumer ism)
+ {
+ super(r);
+ this.session = s;
+ this.reader = r;
+ this.ism = ism;
+ }
- /**
- * Executes the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @param sort the sort criteria.
- * @param resultFetchHint a hint on how many results should be fetched.
- * @param selectorName the single selector name for the query hits.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public MultiColumnQueryHits execute(Query query,
- Sort sort,
- long resultFetchHint,
- InternalQName selectorName)
- throws IOException {
- return new QueryHitsAdapter(
- evaluate(query, sort, resultFetchHint), selectorName);
- }
+ /**
+ * Executes the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @param sort the sort criteria.
+ * @param resultFetchHint a hint on how many results should be fetched.
+ * @param selectorName the single selector name for the query hits.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public MultiColumnQueryHits execute(Query query, Sort sort, long resultFetchHint,
InternalQName selectorName)
+ throws IOException
+ {
+ return new QueryHitsAdapter(evaluate(query, sort, resultFetchHint), selectorName);
+ }
- /**
- * Evaluates the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @param sort the sort criteria.
- * @param resultFetchHint a hint on how many results should be fetched.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public QueryHits evaluate(Query query, Sort sort, long resultFetchHint)
- throws IOException {
- query = query.rewrite(reader);
- QueryHits hits = null;
- if (query instanceof JcrQuery) {
- hits = ((JcrQuery) query).execute(this, session, sort);
- }
- if (hits == null) {
- if (sort == null) {
- hits = new LuceneQueryHits(reader, this, query);
- } else {
- hits = new SortedLuceneQueryHits(
- reader, this, query, sort, resultFetchHint);
+ /**
+ * Evaluates the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @param sort the sort criteria.
+ * @param resultFetchHint a hint on how many results should be fetched.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public QueryHits evaluate(final Query query, final Sort sort, final long
resultFetchHint) throws IOException
+ {
+ return SecurityHelper.doPriviledgedIOExceptionAction(new
PrivilegedExceptionAction<QueryHits>()
+ {
+ public QueryHits run() throws Exception
+ {
+ Query localQuery = query.rewrite(reader);
+ QueryHits hits = null;
+ if (localQuery instanceof JcrQuery)
+ {
+ hits = ((JcrQuery)localQuery).execute(JcrIndexSearcher.this, session,
sort);
}
- }
- return hits;
- }
+ if (hits == null)
+ {
+ if (sort == null)
+ {
+ hits = new LuceneQueryHits(reader, JcrIndexSearcher.this, localQuery);
+ }
+ else
+ {
+ hits = new SortedLuceneQueryHits(reader, JcrIndexSearcher.this,
localQuery, sort, resultFetchHint);
+ }
+ }
+ return hits;
+ }
+ });
+ }
- //------------------------< EvaluationContext >-----------------------------
+ //------------------------< EvaluationContext >-----------------------------
- /**
- * Evaluates the query and returns the hits that match the query.
- *
- * @param query the query to execute.
- * @return the query hits.
- * @throws IOException if an error occurs while executing the query.
- */
- public QueryHits evaluate(Query query) throws IOException {
- return evaluate(query, new Sort(), Integer.MAX_VALUE);
- }
+ /**
+ * Evaluates the query and returns the hits that match the query.
+ *
+ * @param query the query to execute.
+ * @return the query hits.
+ * @throws IOException if an error occurs while executing the query.
+ */
+ public QueryHits evaluate(Query query) throws IOException
+ {
+ return evaluate(query, new Sort(), Integer.MAX_VALUE);
+ }
- /**
- * @return session that executes the query.
- */
- public SessionImpl getSession() {
- return session;
- }
+ /**
+ * @return session that executes the query.
+ */
+ public SessionImpl getSession()
+ {
+ return session;
+ }
- /**
- * @return the item state manager of the workspace.
- */
- public ItemDataConsumer getItemStateManager() {
- return ism;
- }
+ /**
+ * @return the item state manager of the workspace.
+ */
+ public ItemDataConsumer getItemStateManager()
+ {
+ return ism;
+ }
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-16
12:54:31 UTC (rev 2632)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-06-16
13:20:35 UTC (rev 2633)
@@ -1426,39 +1426,45 @@
{
// File config = PrivilegedFileHelper.file(indexingConfigPath);
-
- InputStream is = SearchIndex.class.getResourceAsStream(indexingConfigPath);
- if (is == null)
+ SecurityHelper.doPriviledgedAction(new PrivilegedAction<Object>()
{
- try
+ public Object run()
{
- is = cfm.getInputStream(indexingConfigPath);
+ InputStream is =
SearchIndex.class.getResourceAsStream(indexingConfigPath);
+ if (is == null)
+ {
+ try
+ {
+ is = cfm.getInputStream(indexingConfigPath);
+ }
+ catch (Exception e1)
+ {
+ log.warn("Unable to load configuration " +
indexingConfigPath);
+ }
+ }
+
+ try
+ {
+ DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ builder.setEntityResolver(new
IndexingConfigurationEntityResolver());
+ indexingConfiguration = builder.parse(is).getDocumentElement();
+ }
+ catch (ParserConfigurationException e)
+ {
+ log.warn("Unable to create XML parser", e);
+ }
+ catch (IOException e)
+ {
+ log.warn("Exception parsing " + indexingConfigPath, e);
+ }
+ catch (SAXException e)
+ {
+ log.warn("Exception parsing " + indexingConfigPath, e);
+ }
+ return null;
}
- catch (Exception e1)
- {
- log.warn("Unable to load configuration " +
indexingConfigPath);
- }
- }
-
- try
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver(new IndexingConfigurationEntityResolver());
- indexingConfiguration = builder.parse(is).getDocumentElement();
- }
- catch (ParserConfigurationException e)
- {
- log.warn("Unable to create XML parser", e);
- }
- catch (IOException e)
- {
- log.warn("Exception parsing " + indexingConfigPath, e);
- }
- catch (SAXException e)
- {
- log.warn("Exception parsing " + indexingConfigPath, e);
- }
+ });
}
}
return indexingConfiguration;
@@ -1662,10 +1668,9 @@
* aggregate roots are collected in this map. Key=UUID,
* value=NodeState.
*/
- protected void retrieveAggregateRoot(Set<String> removedNodeIds, Map<String,
NodeData> map)
+ protected void retrieveAggregateRoot(final Set<String> removedNodeIds, final
Map<String, NodeData> map)
{
-
if (indexingConfig != null)
{
AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
@@ -1673,55 +1678,62 @@
{
return;
}
- int found = 0;
long time = System.currentTimeMillis();
- try
+ int found = SecurityHelper.doPriviledgedAction(new
PrivilegedAction<Integer>()
{
- CachingMultiIndexReader reader = index.getIndexReader();
- try
+ public Integer run()
{
- Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID,
"");
- TermDocs tDocs = reader.termDocs();
+ int found = 0;
try
{
- ItemDataConsumer ism = getContext().getItemStateManager();
- for (Iterator<String> it = removedNodeIds.iterator();
it.hasNext();)
+ CachingMultiIndexReader reader = index.getIndexReader();
+ try
{
- String id = it.next();
- aggregateUUIDs = aggregateUUIDs.createTerm(id);
- tDocs.seek(aggregateUUIDs);
- while (tDocs.next())
+ Term aggregateUUIDs = new Term(FieldNames.AGGREGATED_NODE_UUID,
"");
+ TermDocs tDocs = reader.termDocs();
+ try
{
- Document doc = reader.document(tDocs.doc(),
FieldSelectors.UUID);
- String uuid = doc.get(FieldNames.UUID);
- ItemData itd = ism.getItemData(uuid);
- if (itd == null)
+ ItemDataConsumer ism = getContext().getItemStateManager();
+ for (Iterator<String> it = removedNodeIds.iterator();
it.hasNext();)
{
- continue;
+ String id = it.next();
+ aggregateUUIDs = aggregateUUIDs.createTerm(id);
+ tDocs.seek(aggregateUUIDs);
+ while (tDocs.next())
+ {
+ Document doc = reader.document(tDocs.doc(),
FieldSelectors.UUID);
+ String uuid = doc.get(FieldNames.UUID);
+ ItemData itd = ism.getItemData(uuid);
+ if (itd == null)
+ {
+ continue;
+ }
+ if (!itd.isNode())
+ {
+ throw new RepositoryException("Item with id:"
+ uuid + " is not a node");
+ }
+ map.put(uuid, (NodeData)itd);
+ found++;
+ }
}
- if (!itd.isNode())
- {
- throw new RepositoryException("Item with id:" + uuid
+ " is not a node");
- }
- map.put(uuid, (NodeData)itd);
- found++;
}
+ finally
+ {
+ tDocs.close();
+ }
}
+ finally
+ {
+ reader.release();
+ }
}
- finally
+ catch (Exception e)
{
- tDocs.close();
+ log.warn("Exception while retrieving aggregate roots", e);
}
+ return found;
}
- finally
- {
- reader.release();
- }
- }
- catch (Exception e)
- {
- log.warn("Exception while retrieving aggregate roots", e);
- }
+ });
time = System.currentTimeMillis() - time;
log.debug("Retrieved {} aggregate roots in {} ms.", new
Integer(found), new Long(time));
}