[exo-jcr-commits] exo-jcr SVN: r3634 - in jcr/branches/1.14-IMPR/exo.jcr.component.core: src/main/java/org/exoplatform/services/jcr/datamodel and 6 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 9 07:58:50 EST 2010
Author: nzamosenchuk
Date: 2010-12-09 07:58:49 -0500 (Thu, 09 Dec 2010)
New Revision: 3634
Removed:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractLuceneQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CRTSearchIndex.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultMultiColumnQueryHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQueryHitsList.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryContextHolder.java
Modified:
jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPath.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CaseTermQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildAxisQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildNodesQueryHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CloseableHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DerefQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DescendantSelfAxisQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FilterQueryHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexFormatVersion.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexReader.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrTermQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameRangeQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllDocsQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameRangeQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTraversingQueryHits.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NotQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ParentAxisQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryHitsQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RangeQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNode.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SimilarityQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/WildcardQuery.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/constraint/EvaluationContext.java
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-1080 : reverting previous commit back to vanilla code
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-09 12:58:49 UTC (rev 3634)
@@ -380,7 +380,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <!--argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine-->
+ <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
@@ -433,7 +433,6 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/TestLinkedWorkspaceStorageCacheMetrics.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/SQLBenchmarkTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestLockPerstistentDataManager.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/TestSecurityRepositoryManagment.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestCleanableFileStreamValueData.java</exclude>
</excludes>
</configuration>
@@ -581,7 +580,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TAKE CARE TO UPDATE ALSO run-all PROFILE -->
- <!--argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine-->
+ <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
@@ -658,7 +657,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- TAKE CARE TO UPDATE ALSO run-tck PROFILE -->
- <!--argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine-->
+ <argLine>${env.MAVEN_OPTS} -Djava.security.manager=org.exoplatform.commons.test.TestSecurityManager -Djava.security.policy=${project.build.directory}/test-classes/test.policy</argLine>
<systemProperties>
<property>
<name>jcr.test.configuration.file</name>
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -20,8 +20,6 @@
import org.exoplatform.commons.utils.QName;
-import java.io.Serializable;
-
/**
* Created by The eXo Platform SAS.
*
@@ -29,18 +27,10 @@
* @version $Id: InternalQName.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class InternalQName extends QName implements Serializable
+public class InternalQName extends QName
{
/**
- * for serialization
- */
- public InternalQName()
- {
- super();
- }
-
- /**
* InternalQName constructor.
*
* @param namespace
@@ -72,15 +62,11 @@
{
if (!qName.startsWith("["))
- {
throw new IllegalNameException("Invalid Internal QName '" + qName + "' Should start of '['");
- }
int uriStart = 0;
int uriFinish = qName.indexOf("]", uriStart);
if (uriFinish == -1)
- {
throw new IllegalNameException("Invalid Internal QName '" + qName + "' No closed ']'");
- }
String uri = qName.substring(uriStart + 1, uriFinish);
String localName = qName.substring(uriFinish + 1, qName.length());
return new InternalQName(uri, localName);
@@ -93,14 +79,10 @@
public boolean equals(Object o)
{
if (o == this)
- {
return true;
- }
if (o == null)
- {
return false;
- }
if (o instanceof InternalQName)
{
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPath.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPath.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPath.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -22,7 +22,6 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -36,7 +35,7 @@
* @version $Id: QPath.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class QPath implements Comparable<QPath>, Serializable
+public class QPath implements Comparable<QPath>
{
/**
* Logger.
@@ -46,17 +45,17 @@
/**
* QPath prefix delimiter.
*/
- public final static String PREFIX_DELIMITER = ":";
+ public static final String PREFIX_DELIMITER = ":";
/**
* Names storage.
*/
- private QPathEntry[] names;
+ private final QPathEntry[] names;
/**
* Path hash code.
*/
- private int hashCode;
+ private final int hashCode;
/**
* String representation of the path.
@@ -64,13 +63,6 @@
private String stringName;
/**
- * For serialization
- */
- public QPath()
- {
- }
-
- /**
* QPath constructor.
*
* @param names
@@ -97,13 +89,9 @@
public boolean isAbsolute()
{
if (names[0].getIndex() == 1 && names[0].getName().length() == 0 && names[0].getNamespace().length() == 0)
- {
return true;
- }
else
- {
return false;
- }
}
/**
@@ -149,10 +137,8 @@
int len = getLength() - relativeDegree;
if (len < 0)
- {
throw new IllegalPathException("Relative degree " + relativeDegree + " is more than depth for "
+ getAsString());
- }
QPathEntry[] relPath = new QPathEntry[relativeDegree];
System.arraycopy(names, len, relPath, 0, relPath.length);
@@ -185,16 +171,12 @@
final InternalQName[] ancestorNames = ancestorPath.names;
if (names.length - ancestorNames.length <= 0)
- {
return false;
- }
for (int i = 0; i < ancestorNames.length; i++)
{
if (!names[i].equals(ancestorNames[i]))
- {
return false;
- }
}
return true;
}
@@ -212,17 +194,13 @@
// int depthDiff = getDepth() - anotherPath.getDepth();
int depthDiff = names.length - anotherNames.length;
if (depthDiff <= 0 || (childOnly && depthDiff != 1))
- {
return false;
- }
// InternalQName[] anotherNames = anotherPath.getEntries();
for (int i = 0; i < anotherNames.length; i++)
{
if (!anotherNames[i].equals(names[i]))
- {
return false;
- }
}
return true;
}
@@ -321,14 +299,10 @@
public boolean equals(Object o)
{
if (o == this)
- {
return true;
- }
if (!(o instanceof QPath))
- {
return false;
- }
return hashCode == o.hashCode();
}
@@ -339,9 +313,7 @@
public int compareTo(QPath compare)
{
if (compare.equals(this))
- {
return 0;
- }
QPathEntry[] e1 = names;
QPathEntry[] e2 = compare.getEntries();
@@ -386,14 +358,10 @@
public static QPath parse(String qPath) throws IllegalPathException
{
if (qPath == null)
- {
throw new IllegalPathException("Bad internal path '" + qPath + "'");
- }
if (qPath.length() < 2 || !qPath.startsWith("[]"))
- {
throw new IllegalPathException("Bad internal path '" + qPath + "'");
- }
int uriStart = 0;
List<QPathEntry> entries = new ArrayList<QPathEntry>();
@@ -412,9 +380,7 @@
uriStart = -1;
}
else
- {
uriStart = tmp;
- }
String localName = qPath.substring(uriFinish + 1, tmp);
int index = 0;
@@ -427,10 +393,8 @@
else
{
if (uriStart > -1)
- {
throw new IllegalPathException("Bad internal path '" + qPath
+ "' each intermediate name should have index");
- }
}
entries.add(new QPathEntry(uri, localName, index));
@@ -522,14 +486,10 @@
final QPathEntry[] names = new QPathEntry[parentEntries.length + relEntries.length];
int index = 0;
for (QPathEntry name : parentEntries)
- {
names[index++] = name;
- }
for (QPathEntry name : relEntries)
- {
names[index++] = name;
- }
QPath path = new QPath(names);
return path;
@@ -558,9 +518,7 @@
final QPathEntry[] names = new QPathEntry[parentEntries.length + 1];
int index = 0;
for (QPathEntry name : parentEntries)
- {
names[index++] = name;
- }
names[index] = relEntry;
@@ -579,15 +537,11 @@
{
if (!entry.startsWith("["))
- {
throw new IllegalPathException("Invalid QPath Entry '" + entry + "' Should start of '['");
- }
final int uriStart = 0;
final int uriFinish = entry.indexOf("]", uriStart);
if (uriFinish == -1)
- {
throw new IllegalPathException("Invalid QPath Entry '" + entry + "' No closed ']'");
- }
final String uri = entry.substring(uriStart + 1, uriFinish);
final String localName = entry.substring(uriFinish + 1, entry.length());
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -30,21 +30,13 @@
/**
* QPath index.
*/
- private int index;
+ private final int index;
private String cachedToString;
private String cachedToStringShowIndex;
/**
- * For serialization
- */
- public QPathEntry()
- {
- super();
- }
-
- /**
* QPathEntry constructor.
*
* @param qName
@@ -119,9 +111,7 @@
public boolean isSame(QPathEntry obj)
{
if (super.equals(obj))
- {
return index == obj.getIndex();
- }
return false;
}
@@ -190,17 +180,13 @@
int result = 0;
if (this.isSame(compare))
- {
return result;
- }
result = namespace.compareTo(compare.namespace);
if (result == 0)
{
result = name.compareTo(compare.name);
if (result == 0)
- {
result = index - compare.index;
- }
}
return result;
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -121,7 +121,7 @@
* @return XASessionImpl if TransactionService present or SessionImpl otherwise
* @throws RepositoryException
*/
- public SessionImpl createSession(ConversationState user) throws RepositoryException, LoginException
+ SessionImpl createSession(ConversationState user) throws RepositoryException, LoginException
{
if (IdentityConstants.SYSTEM.equals(user.getIdentity().getUserId()))
{
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -27,7 +27,6 @@
import org.exoplatform.services.jcr.config.QueryHandlerParams;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
-import org.exoplatform.services.jcr.core.NamespaceAccessor;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.dataflow.ItemState;
@@ -40,11 +39,9 @@
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.datamodel.ValueData;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.RepositoryContainer;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
import org.exoplatform.services.jcr.impl.core.SessionDataManager;
-import org.exoplatform.services.jcr.impl.core.SessionFactory;
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.query.lucene.FieldNames;
import org.exoplatform.services.jcr.impl.core.query.lucene.LuceneVirtualTableResolver;
@@ -57,7 +54,6 @@
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rpc.RPCService;
import org.jboss.cache.factories.annotations.NonVolatile;
import org.picocontainer.Startable;
@@ -76,7 +72,6 @@
import javax.jcr.Node;
import javax.jcr.PropertyType;
-import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.query.InvalidQueryException;
@@ -145,11 +140,7 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
- protected SessionFactory sessionFactory;
-
- protected final RPCService rpcService;
-
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -174,10 +165,9 @@
* @throws RepositoryConfigurationException
*/
- public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg,
- NodeTypeDataManager ntReg, WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
- DocumentReaderService extractor, ConfigurationManager cfm,
- final RepositoryIndexSearcherHolder indexSearcherHolder, SessionFactory sessionFactory, RPCService rpcService)
+ public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder parentSearchManager,
+ DocumentReaderService extractor, ConfigurationManager cfm, final RepositoryIndexSearcherHolder indexSearcherHolder)
throws RepositoryException, RepositoryConfigurationException
{
this.wsId = wsConfig.getUniqueName();
@@ -190,9 +180,6 @@
this.cfm = cfm;
this.virtualTableResolver = new LuceneVirtualTableResolver(nodeTypeDataManager, nsReg);
this.parentSearchManager = parentSearchManager != null ? parentSearchManager.get() : null;
- this.sessionFactory = sessionFactory;
- this.rpcService = rpcService;
-
if (parentSearchManager != null)
{
((WorkspacePersistentDataManager)this.itemMgr).addItemPersistenceListener(this);
@@ -290,9 +277,7 @@
try
{
if (reader != null)
- {
reader.close();
- }
}
catch (IOException e)
{
@@ -405,9 +390,7 @@
{
if (log.isDebugEnabled())
- {
log.debug("start");
- }
try
{
if (indexingTree == null)
@@ -429,9 +412,7 @@
{
ItemData excludeData = itemMgr.getItemData(stringTokenizer.nextToken());
if (excludeData != null)
- {
excludedPath.add(excludeData.getQPath());
- }
}
catch (RepositoryException e)
{
@@ -448,9 +429,7 @@
{
ItemData indexingRootDataItem = itemMgr.getItemData(rootNodeIdentifer);
if (indexingRootDataItem != null && indexingRootDataItem.isNode())
- {
indexingRootData = (NodeData)indexingRootDataItem;
- }
}
catch (RepositoryException e)
{
@@ -531,20 +510,14 @@
if (item.isNode())
{
if (!indexingTree.isExcluded(item))
- {
return (NodeData)item;
- }
}
else
- {
log.warn("Node not found, but property " + id + ", " + item.getQPath().getAsString()
+ " found. ");
- }
}
else
- {
log.warn("Unable to index node with id " + id + ", node does not exist.");
- }
}
catch (RepositoryException e)
@@ -735,21 +708,13 @@
// initialize query handler
String className = config.getType();
if (className == null)
- {
throw new RepositoryConfigurationException("Content hanler configuration fail");
- }
try
{
Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
- // (QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm, RPCService rpcService, String wsId, NamespaceAccessor namespaceAccessor, ItemDataConsumer dataConsumer)
- Constructor constuctor =
- qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class, RPCService.class,
- String.class, NamespaceAccessor.class, ItemDataConsumer.class);
- // TODO
-
- handler = (QueryHandler)constuctor.newInstance(config, cfm, this.rpcService, this.wsId, nsReg, itemMgr);
-
+ Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
+ handler = (QueryHandler)constuctor.newInstance(config, cfm);
QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
QueryHandlerContext context = createQueryHandlerContext(parentHandler);
handler.setContext(context);
@@ -759,61 +724,34 @@
changesFilter = initializeChangesFilter();
}
}
- catch (Exception e)
+ catch (SecurityException e)
{
- log.error("Problem creating CRT Search Index");
- log.error(e);
- e.printStackTrace();
+ throw new RepositoryException(e.getMessage(), e);
}
-
- if (handler == null)
+ catch (IllegalArgumentException e)
{
- try
- {
- Class qHandlerClass = Class.forName(className, true, this.getClass().getClassLoader());
- Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class, ConfigurationManager.class);
- handler = (QueryHandler)constuctor.newInstance(config, cfm);
- QueryHandler parentHandler = (this.parentSearchManager != null) ? parentSearchManager.getHandler() : null;
- QueryHandlerContext context = createQueryHandlerContext(parentHandler);
- handler.setContext(context);
-
- // SessionFactory sessionFactory = workspaceContainer.getSessionFactory();
- // sessionFactory.createSession(authenticationPolicy.authenticate(SYSTEM_CREDENTIALS));
-
- if (parentSearchManager != null)
- {
- changesFilter = initializeChangesFilter();
- }
- }
- 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);
- }
+ 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);
+ }
}
/**
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -25,13 +25,10 @@
import org.exoplatform.services.jcr.datamodel.NodeData;
import org.exoplatform.services.jcr.datamodel.QPath;
import org.exoplatform.services.jcr.impl.Constants;
-import org.exoplatform.services.jcr.impl.RepositoryContainer;
import org.exoplatform.services.jcr.impl.core.NamespaceRegistryImpl;
-import org.exoplatform.services.jcr.impl.core.SessionFactory;
import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.exoplatform.services.rpc.RPCService;
import java.util.ArrayList;
import java.util.List;
@@ -60,13 +57,11 @@
public static final String INDEX_DIR_SUFFIX = "system";
- public SystemSearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg,
- NodeTypeDataManager ntReg, WorkspacePersistentDataManager itemMgr, DocumentReaderService service,
- ConfigurationManager cfm, RepositoryIndexSearcherHolder indexSearcherHolder, SessionFactory sessionFactory,
- RPCService rpcService) throws RepositoryException, RepositoryConfigurationException
+ public SystemSearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config, NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
+ WorkspacePersistentDataManager itemMgr, DocumentReaderService service, ConfigurationManager cfm,
+ RepositoryIndexSearcherHolder indexSearcherHolder) throws RepositoryException, RepositoryConfigurationException
{
- super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder, sessionFactory,
- rpcService);
+ super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm, indexSearcherHolder);
}
@Override
Deleted: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractLuceneQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractLuceneQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractLuceneQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2010 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.lucene;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.search.Query;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: AbstractLuceneQuery.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public abstract class AbstractLuceneQuery extends Query
-{
- private static final long serialVersionUID = 1L;
-
- // skip it's serialization
- protected transient QueryContextHolder contextHolder;
-
- /**
- * The item state manager containing persistent item states.
- */
- private transient ItemDataConsumer itemMgr;
-
- /**
- * The internal namespace mappings.
- */
- private transient NamespaceMappings nsMappings;
-
- private transient Analyzer analyzer;
-
- /**
- * Default constructor for serialization
- */
- public AbstractLuceneQuery()
- {
- super();
- }
-
- public AbstractLuceneQuery(ItemDataConsumer itemMgr, NamespaceMappings nsMappings)
- {
- super();
- this.itemMgr = itemMgr;
- this.nsMappings = nsMappings;
- this.analyzer = null;
- }
-
- public AbstractLuceneQuery(Analyzer analyzer)
- {
- super();
- this.itemMgr = null;
- this.nsMappings = null;
- this.analyzer = analyzer;
- }
-
- public QueryContextHolder getContextHolder()
- {
- // TODO REMOVE THIS ASSERT
- //assert contextHolder != null;
- return contextHolder;
- }
-
- public void setContextHolder(QueryContextHolder contextHolder)
- {
- if (contextHolder != null)
- {
- this.contextHolder = contextHolder;
- }
- }
-
- public ItemDataConsumer getDataManager()
- {
- if (itemMgr != null)
- {
- return itemMgr;
- }
- else if (contextHolder != null)
- {
- return getContextHolder().getDataManger();
- }
- return null;
- }
-
- public NamespaceMappings getNamespaceMappings()
- {
- if (nsMappings != null)
- {
- return nsMappings;
- }
- else if (contextHolder != null)
- {
- return getContextHolder().getNamespaceMappings();
- }
- return null;
- }
-
- public Analyzer getAnalyzer()
- {
- if (analyzer != null)
- {
- return analyzer;
- }
- else
- {
- return getContextHolder().getAnalyzer();
- }
- }
-}
Deleted: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CRTSearchIndex.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CRTSearchIndex.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CRTSearchIndex.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -1,484 +0,0 @@
-/*
- * Copyright (C) 2010 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.lucene;
-
-import com.thoughtworks.xstream.core.ReferenceByIdMarshaller.IDGenerator;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.Sort;
-import org.exoplatform.container.configuration.ConfigurationManager;
-import org.exoplatform.services.jcr.config.QueryHandlerEntry;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.core.NamespaceAccessor;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.datamodel.QPath;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import org.exoplatform.services.jcr.util.IdGenerator;
-import org.exoplatform.services.rpc.RPCException;
-import org.exoplatform.services.rpc.RPCService;
-import org.exoplatform.services.rpc.RemoteCommand;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.jcr.RepositoryException;
-
-/**
- * Clustered RealTime Search Index implementation
- *
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: CRTSearchIndex.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class CRTSearchIndex extends SearchIndex
-{
- private static final Logger log = LoggerFactory.getLogger("exo.jcr.component.core.SearchIndex");
-
- private final RPCService rpcService;
-
- private final QueryContextHolder contextHolder;
-
- private final String wsName;
-
- private final RemoteCommand executeQuery;
-
- private final RemoteCommand executeQuery2;
-
- private final RemoteCommand executeQuery3;
-
- /**
- * Non-clustered default behavior
- *
- * @param queryHandlerConfig
- * @param cfm
- * @throws IOException
- * @throws RepositoryConfigurationException
- */
- // public CRTSearchIndex(QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm) throws IOException,
- // RepositoryConfigurationException
- // {
- // super(queryHandlerConfig, cfm);
- // this.rpcService = null;
- // this.contextHolder = null;
- // this.wsName = null;
- // this.executeQuery = null;
- // this.executeQuery2 = null;
- // this.executeQuery3 = null;
- // }
-
- /**
- * @param queryHandlerConfig
- * @param cfm
- * @param rpcService
- * @throws IOException
- * @throws RepositoryConfigurationException
- */
- public CRTSearchIndex(QueryHandlerEntry queryHandlerConfig, ConfigurationManager cfm, RPCService rpcService,
- String wsId, NamespaceAccessor namespaceAccessor, ItemDataConsumer dataConsumer) throws IOException,
- RepositoryConfigurationException
- {
- super(queryHandlerConfig, cfm);
- log.info("CRT Creating...");
- this.rpcService = rpcService;
-
- this.contextHolder = new QueryContextHolder(dataConsumer, namespaceAccessor);
- this.contextHolder.setAnalyzer(getTextAnalyzer());
- this.wsName = wsId;
-
- executeQuery = rpcService.registerCommand(new RemoteCommand()
- {
- public String getId()
- {
- return "executeQuery-" + wsName;
- }
-
- public Serializable execute(Serializable[] args) throws Throwable
- {
- try
- {
- //log.info("COORDINATOR execution : " + getId() + " isCoordinator: " + CRTSearchIndex.this.rpcService.isCoordinator());
- Query query = (Query)args[0];
- // Injecting dependencies into remote query
- if (query instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)query).setContextHolder(contextHolder);
- }
- return CRTSearchIndex.this.executeQueryInternal(query);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- }
- });
-
- executeQuery2 = rpcService.registerCommand(new RemoteCommand()
- {
- public String getId()
- {
- return "executeQuery2-" + wsName;
- }
-
- public Serializable execute(Serializable[] args) throws Throwable
- {
- try
- {
- //log.info("COORDINATOR execution : " + getId() + " isCoordinator: " + CRTSearchIndex.this.rpcService.isCoordinator());
- // executeQueryInternal(needsSystemTree, query, orderPropsList, orderSpecsList, resultFetchHint)
- boolean needsSystemTree = (Boolean)args[0];
- Query query = (Query)args[1];
- // Injecting dependencies into remote query
- if (query instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)query).setContextHolder(contextHolder);
- }
- QPath[] orderProps = (QPath[])args[2];
- boolean[] orderSpecs = (boolean[])args[3];
- long resultFetchHint = (Long)args[4];
- MultiColumnQueryHitsList columnQueryHitsList =
- CRTSearchIndex.this.executeQueryInternal(needsSystemTree, query, orderProps, orderSpecs,
- resultFetchHint);
- //log.info("\n\n\n>>>size: " + columnQueryHitsList.getNodes().size());
- return columnQueryHitsList;
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- //new DefaultMultiColumnQueryHits(columnQueryHitsList.getNodes(), columnQueryHitsList.getSelectors());
- }
- });
-
- executeQuery3 = rpcService.registerCommand(new RemoteCommand()
- {
- public String getId()
- {
- return "executeQuery3-" + wsName;
- }
-
- public Serializable execute(Serializable[] args) throws Throwable
- {
- try
- {
- // log.info("COORDINATOR execution : " + getId() + " isCoordinator: " + CRTSearchIndex.this.rpcService.isCoordinator());
- MultiColumnQuery query = (MultiColumnQuery)args[0];
- // Injecting dependencies into remote query
- if (query instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)query).setContextHolder(contextHolder);
- }
-
- QPath[] orderProps = (QPath[])args[1];
- boolean[] orderSpecs = (boolean[])args[2];
- long resultFetchHint = (Long)args[3];
- MultiColumnQueryHitsList columnQueryHitsList =
- executeQueryInternal(query, orderProps, orderSpecs, resultFetchHint);
- // log.info("\n\n\n>>>size: " + columnQueryHitsList.getNodes().size());
- return columnQueryHitsList;
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw e;
- }
- //new DefaultMultiColumnQueryHits(columnQueryHitsList.getNodes(), columnQueryHitsList.getSelectors());
- }
- });
- }
-
- @Override
- public QueryHits executeQuery(Query query) throws IOException
- {
- if (rpcService == null)
- {
- return super.executeQuery(query);
- }
-
- try
- {
- return new DefaultQueryHits((Collection)rpcService.executeCommandOnCoordinator(executeQuery, true, query));
- }
- catch (SecurityException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- catch (RPCException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- }
-
- @Override
- public MultiColumnQueryHits executeQuery(SessionImpl session, AbstractQueryImpl queryImpl, Query query,
- QPath[] orderProps, boolean[] orderSpecs, long resultFetchHint) throws IOException, RepositoryException
- {
- if (rpcService == null)
- {
- return super.executeQuery(session, queryImpl, query, orderProps, orderSpecs, resultFetchHint);
- }
-
- // ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- // ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
- // objectOutputStream.writeObject(query);
- // objectOutputStream.close();
- //
- // ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
- // ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
- // Query query2 = null;
- // try
- // {
- // query2 = (Query)objectInputStream.readObject();
- // }
- // catch (ClassNotFoundException e)
- // {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
- // objectInputStream.close();
- //
- // MultiColumnQueryHitsList columnQueryHitsList =
- // CRTSearchIndex.this.executeQueryInternal(queryImpl.needsSystemTree(), query2, orderProps, orderSpecs,
- // resultFetchHint);
- // return new DefaultMultiColumnQueryHits(columnQueryHitsList.getNodes(), columnQueryHitsList.getSelectors());
-
- try
- {
- // executeQueryInternal(needsSystemTree, query, orderPropsList, orderSpecsList, resultFetchHint)
-
- Object result =
- rpcService.executeCommandOnCoordinator(executeQuery2, true, queryImpl.needsSystemTree(), query, orderProps,
- orderSpecs, resultFetchHint);
- MultiColumnQueryHitsList columnQueryHitsList = (MultiColumnQueryHitsList)result;
- //log.info("\n\n\n<<<size: " + columnQueryHitsList.getNodes().size());
- return new DefaultMultiColumnQueryHits(columnQueryHitsList.getNodes(), columnQueryHitsList.getSelectors());
- }
- catch (SecurityException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- catch (RPCException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- }
-
- @Override
- public MultiColumnQueryHits executeQuery(SessionImpl session, MultiColumnQuery query, QPath[] orderProps,
- boolean[] orderSpecs, long resultFetchHint) throws IOException, RepositoryException
- {
- if (rpcService == null)
- {
- return super.executeQuery(session, query, orderProps, orderSpecs, resultFetchHint);
- }
- try
- {
- // executeQueryInternal(query, orderProps, orderSpecs, resultFetchHint);
- MultiColumnQueryHitsList columnQueryHitsList =
- (MultiColumnQueryHitsList)rpcService.executeCommandOnCoordinator(executeQuery3, true, query, orderProps,
- orderSpecs, resultFetchHint);
- //log.info("\n\n\n<<<size: " + columnQueryHitsList.getNodes().size());
- return new DefaultMultiColumnQueryHits(columnQueryHitsList.getNodes(), columnQueryHitsList.getSelectors());
- }
- catch (SecurityException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- catch (RPCException e)
- {
- throw new ExttendedIOException("Exception during query execution on coordinator side: ", e);
- }
- }
-
- // ==============================================================
-
- private MultiColumnQueryHitsList executeQueryInternal(boolean needsSystemTree, Query query, QPath[] orderProps,
- boolean[] orderSpecs, long resultFetchHint) throws IOException, RepositoryException
- {
- // copy-paste from super.executeQuery(session, queryImpl, query, orderProps, orderSpecs, resultFetchHint);
- checkOpen();
- // QPath[] orderProps = new QPath[orderPropsList.size()];
- // for (int i = 0; i < orderPropsList.size(); i++)
- // {
- // orderProps[i] = QPath.parse(orderPropsList.get(i));
- // }
- // boolean[] orderSpecs = new boolean[orderSpecsList.size()];
- // for (int i = 0; i < orderSpecsList.size(); i++)
- // {
- // orderSpecs[i] = orderSpecsList.get(i);
- // }
- Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
-
- final IndexReader reader = getIndexReader(needsSystemTree);
- JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader, getContext().getItemStateManager());
- searcher.setSimilarity(getSimilarity());
- MultiColumnQueryHits multiColumnQueryHits =
- new FilterMultiColumnQueryHits(searcher.execute(query, sort, resultFetchHint, QueryImpl.DEFAULT_SELECTOR_NAME))
- {
- @Override
- public void close() throws IOException
- {
- try
- {
- super.close();
- }
- finally
- {
- PerQueryCache.getInstance().dispose();
- Util.closeOrRelease(reader);
- }
- }
- };
- MultiColumnQueryHitsList hitsList =
- new MultiColumnQueryHitsList(hitsToList(multiColumnQueryHits), multiColumnQueryHits.getSelectorNames());
- multiColumnQueryHits.close();
- return hitsList;
- }
-
- private MultiColumnQueryHitsList executeQueryInternal(MultiColumnQuery query, QPath[] orderProps,
- boolean[] orderSpecs, long resultFetchHint) throws IOException, RepositoryException
- {
- // QPath[] orderProps = new QPath[orderPropsList.size()];
- // for (int i = 0; i < orderPropsList.size(); i++)
- // {
- // orderProps[i] = QPath.parse(orderPropsList.get(i));
- // }
- // boolean[] orderSpecs = new boolean[orderSpecsList.size()];
- // for (int i = 0; i < orderSpecsList.size(); i++)
- // {
- // orderSpecs[i] = orderSpecsList.get(i);
- // }
- // MultiColumnQueryHits multiColumnQueryHits =
- // super.executeQuery(contextHolder, query, orderProps, orderSpecs, resultFetchHint);
- checkOpen();
-
- Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
-
- final IndexReader reader = getIndexReader();
- JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader, getContext().getItemStateManager());
- searcher.setSimilarity(getSimilarity());
- MultiColumnQueryHits multiColumnQueryHits =
- new FilterMultiColumnQueryHits(query.execute(searcher, sort, resultFetchHint))
- {
- @Override
- public void close() throws IOException
- {
- try
- {
- super.close();
- }
- finally
- {
- PerQueryCache.getInstance().dispose();
- Util.closeOrRelease(reader);
- }
- }
- };
- MultiColumnQueryHitsList hitsList =
- new MultiColumnQueryHitsList(hitsToList(multiColumnQueryHits), multiColumnQueryHits.getSelectorNames());
- multiColumnQueryHits.close();
- return hitsList;
- }
-
- private ArrayList<ScoreNode> executeQueryInternal(Query query) throws IOException
- {
- return hitsToList(super.executeQuery(query));
- }
-
- // ==================== UTILS ====================
-
- /**
- * Extracts all ScoreNodes into the list
- *
- * @param hits
- * @return
- * @throws IOException
- */
- private ArrayList<ScoreNode> hitsToList(QueryHits hits) throws IOException
- {
- ArrayList<ScoreNode> list = new ArrayList<ScoreNode>();
- ScoreNode scoreNode = null;
- do
- {
- scoreNode = hits.nextScoreNode();
- if (scoreNode != null)
- {
- list.add(scoreNode);
- }
- }
- while (scoreNode != null);
- return list;
- }
-
- /**
- * Extracts all ScoreNodes into the list
- *
- * @param hits
- * @return
- * @throws IOException
- */
- private List<ScoreNode[]> hitsToList(MultiColumnQueryHits hits) throws IOException
- {
- List<ScoreNode[]> list = new ArrayList<ScoreNode[]>();
- ScoreNode[] scoreNodes = null;
- do
- {
- scoreNodes = hits.nextScoreNodes();
- if (scoreNodes != null)
- {
- if (scoreNodes.length > 1)
- {
- System.out.println("\n\n\n\n\n\n" + scoreNodes.length + "\n\n\n\n\n");
- }
- list.add(scoreNodes);
- }
- }
- while (scoreNodes != null);
- return list;
- }
-
- private class ExttendedIOException extends IOException
- {
- private Throwable cause;
-
- public ExttendedIOException(String message, Throwable cause)
- {
- super(message);
- this.cause = cause;
- }
-
- public Throwable getCause()
- {
- return cause;
- }
- }
-
-}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CaseTermQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CaseTermQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CaseTermQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -39,7 +39,7 @@
* Indicates whether terms from the index should be lower-cased or
* upper-cased.
*/
- protected int transform;
+ protected final int transform;
CaseTermQuery(Term term, int transform) {
super(term);
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildAxisQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildAxisQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildAxisQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -31,6 +31,7 @@
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.core.query.LocationStepQueryNode;
import org.exoplatform.services.jcr.impl.core.query.lucene.hits.AdaptingHits;
import org.exoplatform.services.jcr.impl.core.query.lucene.hits.Hits;
@@ -53,7 +54,7 @@
* Implements a lucene <code>Query</code> which returns the child nodes of the
* nodes selected by another <code>Query</code>.
*/
-class ChildAxisQuery extends AbstractLuceneQuery implements JcrQuery
+class ChildAxisQuery extends Query implements JcrQuery
{
/**
@@ -68,6 +69,11 @@
private static int CONTEXT_SIZE_THRESHOLD = 10;
/**
+ * The item state manager containing persistent item states.
+ */
+ private final ItemDataConsumer itemMgr;
+
+ /**
* The context query
*/
private Query contextQuery;
@@ -76,36 +82,33 @@
* The nameTest to apply on the child axis, or <code>null</code> if all
* child nodes should be selected.
*/
- private InternalQName nameTest;
+ private final InternalQName nameTest;
/**
* The context position for the selected child node, or
* {@link LocationStepQueryNode#NONE} if no position is specified.
*/
- private int position;
+ private final int position;
/**
* The index format version.
*/
- private IndexFormatVersion version;
+ private final IndexFormatVersion version;
/**
- * The scorer of the context query
+ * The internal namespace mappings.
*/
- private transient Scorer contextScorer;
+ private final NamespaceMappings nsMappings;
/**
- * The scorer of the name test query
+ * The scorer of the context query
*/
- private transient Scorer nameTestScorer;
+ private Scorer contextScorer;
/**
- * for serialization
+ * The scorer of the name test query
*/
- public ChildAxisQuery()
- {
- super();
- }
+ private Scorer nameTestScorer;
/**
* Creates a new <code>ChildAxisQuery</code> based on a <code>context</code>
@@ -141,11 +144,12 @@
ChildAxisQuery(ItemDataConsumer itemMgr, Query context, InternalQName nameTest, int position,
IndexFormatVersion version, NamespaceMappings nsMapping)
{
- super(itemMgr, nsMapping);
+ this.itemMgr = itemMgr;
this.contextQuery = context;
this.nameTest = nameTest;
this.position = position;
this.version = version;
+ this.nsMappings = nsMapping;
}
/**
@@ -206,11 +210,6 @@
*/
public Query rewrite(IndexReader reader) throws IOException
{
- if (reader instanceof JcrIndexReader && contextQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)contextQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
Query cQuery = contextQuery.rewrite(reader);
// only try to compact if no position is specified
if (position == LocationStepQueryNode.NONE)
@@ -227,7 +226,7 @@
}
else
{
- sub = new NameQuery(nameTest, version, getNamespaceMappings());
+ sub = new NameQuery(nameTest, version, nsMappings);
}
return new DescendantSelfAxisQuery(dsaq.getContextQuery(), sub, dsaq.getMinLevels() + 1).rewrite(reader);
}
@@ -241,17 +240,7 @@
}
else
{
- AbstractLuceneQuery newQuery =
- new ChildAxisQuery(getDataManager(), cQuery, nameTest, position, version, getNamespaceMappings());
- if (reader instanceof JcrIndexReader)
- {
- newQuery.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- else
- {
- log.error("reader is not JCRIndexReader");
- }
- return newQuery;
+ return new ChildAxisQuery(itemMgr, cQuery, nameTest, position, version, nsMappings);
}
}
@@ -279,12 +268,12 @@
/**
* {@inheritDoc}
*/
- public QueryHits execute(JcrIndexSearcher searcher, QueryContextHolder contextHolder, Sort sort) throws IOException
+ public QueryHits execute(JcrIndexSearcher searcher, SessionImpl session, Sort sort) throws IOException
{
if (sort.getSort().length == 0 && matchesAnyChildNode())
{
Query context = getContextQuery();
- return new ChildNodesQueryHits(searcher.evaluate(context), contextHolder);
+ return new ChildNodesQueryHits(searcher.evaluate(context), session);
}
else
{
@@ -361,7 +350,7 @@
contextScorer = contextQuery.weight(searcher).scorer(reader);
if (nameTest != null)
{
- nameTestScorer = new NameQuery(nameTest, version, getNamespaceMappings()).weight(searcher).scorer(reader);
+ nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader);
}
return new ChildAxisScorer(searcher.getSimilarity(), reader, (HierarchyResolver)reader);
}
@@ -536,7 +525,7 @@
try
{
//NodeState state = (NodeState) itemMgr.getItemState(parentId);
- NodeData state = (NodeData)getDataManager().getItemData(parentId);
+ NodeData state = (NodeData)itemMgr.getItemData(parentId);
if (nameTest == null)
{
// only select this node if it is the child at
@@ -544,7 +533,7 @@
if (position == LocationStepQueryNode.LAST)
{
// only select last
- List<NodeData> childNodes = getDataManager().getChildNodesData(state);
+ List<NodeData> childNodes = itemMgr.getChildNodesData(state);
if (childNodes.size() == 0 || !childNodes.get(childNodes.size() - 1).getIdentifier().equals(id))
{
return false;
@@ -552,7 +541,7 @@
}
else
{
- List<NodeData> childNodes = getDataManager().getChildNodesData(state);
+ List<NodeData> childNodes = itemMgr.getChildNodesData(state);
if (position < 1 || childNodes.size() < position
|| !childNodes.get(position - 1).getIdentifier().equals(id))
{
@@ -576,7 +565,7 @@
else
{
// only use the last one
- List<NodeData> childNodes = getDataManager().getChildNodesData(state);
+ List<NodeData> childNodes = itemMgr.getChildNodesData(state);
if (childNodes.size() == 0 || !childNodes.get(childNodes.size() - 1).getIdentifier().equals(id))
{
return false;
@@ -585,7 +574,7 @@
}
else
{
- NodeData nodeData = (NodeData)getDataManager().getItemData(id);
+ NodeData nodeData = (NodeData)itemMgr.getItemData(id);
if (nodeData == null)
{
// no such child node, probably has been deleted meanwhile
@@ -594,9 +583,7 @@
else
{
if (nodeData.getQPath().getIndex() != position)
- {
return false;
- }
}
}
}
@@ -664,7 +651,7 @@
/**
* The context hits.
*/
- private transient final Hits contextHits = new AdaptingHits();
+ private final Hits contextHits = new AdaptingHits();
/**
* Creates a new simple children calculator.
@@ -707,14 +694,14 @@
try
{
long time = System.currentTimeMillis();
- NodeData state = (NodeData)getDataManager().getItemData(uuid);
+ NodeData state = (NodeData)itemMgr.getItemData(uuid);
time = System.currentTimeMillis() - time;
log.debug("got NodeState with id {} in {} ms.", uuid, new Long(time));
Iterator<NodeData> entries;
if (nameTest != null)
{
//NodeData childNodeData = (NodeData)itemMgr.getItemData(state, new QPathEntry(nameTest, 1));//state.getChildNodeEntries(nameTest).iterator();
- List<NodeData> childs = getDataManager().getChildNodesData(state);
+ List<NodeData> childs = itemMgr.getChildNodesData(state);
List<NodeData> datas = new ArrayList<NodeData>();
if (childs != null)
@@ -722,9 +709,7 @@
for (NodeData nodeData : childs)
{
if (nameTest.equals(nodeData.getQPath().getName()))
- {
datas.add(nodeData);
- }
}
}
@@ -733,7 +718,7 @@
else
{
// get all children
- entries = getDataManager().getChildNodesData(state).iterator();
+ entries = itemMgr.getChildNodesData(state).iterator();
}
while (entries.hasNext())
{
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildNodesQueryHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildNodesQueryHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ChildNodesQueryHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,110 +16,94 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-
import java.io.IOException;
+import javax.jcr.Node;
import javax.jcr.RepositoryException;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
/**
* <code>ChildNodesQueryHits</code> implements query hits that returns the child
* nodes of another given query hits.
*/
-public class ChildNodesQueryHits extends AbstractQueryHits
-{
+public class ChildNodesQueryHits extends AbstractQueryHits {
- /**
- * The parent query hits.
- */
- private final QueryHits parents;
+ /**
+ * The parent query hits.
+ */
+ private final QueryHits parents;
- /**
- * This session that executes the query.
- */
- private final QueryContextHolder contextHolder;
+ /**
+ * This session that executes the query.
+ */
+ private final SessionImpl session;
- /**
- * The current child hits.
- */
- private QueryHits childHits;
+ /**
+ * The current child hits.
+ */
+ private QueryHits childHits;
- /**
- * Creates a new <code>ChildNodesQueryHits</code> that returns the child
- * nodes of all query hits from the given <code>parents</code>.
- *
- * @param parents the parent query hits.
- * @param session the session that executes the query.
- * @throws IOException if an error occurs while reading from
- * <code>parents</code>
- */
- public ChildNodesQueryHits(QueryHits parents, QueryContextHolder contextHolder) throws IOException
- {
- this.parents = parents;
- this.contextHolder = contextHolder;
- fetchNextChildHits();
- }
+ /**
+ * Creates a new <code>ChildNodesQueryHits</code> that returns the child
+ * nodes of all query hits from the given <code>parents</code>.
+ *
+ * @param parents the parent query hits.
+ * @param session the session that executes the query.
+ * @throws IOException if an error occurs while reading from
+ * <code>parents</code>
+ */
+ public ChildNodesQueryHits(QueryHits parents, SessionImpl session)
+ throws IOException {
+ this.parents = parents;
+ this.session = session;
+ fetchNextChildHits();
+ }
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException
- {
- if (childHits != null)
- {
- childHits.close();
- }
- parents.close();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ if (childHits != null) {
+ childHits.close();
+ }
+ parents.close();
+ }
- /**
- * {@inheritDoc}
- */
- public ScoreNode nextScoreNode() throws IOException
- {
- while (childHits != null)
- {
- ScoreNode sn = childHits.nextScoreNode();
- if (sn != null)
- {
- return sn;
- }
- else
- {
- fetchNextChildHits();
- }
- }
- // if we get here there are no more score nodes
- return null;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException {
+ while (childHits != null) {
+ ScoreNode sn = childHits.nextScoreNode();
+ if (sn != null) {
+ return sn;
+ } else {
+ fetchNextChildHits();
+ }
+ }
+ // if we get here there are no more score nodes
+ return null;
+ }
- /**
- * Fetches the next {@link #childHits}
- * @throws IOException
- */
- private void fetchNextChildHits() throws IOException
- {
- if (childHits != null)
- {
- childHits.close();
- }
- ScoreNode nextParent = parents.nextScoreNode();
- if (nextParent != null)
- {
- try
- {
- //Node parent = (Node)session.getTransientNodesManager().getItemByIdentifier(nextParent.getNodeId(),true);
- NodeData parent = (NodeData)contextHolder.getDataManger().getItemData(nextParent.getNodeId());
- childHits = new NodeTraversingQueryHits(contextHolder, parent, false, 1);
- }
- catch (RepositoryException e)
- {
- throw Util.createIOException(e);
- }
- }
- else
- {
- childHits = null;
- }
- }
+ /**
+ * Fetches the next {@link #childHits}
+ * @throws IOException
+ */
+ private void fetchNextChildHits() throws IOException {
+ if (childHits != null) {
+ childHits.close();
+ }
+ ScoreNode nextParent = parents.nextScoreNode();
+ if (nextParent != null) {
+ try {
+ Node parent = (Node)session.getTransientNodesManager().getItemByIdentifier(nextParent.getNodeId(),true);
+ childHits = new NodeTraversingQueryHits(parent, false, 1);
+ } catch (RepositoryException e) {
+ throw Util.createIOException(e);
+ }
+ } else {
+ childHits = null;
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CloseableHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CloseableHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CloseableHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -17,14 +17,13 @@
package org.exoplatform.services.jcr.impl.core.query.lucene;
import java.io.IOException;
-import java.io.Serializable;
/**
* Defines an interface for query hits that need to be closed when done reading
* from it. A client will call {@link #close()} to release resources after a
* query has been executed and the results have been read.
*/
-public interface CloseableHits{
+public interface CloseableHits {
/**
* Releases resources held by this hits instance.
Deleted: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultMultiColumnQueryHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultMultiColumnQueryHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultMultiColumnQueryHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2010 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.lucene;
-
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: DefaultMultiColumnQueryHits.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class DefaultMultiColumnQueryHits implements MultiColumnQueryHits
-{
-
- private Iterator<ScoreNode[]> scoreNodes;
-
- private int size;
-
- private InternalQName[] selectors;
-
- public DefaultMultiColumnQueryHits(List<ScoreNode[]> nodes, InternalQName[] selectors)
- {
- this.scoreNodes = nodes.iterator();
- this.size = nodes.size();
- this.selectors = selectors;
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.MultiColumnQueryHits#getSelectorNames()
- */
- public InternalQName[] getSelectorNames()
- {
- return selectors;
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.MultiColumnQueryHits#nextScoreNodes()
- */
- public ScoreNode[] nextScoreNodes() throws IOException
- {
- if (scoreNodes.hasNext())
- {
- return scoreNodes.next();
- }
- else
- {
- return null;
- }
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.CloseableHits#close()
- */
- public void close() throws IOException
- {
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.CloseableHits#getSize()
- */
- public int getSize()
- {
- return size;
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.CloseableHits#skip(int)
- */
- public void skip(int n) throws IOException
- {
- while (n-- > 0)
- {
- if (nextScoreNodes() == null)
- {
- return;
- }
- }
- }
-
-}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DerefQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DerefQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DerefQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -39,366 +39,311 @@
* Implements a lucene <code>Query</code> which returns the nodes selected by
* a reference property of the context node.
*/
-class DerefQuery extends AbstractLuceneQuery
-{
+class DerefQuery extends Query {
- /**
- * The context query
- */
- private Query contextQuery;
+ /**
+ * The context query
+ */
+ private final Query contextQuery;
- /**
- * The name of the reference property.
- */
- private String refProperty;
+ /**
+ * The name of the reference property.
+ */
+ private final String refProperty;
- /**
- * The nameTest to apply on target node, or <code>null</code> if all
- * target nodes should be selected.
- */
- private InternalQName nameTest;
+ /**
+ * The nameTest to apply on target node, or <code>null</code> if all
+ * target nodes should be selected.
+ */
+ private final InternalQName nameTest;
- /**
- * The index format version.
- */
- private IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private final IndexFormatVersion version;
- /**
- * The scorer of the context query
- */
- private transient Scorer contextScorer;
+ /**
+ * The internal namespace mappings.
+ */
+ private final NamespaceMappings nsMappings;
- /**
- * The scorer of the name test query
- */
- private transient Scorer nameTestScorer;
+ /**
+ * The scorer of the context query
+ */
+ private Scorer contextScorer;
- /**
- * for serialization
- */
- public DerefQuery()
- {
- super();
- }
+ /**
+ * The scorer of the name test query
+ */
+ private Scorer nameTestScorer;
- /**
- * Creates a new <code>DerefQuery</code> based on a <code>context</code>
- * query.
- *
- * @param context the context for this query.
- * @param refProperty the name of the reference property.
- * @param nameTest a name test or <code>null</code> if any node is
- * selected.
- * @param version the index format version.
- * @param nsMappings the namespace mappings.
- */
- DerefQuery(Query context, String refProperty, InternalQName nameTest, IndexFormatVersion version,
- NamespaceMappings nsMappings)
- {
- super(null, nsMappings);
- this.contextQuery = context;
- this.refProperty = refProperty;
- this.nameTest = nameTest;
- this.version = version;
- }
+ /**
+ * Creates a new <code>DerefQuery</code> based on a <code>context</code>
+ * query.
+ *
+ * @param context the context for this query.
+ * @param refProperty the name of the reference property.
+ * @param nameTest a name test or <code>null</code> if any node is
+ * selected.
+ * @param version the index format version.
+ * @param nsMappings the namespace mappings.
+ */
+ DerefQuery(Query context, String refProperty, InternalQName nameTest,
+ IndexFormatVersion version, NamespaceMappings nsMappings) {
+ this.contextQuery = context;
+ this.refProperty = refProperty;
+ this.nameTest = nameTest;
+ this.version = version;
+ this.nsMappings = nsMappings;
+ }
- /**
- * Creates a <code>Weight</code> instance for this query.
- *
- * @param searcher the <code>Searcher</code> instance to use.
- * @return a <code>DerefWeight</code>.
- */
- protected Weight createWeight(Searcher searcher)
- {
- return new DerefWeight(searcher);
- }
+ /**
+ * Creates a <code>Weight</code> instance for this query.
+ *
+ * @param searcher the <code>Searcher</code> instance to use.
+ * @return a <code>DerefWeight</code>.
+ */
+ protected Weight createWeight(Searcher searcher) {
+ return new DerefWeight(searcher);
+ }
- /**
- * Always returns 'DerefQuery'.
- *
- * @param field the name of a field.
- * @return 'DerefQuery'.
- */
- public String toString(String field)
- {
- return "DerefQuery";
- }
+ /**
+ * Always returns 'DerefQuery'.
+ *
+ * @param field the name of a field.
+ * @return 'DerefQuery'.
+ */
+ public String toString(String field) {
+ return "DerefQuery";
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- // no terms to extract
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ // no terms to extract
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (reader instanceof JcrIndexReader && contextQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)contextQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- Query cQuery = contextQuery.rewrite(reader);
- if (cQuery == contextQuery)
- {
- return this;
- }
- else
- {
- AbstractLuceneQuery newQuery = new DerefQuery(cQuery, refProperty, nameTest, version, getNamespaceMappings());
- if (reader instanceof JcrIndexReader)
- {
- newQuery.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- return newQuery;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ Query cQuery = contextQuery.rewrite(reader);
+ if (cQuery == contextQuery) {
+ return this;
+ } else {
+ return new DerefQuery(cQuery, refProperty, nameTest, version, nsMappings);
+ }
+ }
- //-------------------< DerefWeight >------------------------------------
+ //-------------------< DerefWeight >------------------------------------
- /**
- * The <code>Weight</code> implementation for this <code>DerefQuery</code>.
- */
- private class DerefWeight implements Weight
- {
+ /**
+ * The <code>Weight</code> implementation for this <code>DerefQuery</code>.
+ */
+ private class DerefWeight implements Weight {
- /**
- * The searcher in use
- */
- private final Searcher searcher;
+ /**
+ * The searcher in use
+ */
+ private final Searcher searcher;
- /**
- * Creates a new <code>DerefWeight</code> instance using
- * <code>searcher</code>.
- *
- * @param searcher a <code>Searcher</code> instance.
- */
- private DerefWeight(Searcher searcher)
- {
- this.searcher = searcher;
- }
+ /**
+ * Creates a new <code>DerefWeight</code> instance using
+ * <code>searcher</code>.
+ *
+ * @param searcher a <code>Searcher</code> instance.
+ */
+ private DerefWeight(Searcher searcher) {
+ this.searcher = searcher;
+ }
- /**
- * Returns this <code>DerefQuery</code>.
- *
- * @return this <code>DerefQuery</code>.
- */
- public Query getQuery()
- {
- return DerefQuery.this;
- }
+ /**
+ * Returns this <code>DerefQuery</code>.
+ *
+ * @return this <code>DerefQuery</code>.
+ */
+ public Query getQuery() {
+ return DerefQuery.this;
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue()
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue() {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm)
- {
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm) {
+ }
- /**
- * Creates a scorer for this <code>DerefQuery</code>.
- *
- * @param reader a reader for accessing the index.
- * @return a <code>DerefScorer</code>.
- * @throws IOException if an error occurs while reading from the index.
- */
- public Scorer scorer(IndexReader reader) throws IOException
- {
- contextScorer = contextQuery.weight(searcher).scorer(reader);
- if (nameTest != null)
- {
- nameTestScorer = new NameQuery(nameTest, version, getNamespaceMappings()).weight(searcher).scorer(reader);
- }
- return new DerefScorer(searcher.getSimilarity(), reader);
- }
+ /**
+ * Creates a scorer for this <code>DerefQuery</code>.
+ *
+ * @param reader a reader for accessing the index.
+ * @return a <code>DerefScorer</code>.
+ * @throws IOException if an error occurs while reading from the index.
+ */
+ public Scorer scorer(IndexReader reader) throws IOException {
+ contextScorer = contextQuery.weight(searcher).scorer(reader);
+ if (nameTest != null) {
+ nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader);
+ }
+ return new DerefScorer(searcher.getSimilarity(), reader);
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- return new Explanation();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException {
+ return new Explanation();
+ }
+ }
- //----------------------< DerefScorer >---------------------------------
+ //----------------------< DerefScorer >---------------------------------
- /**
- * Implements a <code>Scorer</code> for this <code>DerefQuery</code>.
- */
- private class DerefScorer extends Scorer
- {
+ /**
+ * Implements a <code>Scorer</code> for this <code>DerefQuery</code>.
+ */
+ private class DerefScorer extends Scorer {
- /**
- * An <code>IndexReader</code> to access the index.
- */
- private final IndexReader reader;
+ /**
+ * An <code>IndexReader</code> to access the index.
+ */
+ private final IndexReader reader;
- /**
- * BitSet storing the id's of selected documents
- */
- private final BitSet hits;
+ /**
+ * BitSet storing the id's of selected documents
+ */
+ private final BitSet hits;
- /**
- * List of UUIDs of selected nodes
- */
- private List uuids = null;
+ /**
+ * List of UUIDs of selected nodes
+ */
+ private List uuids = null;
- /**
- * The next document id to return
- */
- private int nextDoc = -1;
+ /**
+ * The next document id to return
+ */
+ private int nextDoc = -1;
- /**
- * Creates a new <code>DerefScorer</code>.
- *
- * @param similarity the <code>Similarity</code> instance to use.
- * @param reader for index access.
- */
- protected DerefScorer(Similarity similarity, IndexReader reader)
- {
- super(similarity);
- this.reader = reader;
- this.hits = new BitSet(reader.maxDoc());
- }
+ /**
+ * Creates a new <code>DerefScorer</code>.
+ *
+ * @param similarity the <code>Similarity</code> instance to use.
+ * @param reader for index access.
+ */
+ protected DerefScorer(Similarity similarity, IndexReader reader) {
+ super(similarity);
+ this.reader = reader;
+ this.hits = new BitSet(reader.maxDoc());
+ }
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException
- {
- calculateChildren();
- nextDoc = hits.nextSetBit(nextDoc + 1);
- return nextDoc > -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException {
+ calculateChildren();
+ nextDoc = hits.nextSetBit(nextDoc + 1);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public int doc()
- {
- return nextDoc;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc() {
+ return nextDoc;
+ }
- /**
- * {@inheritDoc}
- */
- public float score() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() throws IOException {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException
- {
- calculateChildren();
- nextDoc = hits.nextSetBit(target);
- return nextDoc > -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException {
+ calculateChildren();
+ nextDoc = hits.nextSetBit(target);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException this implementation always
- * throws an <code>UnsupportedOperationException</code>.
- */
- public Explanation explain(int doc) throws IOException
- {
- throw new UnsupportedOperationException();
- }
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException this implementation always
+ * throws an <code>UnsupportedOperationException</code>.
+ */
+ public Explanation explain(int doc) throws IOException {
+ throw new UnsupportedOperationException();
+ }
- private void calculateChildren() throws IOException
- {
- if (uuids == null)
- {
- uuids = new ArrayList();
- contextScorer.score(new HitCollector()
- {
- public void collect(int doc, float score)
- {
- hits.set(doc);
- }
- });
+ private void calculateChildren() throws IOException {
+ if (uuids == null) {
+ uuids = new ArrayList();
+ contextScorer.score(new HitCollector() {
+ public void collect(int doc, float score) {
+ hits.set(doc);
+ }
+ });
- // collect nameTest hits
- final BitSet nameTestHits = new BitSet();
- if (nameTestScorer != null)
- {
- nameTestScorer.score(new HitCollector()
- {
- public void collect(int doc, float score)
- {
- nameTestHits.set(doc);
- }
- });
- }
+ // collect nameTest hits
+ final BitSet nameTestHits = new BitSet();
+ if (nameTestScorer != null) {
+ nameTestScorer.score(new HitCollector() {
+ public void collect(int doc, float score) {
+ nameTestHits.set(doc);
+ }
+ });
+ }
- // retrieve uuids of target nodes
- String prefix = FieldNames.createNamedValue(refProperty, "");
- for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1))
- {
- String[] values = reader.document(i).getValues(FieldNames.PROPERTIES);
- if (values == null)
- {
- // no reference properties at all on this node
- continue;
- }
- for (int v = 0; v < values.length; v++)
- {
- if (values[v].startsWith(prefix))
- {
- uuids.add(values[v].substring(prefix.length()));
- }
- }
- }
+ // retrieve uuids of target nodes
+ String prefix = FieldNames.createNamedValue(refProperty, "");
+ for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
+ String[] values = reader.document(i).getValues(FieldNames.PROPERTIES);
+ if (values == null) {
+ // no reference properties at all on this node
+ continue;
+ }
+ for (int v = 0; v < values.length; v++) {
+ if (values[v].startsWith(prefix)) {
+ uuids.add(values[v].substring(prefix.length()));
+ }
+ }
+ }
- // collect the doc ids of all target nodes. we reuse the existing
- // bitset.
- hits.clear();
- for (Iterator it = uuids.iterator(); it.hasNext();)
- {
- TermDocs node = reader.termDocs(new Term(FieldNames.UUID, (String)it.next()));
- try
- {
- while (node.next())
- {
- hits.set(node.doc());
- }
- }
- finally
- {
- node.close();
- }
+ // collect the doc ids of all target nodes. we reuse the existing
+ // bitset.
+ hits.clear();
+ for (Iterator it = uuids.iterator(); it.hasNext();) {
+ TermDocs node = reader.termDocs(new Term(FieldNames.UUID, (String) it.next()));
+ try {
+ while (node.next()) {
+ hits.set(node.doc());
+ }
+ } finally {
+ node.close();
+ }
+ }
+ // filter out the target nodes that do not match the name test
+ // if there is any name test at all.
+ if (nameTestScorer != null) {
+ hits.and(nameTestHits);
+ }
}
- // filter out the target nodes that do not match the name test
- // if there is any name test at all.
- if (nameTestScorer != null)
- {
- hits.and(nameTestHits);
- }
- }
- }
- }
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DescendantSelfAxisQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DescendantSelfAxisQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DescendantSelfAxisQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -25,8 +25,8 @@
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.Weight;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.SessionDataManager;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,6 +37,7 @@
import java.util.Set;
import java.util.TreeMap;
+import javax.jcr.Node;
import javax.jcr.RepositoryException;
/**
@@ -55,38 +56,30 @@
/**
* The context query
*/
- private Query contextQuery;
+ private final Query contextQuery;
/**
* The scorer of the context query
*/
- private transient Scorer contextScorer;
+ private Scorer contextScorer;
/**
* The sub query to filter
*/
- private Query subQuery;
+ private final Query subQuery;
/**
* The minimal levels required between context and sub nodes for a sub node
* to match.
*/
- private int minLevels;
+ private final int minLevels;
/**
* The scorer of the sub query to filter
*/
- private transient Scorer subScorer;
+ private Scorer subScorer;
/**
- * for serialization
- */
- public DescendantSelfAxisQuery()
- {
- super();
- }
-
- /**
* Creates a new <code>DescendantSelfAxisQuery</code> based on a
* <code>context</code> and matches all descendants of the context nodes.
* Whether the context nodes match as well is controlled by
@@ -223,17 +216,6 @@
*/
public Query rewrite(IndexReader reader) throws IOException
{
- if (reader instanceof JcrIndexReader)
- {
- if (contextQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)contextQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- if (subQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)subQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- }
Query cQuery = contextQuery.rewrite(reader);
Query sQuery = subQuery.rewrite(reader);
if (contextQuery instanceof DescendantSelfAxisQuery)
@@ -260,7 +242,7 @@
/**
* {@inheritDoc}
*/
- public QueryHits execute(final JcrIndexSearcher searcher, final QueryContextHolder contextHolder, final Sort sort)
+ public QueryHits execute(final JcrIndexSearcher searcher, final SessionImpl session, final Sort sort)
throws IOException
{
// Query tt = ((BooleanClause)((BooleanQuery)subQuery).clauses().get(0)).getQuery();
@@ -280,7 +262,7 @@
// intermediate ChildNodesQueryHits are required.
for (int i = 2; i <= getMinLevels(); i++)
{
- result = new ChildNodesQueryHits(result, contextHolder);
+ result = new ChildNodesQueryHits(result, session);
}
ScoreNode sn;
@@ -289,10 +271,8 @@
while ((sn = result.nextScoreNode()) != null)
{
//Node node = session.getNodeById(sn.getNodeId());
- NodeData node = (NodeData)contextHolder.getDataManger().getItemData(sn.getNodeId());
- //Node node = (Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
- startingPoints.put(contextHolder.getLocationFactory().createJCRPath(node.getQPath()).getAsString(
- false), sn);
+ Node node = (Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
+ startingPoints.put(node.getPath(), sn);
}
}
catch (RepositoryException e)
@@ -328,7 +308,7 @@
private NodeTraversingQueryHits currentTraversal;
- private ItemDataConsumer itemMgr = contextHolder.getDataManger();//session.getTransientNodesManager();
+ private SessionDataManager itemMgr = session.getTransientNodesManager();
{
fetchNextTraversal();
@@ -372,9 +352,8 @@
try
{
//Node node = session.getNodeById(sn.getNodeId());
- NodeData data = (NodeData)contextHolder.getDataManger().getItemData(sn.getNodeId());
- //Node node = (Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
- currentTraversal = new NodeTraversingQueryHits(contextHolder, data, getMinLevels() == 0);
+ Node node = (Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
+ currentTraversal = new NodeTraversingQueryHits(node, getMinLevels() == 0);
}
catch (RepositoryException e)
{
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FilterQueryHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FilterQueryHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FilterQueryHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -22,62 +22,48 @@
* <code>FilterQueryHits</code> implements a {@link QueryHits} filter that
* forwards each call to the underlying query hits.
*/
-public class FilterQueryHits implements QueryHits
-{
+public class FilterQueryHits implements QueryHits {
- /**
- * The underlying query hits.
- */
- private QueryHits hits;
+ /**
+ * The underlying query hits.
+ */
+ private final QueryHits hits;
- /**
- * For serialization
- */
- public FilterQueryHits()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Creates a new <code>FilterQueryHits</code>, which forwards each call to
+ * <code>hits</code>.
+ *
+ * @param hits the underlying query hits.
+ */
+ public FilterQueryHits(QueryHits hits) {
+ this.hits = hits;
+ }
- /**
- * Creates a new <code>FilterQueryHits</code>, which forwards each call to
- * <code>hits</code>.
- *
- * @param hits the underlying query hits.
- */
- public FilterQueryHits(QueryHits hits)
- {
- this.hits = hits;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ hits.close();
+ }
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException
- {
- hits.close();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int getSize() {
+ return hits.getSize();
+ }
- /**
- * {@inheritDoc}
- */
- public int getSize()
- {
- return hits.getSize();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException {
+ return hits.nextScoreNode();
+ }
- /**
- * {@inheritDoc}
- */
- public ScoreNode nextScoreNode() throws IOException
- {
- return hits.nextScoreNode();
- }
-
- /**
- * {@inheritDoc}
- */
- public void skip(int n) throws IOException
- {
- hits.skip(n);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void skip(int n) throws IOException {
+ hits.skip(n);
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexFormatVersion.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexFormatVersion.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexFormatVersion.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,7 +16,6 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import java.io.Serializable;
import java.util.Collection;
import org.apache.lucene.index.IndexReader;
@@ -40,94 +39,77 @@
* version! If you want to take advantage of a certain 'feature' in an index
* format version you need to re-index the repository.
*/
-public class IndexFormatVersion implements Serializable
-{
+public class IndexFormatVersion {
- /**
- * V1 is the index format for Jackrabbit releases 1.0 to 1.3.x.
- */
- public static final IndexFormatVersion V1 = new IndexFormatVersion(1);
+ /**
+ * V1 is the index format for Jackrabbit releases 1.0 to 1.3.x.
+ */
+ public static final IndexFormatVersion V1 = new IndexFormatVersion(1);
- /**
- * V2 is the index format for Jackrabbit releases 1.4.x
- */
- public static final IndexFormatVersion V2 = new IndexFormatVersion(2);
+ /**
+ * V2 is the index format for Jackrabbit releases 1.4.x
+ */
+ public static final IndexFormatVersion V2 = new IndexFormatVersion(2);
- /**
- * V3 is the index format for Jackrabbit releases >= 1.5
- */
- public static final IndexFormatVersion V3 = new IndexFormatVersion(3);
+ /**
+ * V3 is the index format for Jackrabbit releases >= 1.5
+ */
+ public static final IndexFormatVersion V3 = new IndexFormatVersion(3);
- /**
- * The used version of the index format
- */
- private int version;
+ /**
+ * The used version of the index format
+ */
+ private final int version;
- /**
- * for serialization
+ /**
+ * Creates a index format version.
+ *
+ * @param version The version of the index.
*/
- public IndexFormatVersion()
- {
- }
+ private IndexFormatVersion(int version) {
+ this.version = version;
+ }
- /**
- * Creates a index format version.
- *
- * @param version The version of the index.
- */
- private IndexFormatVersion(int version)
- {
- this.version = version;
- }
+ /**
+ * Returns the index format version
+ * @return the index format version.
+ */
+ public int getVersion() {
+ return version;
+ }
- /**
- * Returns the index format version
- * @return the index format version.
- */
- public int getVersion()
- {
- return version;
- }
+ /**
+ * Returns <code>true</code> if this version is at least as high as the
+ * given <code>version</code>.
+ *
+ * @param version the other version to compare.
+ * @return <code>true</code> if this version is at least as high as the
+ * provided; <code>false</code> otherwise.
+ */
+ public boolean isAtLeast(IndexFormatVersion version) {
+ return this.version >= version.getVersion();
+ }
- /**
- * Returns <code>true</code> if this version is at least as high as the
- * given <code>version</code>.
- *
- * @param version the other version to compare.
- * @return <code>true</code> if this version is at least as high as the
- * provided; <code>false</code> otherwise.
- */
- public boolean isAtLeast(IndexFormatVersion version)
- {
- return this.version >= version.getVersion();
- }
+ /**
+ * @return a string representation of this index format version.
+ */
+ public String toString() {
+ return String.valueOf(getVersion());
+ }
- /**
- * @return a string representation of this index format version.
- */
- public String toString()
- {
- return String.valueOf(getVersion());
- }
-
- /**
- * @return the index format version of the index used by the given
- * index reader.
- */
- public static IndexFormatVersion getVersion(IndexReader indexReader)
- {
- Collection fields = indexReader.getFieldNames(IndexReader.FieldOption.ALL);
- if (fields.contains(FieldNames.LOCAL_NAME) || indexReader.numDocs() == 0)
- {
- return IndexFormatVersion.V3;
- }
- else if (fields.contains(FieldNames.PROPERTIES_SET))
- {
- return IndexFormatVersion.V2;
- }
- else
- {
- return IndexFormatVersion.V1;
- }
- }
+ /**
+ * @return the index format version of the index used by the given
+ * index reader.
+ */
+ public static IndexFormatVersion getVersion(IndexReader indexReader) {
+ Collection fields = indexReader.getFieldNames(
+ IndexReader.FieldOption.ALL);
+ if (fields.contains(FieldNames.LOCAL_NAME) || indexReader.numDocs() == 0) {
+ return IndexFormatVersion.V3;
+ } else if (fields.contains(FieldNames.PROPERTIES_SET)) {
+ return IndexFormatVersion.V2;
+ } else {
+ return IndexFormatVersion.V1;
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexReader.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexReader.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexReader.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -32,22 +32,7 @@
extends FilterIndexReader
implements HierarchyResolver, MultiIndexReader {
- private QueryContextHolder contextHolder;
-
- public QueryContextHolder getContextHolder()
- {
- return contextHolder;
- }
-
- public void setContextHolder(QueryContextHolder contextHolder)
- {
- if (contextHolder!=null)
- {
- this.contextHolder = contextHolder;
- }
- }
-
- /**
+ /**
* The hierarchy resolver.
*/
private final HierarchyResolver resolver;
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrIndexSearcher.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -22,6 +22,7 @@
import org.apache.lucene.search.Sort;
import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
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;
@@ -38,7 +39,7 @@
/**
* The session that executes the query.
*/
- private final QueryContextHolder contextHolder;
+ private final SessionImpl session;
/**
* The underlying index reader.
@@ -57,15 +58,11 @@
* @param r the index reader.
* @param ism the shared item state manager.
*/
- public JcrIndexSearcher(QueryContextHolder contextHolder, IndexReader r, ItemDataConsumer ism)
+ public JcrIndexSearcher(SessionImpl s, IndexReader r, ItemDataConsumer ism)
{
super(r);
- this.contextHolder = contextHolder;
+ this.session = s;
this.reader = r;
- if (this.reader instanceof JcrIndexReader)
- {
- ((JcrIndexReader)this.reader).setContextHolder(contextHolder);
- }
this.ism = ism;
}
@@ -101,16 +98,10 @@
public QueryHits run() throws Exception
{
Query localQuery = query.rewrite(reader);
-
- if (reader instanceof JcrIndexReader && localQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)localQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
-
QueryHits hits = null;
if (localQuery instanceof JcrQuery)
{
- hits = ((JcrQuery)localQuery).execute(JcrIndexSearcher.this, contextHolder, sort);
+ hits = ((JcrQuery)localQuery).execute(JcrIndexSearcher.this, session, sort);
}
if (hits == null)
{
@@ -143,6 +134,14 @@
}
/**
+ * @return session that executes the query.
+ */
+ public SessionImpl getSession()
+ {
+ return session;
+ }
+
+ /**
* @return the item state manager of the workspace.
*/
public ItemDataConsumer getItemStateManager()
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -48,7 +48,7 @@
* @throws IOException if an error occurs while executing the query.
*/
public QueryHits execute(JcrIndexSearcher searcher,
- QueryContextHolder contextHolder,
+ SessionImpl session,
Sort sort)
throws IOException;
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrTermQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrTermQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/JcrTermQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -31,94 +31,76 @@
* <code>JackrabbitTermQuery</code> implements a {@link TermQuery} where score
* values are retrieved on a per index segment basis using {@link MultiScorer}.
*/
-public class JcrTermQuery extends TermQuery
-{
+public class JcrTermQuery extends TermQuery {
- private static final long serialVersionUID = 4244799812287335957L;
+ private static final long serialVersionUID = 4244799812287335957L;
- /**
- * for serialization
- */
- public JcrTermQuery()
- {
- super(null);
- }
+ public JcrTermQuery(Term t) {
+ super(t);
+ }
- public JcrTermQuery(Term t)
- {
- super(t);
- }
+ protected Weight createWeight(Searcher searcher) throws IOException {
+ return new JackrabbitTermWeight(searcher, super.createWeight(searcher));
+ }
- protected Weight createWeight(Searcher searcher) throws IOException
- {
- return new JackrabbitTermWeight(searcher, super.createWeight(searcher));
- }
+ /**
+ * The weight implementation.
+ */
+ protected class JackrabbitTermWeight extends AbstractWeight {
- /**
- * The weight implementation.
- */
- protected class JackrabbitTermWeight extends AbstractWeight
- {
+ private static final long serialVersionUID = -2070964510010945854L;
- private static final long serialVersionUID = -2070964510010945854L;
+ /**
+ * The default lucene TermQuery weight.
+ */
+ private final Weight weight;
- /**
- * The default lucene TermQuery weight.
- */
- private final Weight weight;
+ public JackrabbitTermWeight(Searcher searcher, Weight weight) {
+ super(searcher);
+ this.weight = weight;
+ }
- public JackrabbitTermWeight(Searcher searcher, Weight weight)
- {
- super(searcher);
- this.weight = weight;
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Scorer createScorer(IndexReader reader) throws IOException {
+ return weight.scorer(reader);
+ }
- /**
- * {@inheritDoc}
- */
- protected Scorer createScorer(IndexReader reader) throws IOException
- {
- return weight.scorer(reader);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query getQuery() {
+ return JcrTermQuery.this;
+ }
- /**
- * {@inheritDoc}
- */
- public Query getQuery()
- {
- return JcrTermQuery.this;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue() {
+ return weight.getValue();
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue()
- {
- return weight.getValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return weight.sumOfSquaredWeights();
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return weight.sumOfSquaredWeights();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm) {
+ weight.normalize(norm);
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm)
- {
- weight.normalize(norm);
- }
-
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- return weight.explain(reader, doc);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws
+ IOException {
+ return weight.explain(reader, doc);
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -26,66 +26,51 @@
/**
* <code>LocalNameQuery</code> implements a query for the local name of a node.
*/
-public class LocalNameQuery extends Query
-{
+public class LocalNameQuery extends Query {
- /**
- * The local name of a node.
- */
- private String localName;
+ /**
+ * The local name of a node.
+ */
+ private final String localName;
- /**
- * The index format version.
- */
- private IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private final IndexFormatVersion version;
- /**
- * for serialization
- */
- public LocalNameQuery()
- {
- }
+ /**
+ * Creates a new <code>LocalNameQuery</code> for the given
+ * <code>localName</code>.
+ *
+ * @param localName the local name of a node.
+ * @param version the version of the index.
+ */
+ public LocalNameQuery(String localName, IndexFormatVersion version) {
+ this.localName = localName;
+ this.version = version;
+ }
- /**
- * Creates a new <code>LocalNameQuery</code> for the given
- * <code>localName</code>.
- *
- * @param localName the local name of a node.
- * @param version the version of the index.
- */
- public LocalNameQuery(String localName, IndexFormatVersion version)
- {
- this.localName = localName;
- this.version = version;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+ return new JcrTermQuery(new Term(FieldNames.LOCAL_NAME, localName));
+ } else {
+ throw new IOException("LocalNameQuery requires IndexFormatVersion V3");
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (version.getVersion() >= IndexFormatVersion.V3.getVersion())
- {
- return new JcrTermQuery(new Term(FieldNames.LOCAL_NAME, localName));
- }
- else
- {
- throw new IOException("LocalNameQuery requires IndexFormatVersion V3");
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- }
-
- /**
- * {@inheritDoc}
- */
- public String toString(String field)
- {
- return "local-name() = " + localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field) {
+ return "local-name() = " + localName;
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameRangeQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameRangeQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LocalNameRangeQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -22,67 +22,51 @@
* <code>LocalNameRangeQuery</code> implements a range query on the local name
* of nodes.
*/
-public class LocalNameRangeQuery extends RangeQuery
-{
+public class LocalNameRangeQuery extends RangeQuery {
- /**
- * for serialization
- */
- public LocalNameRangeQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Creates a new <code>LocalNameRangeQuery</code>. The lower or the upper
+ * bound may be null, but not both!
+ *
+ * @param lowerName the lower bound or <code>null</code>.
+ * @param upperName the upper bound or <code>null</code>.
+ * @param inclusive if bounds are inclusive.
+ */
+ public LocalNameRangeQuery(String lowerName,
+ String upperName,
+ boolean inclusive) {
+ super(getLowerTerm(lowerName), getUpperTerm(upperName), inclusive);
+ }
- /**
- * Creates a new <code>LocalNameRangeQuery</code>. The lower or the upper
- * bound may be null, but not both!
- *
- * @param lowerName the lower bound or <code>null</code>.
- * @param upperName the upper bound or <code>null</code>.
- * @param inclusive if bounds are inclusive.
- */
- public LocalNameRangeQuery(String lowerName, String upperName, boolean inclusive)
- {
- super(getLowerTerm(lowerName), getUpperTerm(upperName), inclusive);
- }
+ /**
+ * Creates a {@link Term} for the lower bound local name.
+ *
+ * @param lowerName the lower bound local name.
+ * @return a {@link Term} for the lower bound local name.
+ */
+ private static Term getLowerTerm(String lowerName) {
+ String text;
+ if (lowerName == null) {
+ text = "";
+ } else {
+ text = lowerName;
+ }
+ return new Term(FieldNames.LOCAL_NAME, text);
+ }
- /**
- * Creates a {@link Term} for the lower bound local name.
- *
- * @param lowerName the lower bound local name.
- * @return a {@link Term} for the lower bound local name.
- */
- private static Term getLowerTerm(String lowerName)
- {
- String text;
- if (lowerName == null)
- {
- text = "";
- }
- else
- {
- text = lowerName;
- }
- return new Term(FieldNames.LOCAL_NAME, text);
- }
-
- /**
- * Creates a {@link Term} for the upper bound local name.
- *
- * @param upperName the upper bound local name.
- * @return a {@link Term} for the upper bound local name.
- */
- private static Term getUpperTerm(String upperName)
- {
- String text;
- if (upperName == null)
- {
- text = "\uFFFF";
- }
- else
- {
- text = upperName;
- }
- return new Term(FieldNames.LOCAL_NAME, text);
- }
+ /**
+ * Creates a {@link Term} for the upper bound local name.
+ *
+ * @param upperName the upper bound local name.
+ * @return a {@link Term} for the upper bound local name.
+ */
+ private static Term getUpperTerm(String upperName) {
+ String text;
+ if (upperName == null) {
+ text = "\uFFFF";
+ } else {
+ text = upperName;
+ }
+ return new Term(FieldNames.LOCAL_NAME, text);
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -23,79 +23,67 @@
import java.io.IOException;
+
/**
* Wraps a lucene query result and adds a close method that allows to release
* resources after a query has been executed and the results have been read
* completely.
*/
-public class LuceneQueryHits implements QueryHits
-{
+public class LuceneQueryHits implements QueryHits {
- /**
- * The IndexReader in use by the lucene hits.
- */
- private IndexReader reader;
+ /**
+ * The IndexReader in use by the lucene hits.
+ */
+ private final IndexReader reader;
- /**
- * The scorer for the query.
- */
- private Scorer scorer;
+ /**
+ * The scorer for the query.
+ */
+ private final Scorer scorer;
- /**
- * For serialization
- */
- public LuceneQueryHits()
- {
- }
+ public LuceneQueryHits(IndexReader reader,
+ IndexSearcher searcher,
+ Query query)
+ throws IOException {
+ this.reader = reader;
+ this.scorer = query.weight(searcher).scorer(reader);
+ }
- public LuceneQueryHits(IndexReader reader, IndexSearcher searcher, Query query) throws IOException
- {
- this.reader = reader;
- this.scorer = query.weight(searcher).scorer(reader);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException {
+ if (!scorer.next()) {
+ return null;
+ }
+ int doc = scorer.doc();
+ String uuid = reader.document(doc).get(FieldNames.UUID);
+ return new ScoreNode(uuid, scorer.score(), doc);
+ }
- /**
- * {@inheritDoc}
- */
- public ScoreNode nextScoreNode() throws IOException
- {
- if (!scorer.next())
- {
- return null;
- }
- int doc = scorer.doc();
- String uuid = reader.document(doc).get(FieldNames.UUID);
- return new ScoreNode(uuid, scorer.score(), doc);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException {
+ // make sure scorer frees resources
+ scorer.skipTo(Integer.MAX_VALUE);
+ }
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException
- {
- // make sure scorer frees resources
- scorer.skipTo(Integer.MAX_VALUE);
- }
+ /**
+ * @return always -1.
+ */
+ public int getSize() {
+ return -1;
+ }
- /**
- * @return always -1.
- */
- public int getSize()
- {
- return -1;
- }
-
- /**
- * {@inheritDoc}
- */
- public void skip(int n) throws IOException
- {
- while (n-- > 0)
- {
- if (nextScoreNode() == null)
- {
- return;
- }
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void skip(int n) throws IOException {
+ while (n-- > 0) {
+ if (nextScoreNode() == null) {
+ return;
+ }
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllDocsQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllDocsQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllDocsQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,42 +16,36 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import org.apache.lucene.search.Sort;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.Constants;
-
import java.io.IOException;
import javax.jcr.RepositoryException;
+import org.apache.lucene.search.Sort;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
+
/**
* <code>MatchAllDocsQuery</code> extends the lucene <code>MatchAllDocsQuery</code>
* and in addition implements {@link JcrQuery}.
*/
-public class MatchAllDocsQuery extends org.apache.lucene.search.MatchAllDocsQuery implements JcrQuery
-{
+public class MatchAllDocsQuery
+ extends org.apache.lucene.search.MatchAllDocsQuery
+ implements JcrQuery {
- /**
- * {@inheritDoc}
- */
- public QueryHits execute(JcrIndexSearcher searcher, QueryContextHolder contextHolder, Sort sort) throws IOException
- {
- if (sort.getSort().length == 0)
- {
- try
- {
-
- return new NodeTraversingQueryHits(contextHolder, (NodeData)contextHolder.getDataManger().getItemData(
- Constants.ROOT_UUID), true);
- }
- catch (RepositoryException e)
- {
- throw Util.createIOException(e);
- }
- }
- else
- {
- return null;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public QueryHits execute(JcrIndexSearcher searcher,
+ SessionImpl session,
+ Sort sort) throws IOException {
+ if (sort.getSort().length == 0) {
+ try {
+ return new NodeTraversingQueryHits(
+ session.getRootNode(), true);
+ } catch (RepositoryException e) {
+ throw Util.createIOException(e);
+ }
+ } else {
+ return null;
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MatchAllQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -26,60 +26,47 @@
* Specialized query that returns / scores all pages in the search index.
* <p>Use this Query to perform a match '*'.
*/
-class MatchAllQuery extends Query
-{
+class MatchAllQuery extends Query {
- private String field;
+ private final String field;
- /**
- * for serialization
- */
- public MatchAllQuery()
- {
- }
+ /**
+ * Creates a new <code>MatchAllQuery</code> .
+ * <p/>
+ *
+ * @param field the field name.
+ * @throws NullPointerException if <code>field</code> is null.
+ */
+ MatchAllQuery(String field) throws NullPointerException {
+ if (field == null) {
+ throw new NullPointerException("field");
+ }
+ this.field = field.intern();
+ }
- /**
- * Creates a new <code>MatchAllQuery</code> .
- * <p/>
- *
- * @param field the field name.
- * @throws NullPointerException if <code>field</code> is null.
- */
- MatchAllQuery(String field) throws NullPointerException
- {
- if (field == null)
- {
- throw new NullPointerException("field");
- }
- this.field = field.intern();
- }
+ /**
+ * Returns the <code>Weight</code> for this Query.
+ *
+ * @param searcher the current searcher.
+ * @return the <code>Weight</code> for this Query.
+ */
+ protected Weight createWeight(Searcher searcher) {
+ return new MatchAllWeight(this, searcher, field);
+ }
- /**
- * Returns the <code>Weight</code> for this Query.
- *
- * @param searcher the current searcher.
- * @return the <code>Weight</code> for this Query.
- */
- protected Weight createWeight(Searcher searcher)
- {
- return new MatchAllWeight(this, searcher, field);
- }
+ /**
+ * Returns the String "%".
+ *
+ * @param field default field for the query.
+ * @return the String "%".
+ */
+ public String toString(String field) {
+ return "%";
+ }
- /**
- * Returns the String "%".
- *
- * @param field default field for the query.
- * @return the String "%".
- */
- public String toString(String field)
- {
- return "%";
- }
-
- /**
- * Does nothing but simply returns. There are no terms to extract.
- */
- public void extractTerms(Set terms)
- {
- }
+ /**
+ * Does nothing but simply returns. There are no terms to extract.
+ */
+ public void extractTerms(Set terms) {
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -17,7 +17,6 @@
package org.exoplatform.services.jcr.impl.core.query.lucene;
import java.io.IOException;
-import java.io.Serializable;
import org.apache.lucene.search.Sort;
@@ -25,7 +24,7 @@
* <code>MultiColumnQuery</code> defines an interface for a query that returns
* {@link MultiColumnQueryHits}.
*/
-public interface MultiColumnQuery extends Serializable {
+public interface MultiColumnQuery {
/**
* Executes this query and returns multi column query hits.
Deleted: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQueryHitsList.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQueryHitsList.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQueryHitsList.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -1,45 +0,0 @@
-package org.exoplatform.services.jcr.impl.core.query.lucene;
-
-import org.exoplatform.services.jcr.datamodel.InternalQName;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Data-class for wrapping ScoreNodes and Selectors all together
- */
-public class MultiColumnQueryHitsList implements Serializable
-{
- private static final long serialVersionUID = 222235541619772181L;
-
- private ArrayList<ScoreNode[]> nodes;
-
- private InternalQName[] selectors;
-
- public MultiColumnQueryHitsList(List<ScoreNode[]> nodes, InternalQName[] selectors)
- {
- super();
-
- this.nodes = new ArrayList<ScoreNode[]>(nodes);
- this.selectors = selectors;
- }
-
- /**
- * for serialization
- */
- public MultiColumnQueryHitsList()
- {
- super();
- }
-
- protected List<ScoreNode[]> getNodes()
- {
- return nodes;
- }
-
- protected InternalQName[] getSelectors()
- {
- return selectors;
- }
-}
\ No newline at end of file
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,6 +16,9 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import java.io.IOException;
+import java.util.Set;
+
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
@@ -24,99 +27,82 @@
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.InternalQName;
-import java.io.IOException;
-import java.util.Set;
-
/**
* <code>NameQuery</code> implements a query for the name of a node.
*/
-public class NameQuery extends AbstractLuceneQuery
-{
+public class NameQuery extends Query {
- /**
- * The node name.
- */
- private InternalQName nodeName;
+ /**
+ * The node name.
+ */
+ private final InternalQName nodeName;
- /**
- * The index format version.
- */
- private IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private final IndexFormatVersion version;
- /**
- * for serialization
- */
- public NameQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * The internal namespace mappings of the index.
+ */
+ private final NamespaceMappings nsMappings;
- /**
- * Creates a new <code>NameQuery</code>.
- *
- * @param nodeName the name of the nodes to return.
- * @param version the version of the index.
- * @param nsMappings the namespace mappings of the index.
- */
- public NameQuery(InternalQName nodeName, IndexFormatVersion version, NamespaceMappings nsMappings)
- {
- super(null, nsMappings);
- this.nodeName = nodeName;
- this.version = version;
- }
+ /**
+ * Creates a new <code>NameQuery</code>.
+ *
+ * @param nodeName the name of the nodes to return.
+ * @param version the version of the index.
+ * @param nsMappings the namespace mappings of the index.
+ */
+ public NameQuery(InternalQName nodeName,
+ IndexFormatVersion version,
+ NamespaceMappings nsMappings) {
+ this.nodeName = nodeName;
+ this.version = version;
+ this.nsMappings = nsMappings;
+ }
- /**
- * @return the name of the nodes to return.
- */
- public InternalQName getName()
- {
- return nodeName;
- }
+ /**
+ * @return the name of the nodes to return.
+ */
+ public InternalQName getName() {
+ return nodeName;
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (reader instanceof JcrIndexReader)
- {
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- if (version.getVersion() >= IndexFormatVersion.V3.getVersion())
- {
- // use LOCAL_NAME and NAMESPACE_URI field
- BooleanQuery name = new BooleanQuery();
- name.add(new JcrTermQuery(new Term(FieldNames.NAMESPACE_URI, nodeName.getNamespace())),
- BooleanClause.Occur.MUST);
- name.add(new JcrTermQuery(new Term(FieldNames.LOCAL_NAME, nodeName.getName())), BooleanClause.Occur.MUST);
- return name;
- }
- else
- {
- // use LABEL field
- try
- {
- return new JcrTermQuery(new Term(FieldNames.LABEL, getNamespaceMappings().translateName(nodeName)));
- }
- catch (IllegalNameException e)
- {
- throw Util.createIOException(e);
- }
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ if (version.getVersion() >= IndexFormatVersion.V3.getVersion()) {
+ // use LOCAL_NAME and NAMESPACE_URI field
+ BooleanQuery name = new BooleanQuery();
+ name.add(new JcrTermQuery(new Term(FieldNames.NAMESPACE_URI, nodeName.getNamespace())),
+ BooleanClause.Occur.MUST);
+ name.add(new JcrTermQuery(new Term(FieldNames.LOCAL_NAME,
+ nodeName.getName())),
+ BooleanClause.Occur.MUST);
+ return name;
+ } else {
+ // use LABEL field
+ try {
+ return new JcrTermQuery(new Term(FieldNames.LABEL,
+ nsMappings.translateName(nodeName)));
+ } catch (IllegalNameException e) {
+ throw Util.createIOException(e);
+ }
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field)
- {
- return "name() = " + nodeName.toString();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field) {
+ return "name() = " + nodeName.toString();
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameRangeQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameRangeQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NameRangeQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,6 +16,10 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
@@ -25,45 +29,38 @@
import org.exoplatform.services.jcr.datamodel.IllegalNameException;
import org.exoplatform.services.jcr.datamodel.InternalQName;
-import java.io.IOException;
-
-import javax.jcr.RepositoryException;
-
/**
* <code>NameRangeQuery</code>...
*/
-public class NameRangeQuery extends AbstractLuceneQuery
+public class NameRangeQuery extends Query
{
/**
* The lower name. May be <code>null</code> if <code>upperName</code> is not
* <code>null</code>.
*/
- private InternalQName lowerName;
+ private final InternalQName lowerName;
/**
* The upper name. May be <code>null</code> if <code>lowerName</code> is not
* <code>null</code>.
*/
- private InternalQName upperName;
+ private final InternalQName upperName;
/**
* If <code>true</code> the range interval is inclusive.
*/
- private boolean inclusive;
+ private final boolean inclusive;
/**
* The index format version.
*/
- private IndexFormatVersion version;
+ private final IndexFormatVersion version;
/**
- * for serialization
+ * The internal namespace mappings.
*/
- public NameRangeQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ private final NamespaceMappings nsMappings;
/**
* Creates a new NameRangeQuery. The lower or the upper name may be
@@ -78,7 +75,6 @@
public NameRangeQuery(InternalQName lowerName, InternalQName upperName, boolean inclusive,
IndexFormatVersion version, NamespaceMappings nsMappings)
{
- super(null, nsMappings);
if (lowerName == null && upperName == null)
{
throw new IllegalArgumentException("At least one term must be non-null");
@@ -91,6 +87,7 @@
this.upperName = upperName;
this.inclusive = inclusive;
this.version = version;
+ this.nsMappings = nsMappings;
}
/**
@@ -98,15 +95,12 @@
*/
public Query rewrite(IndexReader reader) throws IOException
{
- if (reader instanceof JcrIndexReader)
- {
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
if (version.getVersion() >= IndexFormatVersion.V3.getVersion())
{
RangeQuery localNames = new RangeQuery(getLowerLocalNameTerm(), getUpperLocalNameTerm(), inclusive);
BooleanQuery query = new BooleanQuery();
- query.add(new JcrTermQuery(new Term(FieldNames.NAMESPACE_URI, getNamespaceURI())), BooleanClause.Occur.MUST);
+ query.add(new JcrTermQuery(new Term(FieldNames.NAMESPACE_URI, getNamespaceURI())),
+ BooleanClause.Occur.MUST);
query.add(localNames, BooleanClause.Occur.MUST);
return query.rewrite(reader);
}
@@ -185,11 +179,11 @@
String text;
if (lowerName == null)
{
- text = getNamespaceMappings().getNamespacePrefixByURI(upperName.getNamespace()) + ":";
+ text = nsMappings.getNamespacePrefixByURI(upperName.getNamespace()) + ":";
}
else
{
- text = getNamespaceMappings().translateName(lowerName);
+ text = nsMappings.translateName(lowerName);
}
return new Term(FieldNames.LABEL, text);
}
@@ -214,11 +208,11 @@
String text;
if (upperName == null)
{
- text = getNamespaceMappings().getNamespacePrefixByURI(lowerName.getNamespace()) + ":\uFFFF";
+ text = nsMappings.getNamespacePrefixByURI(lowerName.getNamespace()) + ":\uFFFF";
}
else
{
- text = getNamespaceMappings().translateName(upperName);
+ text = nsMappings.translateName(upperName);
}
return new Term(FieldNames.LABEL, text);
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTraversingQueryHits.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTraversingQueryHits.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NodeTraversingQueryHits.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,189 +16,160 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
-import org.apache.commons.collections.iterators.IteratorChain;
-import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
+import org.apache.commons.collections.iterators.IteratorChain;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
/**
* <code>NodeTraversingQueryHits</code> implements query hits that traverse
* a node hierarchy.
*/
-public class NodeTraversingQueryHits extends AbstractQueryHits
-{
+public class NodeTraversingQueryHits extends AbstractQueryHits {
- /**
- * The nodes to traverse.
- */
- private final Iterator nodes;
+ /**
+ * The nodes to traverse.
+ */
+ private final Iterator nodes;
- /**
- * Creates query hits that consist of the nodes that are traversed from a
- * given <code>start</code> node.
- *
- * @param start the start node of the traversal.
- * @param includeStart whether to include the start node in the result.
- */
- public NodeTraversingQueryHits(QueryContextHolder contextHolder, NodeData startData, boolean includeStart)
- {
- this(contextHolder, startData, includeStart, Integer.MAX_VALUE);
- }
+ /**
+ * Creates query hits that consist of the nodes that are traversed from a
+ * given <code>start</code> node.
+ *
+ * @param start the start node of the traversal.
+ * @param includeStart whether to include the start node in the result.
+ */
+ public NodeTraversingQueryHits(Node start, boolean includeStart) {
+ this(start, includeStart, Integer.MAX_VALUE);
+ }
- /**
- * Creates query hits that consist of the nodes that are traversed from a
- * given <code>start</code> node.
- *
- * @param start the start node of the traversal.
- * @param includeStart whether to include the start node in the result.
- * @param maxDepth the maximum depth of nodes to traverse.
- */
- public NodeTraversingQueryHits(QueryContextHolder contextHolder, NodeData startData, boolean includeStart,
- int maxDepth)
- {
- this.nodes = new TraversingNodeIterator(contextHolder, startData, maxDepth);
- if (!includeStart)
- {
- nodes.next();
- }
- }
+ /**
+ * Creates query hits that consist of the nodes that are traversed from a
+ * given <code>start</code> node.
+ *
+ * @param start the start node of the traversal.
+ * @param includeStart whether to include the start node in the result.
+ * @param maxDepth the maximum depth of nodes to traverse.
+ */
+ public NodeTraversingQueryHits(Node start,
+ boolean includeStart,
+ int maxDepth) {
+ this.nodes = new TraversingNodeIterator(start, maxDepth);
+ if (!includeStart) {
+ nodes.next();
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public ScoreNode nextScoreNode() throws IOException
- {
- if (nodes.hasNext())
- {
- NodeData n = (NodeData)nodes.next();
- return new ScoreNode(n.getIdentifier(), 1.0f);
- }
- else
- {
- return null;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException {
+ if (nodes.hasNext()) {
+ NodeImpl n = (NodeImpl) nodes.next();
+ return new ScoreNode(n.getData().getIdentifier(), 1.0f);
+ } else {
+ return null;
+ }
+ }
- /**
- * Implements a node iterator that traverses a node tree in document
- * order.
- */
- private class TraversingNodeIterator implements Iterator
- {
+ /**
+ * Implements a node iterator that traverses a node tree in document
+ * order.
+ */
+ private class TraversingNodeIterator implements Iterator {
- /**
- * The current <code>Node</code>, which acts as the starting point for
- * the traversal.
- */
- private final NodeData currentNode;
+ /**
+ * The current <code>Node</code>, which acts as the starting point for
+ * the traversal.
+ */
+ private final Node currentNode;
- private final QueryContextHolder contextHolder;
+ /**
+ * The maximum depth of the traversal.
+ */
+ private final int maxDepth;
- /**
- * The maximum depth of the traversal.
- */
- private final int maxDepth;
+ /**
+ * The chain of iterators which includes the iterators of the children
+ * of the current node.
+ */
+ private Iterator selfAndChildren;
- /**
- * The chain of iterators which includes the iterators of the children
- * of the current node.
- */
- private Iterator selfAndChildren;
+ /**
+ * Creates a <code>TraversingNodeIterator</code>.
+ *
+ * @param start the node from where to start the traversal.
+ * @param maxDepth the maximum depth of nodes to traverse.
+ */
+ TraversingNodeIterator(Node start, int maxDepth) {
+ if (maxDepth < 0) {
+ throw new IllegalArgumentException("maxDepth must be >= 0");
+ }
+ currentNode = start;
+ this.maxDepth = maxDepth;
+ }
- /**
- * Creates a <code>TraversingNodeIterator</code>.
- *
- * @param start the node from where to start the traversal.
- * @param maxDepth the maximum depth of nodes to traverse.
- */
- TraversingNodeIterator(QueryContextHolder contextHolder, NodeData startData, int maxDepth)
- {
- if (maxDepth < 0)
- {
- throw new IllegalArgumentException("maxDepth must be >= 0");
- }
- this.currentNode = startData;
- this.maxDepth = maxDepth;
- this.contextHolder = contextHolder;
- }
+ /**
+ * @exception UnsupportedOperationException always.
+ */
+ public void remove() {
+ throw new UnsupportedOperationException("remove");
+ }
- /**
- * @exception UnsupportedOperationException always.
- */
- public void remove()
- {
- throw new UnsupportedOperationException("remove");
- }
+ /**
+ * @inheritDoc
+ */
+ public boolean hasNext() {
+ init();
+ return selfAndChildren.hasNext();
+ }
- /**
- * @inheritDoc
- */
- public boolean hasNext()
- {
- init();
- return selfAndChildren.hasNext();
- }
+ /**
+ * @inheritDoc
+ */
+ public Object next() {
+ init();
+ NodeImpl n = (NodeImpl) selfAndChildren.next();
+ return n;
+ }
- /**
- * @inheritDoc
- */
- public Object next()
- {
- init();
- NodeData n = (NodeData)selfAndChildren.next();
- return n;
- }
-
- /**
- * Initializes the iterator chain once.
- */
- private void init()
- {
- if (selfAndChildren == null)
- {
- List allIterators = new ArrayList();
- Iterator current = Collections.singletonList(currentNode).iterator();
- allIterators.add(current);
- if (maxDepth == 0)
- {
- // only current node
+ /**
+ * Initializes the iterator chain once.
+ */
+ private void init() {
+ if (selfAndChildren == null) {
+ List allIterators = new ArrayList();
+ Iterator current = Collections.singletonList(currentNode).iterator();
+ allIterators.add(current);
+ if (maxDepth == 0) {
+ // only current node
+ } else if (maxDepth == 1) {
+ try {
+ allIterators.add(currentNode.getNodes());
+ } catch (RepositoryException e) {
+ // currentNode is probably stale
+ }
+ } else {
+ // create new TraversingNodeIterator for each child
+ try {
+ NodeIterator children = currentNode.getNodes();
+ while (children.hasNext()) {
+ allIterators.add(new TraversingNodeIterator(children.nextNode(), maxDepth - 1));
+ }
+ } catch (RepositoryException e) {
+ // currentNode is probably stale
+ }
+ }
+ selfAndChildren = new IteratorChain(allIterators);
}
- else if (maxDepth == 1)
- {
- try
- {
- allIterators.add(contextHolder.getDataManger().getChildNodesData(currentNode).iterator());
- }
- catch (RepositoryException e)
- {
- // currentNode is probably stale
- }
- }
- else
- {
- // create new TraversingNodeIterator for each child
- try
- {
- Iterator<NodeData> children = contextHolder.getDataManger().getChildNodesData(currentNode).iterator();
- while (children.hasNext())
- {
- allIterators.add(new TraversingNodeIterator(contextHolder, children.next(), maxDepth - 1));
- }
- }
- catch (RepositoryException e)
- {
- // currentNode is probably stale
- }
- }
- selfAndChildren = new IteratorChain(allIterators);
- }
- }
- }
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NotQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NotQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/NotQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -33,260 +33,211 @@
* Documents that did not match the context query will be selected by this
* <code>NotQuery</code>.
*/
-class NotQuery extends Query
-{
+class NotQuery extends Query {
- /**
- * The context query to invert.
- */
- private Query context;
+ /**
+ * The context query to invert.
+ */
+ private final Query context;
- /**
- * The context scorer to invert.
- */
- private transient Scorer contextScorer;
+ /**
+ * The context scorer to invert.
+ */
+ private Scorer contextScorer;
- /**
- * for serialization
- */
- public NotQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Creates a new <code>NotQuery</code>.
+ * @param context the context query.
+ */
+ NotQuery(Query context) {
+ this.context = context;
+ }
- /**
- * Creates a new <code>NotQuery</code>.
- * @param context the context query.
- */
- NotQuery(Query context)
- {
- this.context = context;
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Weight createWeight(Searcher searcher) {
+ return new NotQueryWeight(searcher);
+ }
- /**
- * {@inheritDoc}
- */
- protected Weight createWeight(Searcher searcher)
- {
- return new NotQueryWeight(searcher);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field) {
+ return "NotQuery";
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field)
- {
- return "NotQuery";
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ context.extractTerms(terms);
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- context.extractTerms(terms);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ Query cQuery = context.rewrite(reader);
+ if (cQuery == context) {
+ return this;
+ } else {
+ return new NotQuery(cQuery);
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (reader instanceof JcrIndexReader && context instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)context).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
-
- Query cQuery = context.rewrite(reader);
- if (cQuery == context)
- {
- return this;
- }
- else
- {
- return new NotQuery(cQuery);
- }
- }
+ /**
+ * Implements a weight for this <code>NotQuery</code>.
+ */
+ private class NotQueryWeight implements Weight {
- /**
- * Implements a weight for this <code>NotQuery</code>.
- */
- private class NotQueryWeight implements Weight
- {
+ /**
+ * The searcher to access the index.
+ */
+ private final Searcher searcher;
- /**
- * The searcher to access the index.
- */
- private final Searcher searcher;
+ /**
+ * Creates a new NotQueryWeight with a searcher.
+ * @param searcher the searcher.
+ */
+ NotQueryWeight(Searcher searcher) {
+ this.searcher = searcher;
+ }
- /**
- * Creates a new NotQueryWeight with a searcher.
- * @param searcher the searcher.
- */
- NotQueryWeight(Searcher searcher)
- {
- this.searcher = searcher;
- }
+ /**
+ * @inheritDoc
+ */
+ public Query getQuery() {
+ return NotQuery.this;
+ }
- /**
- * @inheritDoc
- */
- public Query getQuery()
- {
- return NotQuery.this;
- }
+ /**
+ * @inheritDoc
+ */
+ public float getValue() {
+ return 1.0f;
+ }
- /**
- * @inheritDoc
- */
- public float getValue()
- {
- return 1.0f;
- }
+ /**
+ * @inheritDoc
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return 1.0f;
+ }
- /**
- * @inheritDoc
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * @inheritDoc
+ */
+ public void normalize(float norm) {
+ }
- /**
- * @inheritDoc
- */
- public void normalize(float norm)
- {
- }
+ /**
+ * @inheritDoc
+ */
+ public Scorer scorer(IndexReader reader) throws IOException {
+ contextScorer = context.weight(searcher).scorer(reader);
+ return new NotQueryScorer(reader);
+ }
- /**
- * @inheritDoc
- */
- public Scorer scorer(IndexReader reader) throws IOException
- {
- contextScorer = context.weight(searcher).scorer(reader);
- return new NotQueryScorer(reader);
- }
+ /**
+ * @throws UnsupportedOperationException always
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+ }
- /**
- * @throws UnsupportedOperationException always
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- throw new UnsupportedOperationException();
- }
- }
+ /**
+ * Implements a scorer that inverts the document matches of the context
+ * scorer.
+ */
+ private class NotQueryScorer extends Scorer {
- /**
- * Implements a scorer that inverts the document matches of the context
- * scorer.
- */
- private class NotQueryScorer extends Scorer
- {
+ /**
+ * The index reader.
+ */
+ private final IndexReader reader;
- /**
- * The index reader.
- */
- private final IndexReader reader;
+ /**
+ * Current document number.
+ */
+ private int docNo = -1;
- /**
- * Current document number.
- */
- private int docNo = -1;
+ /**
+ * Current document number of the context scorer;
+ */
+ private int contextNo = -1;
- /**
- * Current document number of the context scorer;
- */
- private int contextNo = -1;
+ /**
+ * Creates a new scorer
+ * @param reader
+ */
+ NotQueryScorer(IndexReader reader) {
+ super(Similarity.getDefault());
+ this.reader = reader;
+ }
- /**
- * Creates a new scorer
- * @param reader
- */
- NotQueryScorer(IndexReader reader)
- {
- super(Similarity.getDefault());
- this.reader = reader;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException
- {
- if (docNo == -1)
- {
- // get first doc of context scorer
- if (contextScorer.next())
- {
- contextNo = contextScorer.doc();
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException {
+ if (docNo == -1) {
+ // get first doc of context scorer
+ if (contextScorer.next()) {
+ contextNo = contextScorer.doc();
+ }
}
- }
- // move to next candidate
- do
- {
- docNo++;
- }
- while (reader.isDeleted(docNo) && docNo < reader.maxDoc());
+ // move to next candidate
+ do {
+ docNo++;
+ } while (reader.isDeleted(docNo) && docNo < reader.maxDoc());
- // check with contextScorer
- while (contextNo != -1 && contextNo == docNo)
- {
- docNo++;
- if (contextScorer.next())
- {
- contextNo = contextScorer.doc();
+ // check with contextScorer
+ while (contextNo != -1 && contextNo == docNo) {
+ docNo++;
+ if (contextScorer.next()) {
+ contextNo = contextScorer.doc();
+ } else {
+ contextNo = -1;
+ }
}
- else
- {
- contextNo = -1;
- }
- }
- return docNo < reader.maxDoc();
- }
+ return docNo < reader.maxDoc();
+ }
- /**
- * {@inheritDoc}
- */
- public int doc()
- {
- return docNo;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc() {
+ return docNo;
+ }
- /**
- * {@inheritDoc}
- */
- public float score() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() throws IOException {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException
- {
- if (contextNo != -1 && contextNo < target)
- {
- if (contextScorer.skipTo(target))
- {
- contextNo = contextScorer.doc();
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException {
+ if (contextNo != -1 && contextNo < target) {
+ if (contextScorer.skipTo(target)) {
+ contextNo = contextScorer.doc();
+ } else {
+ contextNo = -1;
+ }
}
- else
- {
- contextNo = -1;
- }
- }
- docNo = target - 1;
- return next();
- }
+ docNo = target - 1;
+ return next();
+ }
- /**
- * @throws UnsupportedOperationException always
- */
- public Explanation explain(int doc) throws IOException
- {
- throw new UnsupportedOperationException();
- }
- }
+ /**
+ * @throws UnsupportedOperationException always
+ */
+ public Explanation explain(int doc) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ParentAxisQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ParentAxisQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ParentAxisQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,6 +16,12 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import java.io.IOException;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.HitCollector;
@@ -24,392 +30,339 @@
import org.apache.lucene.search.Searcher;
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.Weight;
+
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.impl.core.query.lucene.hits.Hits;
import org.exoplatform.services.jcr.impl.core.query.lucene.hits.ScorerHits;
-import java.io.IOException;
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
/**
* <code>ParentAxisQuery</code> selects the parent nodes of a context query.
*/
-class ParentAxisQuery extends AbstractLuceneQuery
-{
+class ParentAxisQuery extends Query {
- /**
- * Default score is 1.0f.
- */
- private static final Float DEFAULT_SCORE = new Float(1.0f);
+ /**
+ * Default score is 1.0f.
+ */
+ private static final Float DEFAULT_SCORE = new Float(1.0f);
- /**
- * The context query
- */
- private Query contextQuery;
+ /**
+ * The context query
+ */
+ private final Query contextQuery;
- /**
- * The nameTest to apply on the parent axis, or <code>null</code> if any
- * parent node should be selected.
- */
- private InternalQName nameTest;
+ /**
+ * The nameTest to apply on the parent axis, or <code>null</code> if any
+ * parent node should be selected.
+ */
+ private final InternalQName nameTest;
- /**
- * The index format version.
- */
- private IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private final IndexFormatVersion version;
- /**
- * The scorer of the context query
- */
- private transient Scorer contextScorer;
+ /**
+ * The internal namespace mappings.
+ */
+ private final NamespaceMappings nsMappings;
- /**
- * Creates a new <code>ParentAxisQuery</code> based on a
- * <code>context</code> query.
- *
- * @param context the context for this query.
- * @param nameTest a name test or <code>null</code> if any parent node is
- * selected.
- * @param version the index format version.
- * @param nsMappings the internal namespace mappings.
- */
- ParentAxisQuery(Query context, InternalQName nameTest, IndexFormatVersion version, NamespaceMappings nsMappings)
- {
- super(null, nsMappings);
- this.contextQuery = context;
- this.nameTest = nameTest;
- this.version = version;
- }
+ /**
+ * The scorer of the context query
+ */
+ private Scorer contextScorer;
- /**
- * Creates a <code>Weight</code> instance for this query.
- *
- * @param searcher the <code>Searcher</code> instance to use.
- * @return a <code>ParentAxisWeight</code>.
- */
- protected Weight createWeight(Searcher searcher)
- {
- return new ParentAxisWeight(searcher);
- }
+ /**
+ * Creates a new <code>ParentAxisQuery</code> based on a
+ * <code>context</code> query.
+ *
+ * @param context the context for this query.
+ * @param nameTest a name test or <code>null</code> if any parent node is
+ * selected.
+ * @param version the index format version.
+ * @param nsMappings the internal namespace mappings.
+ */
+ ParentAxisQuery(Query context, InternalQName nameTest,
+ IndexFormatVersion version, NamespaceMappings nsMappings) {
+ this.contextQuery = context;
+ this.nameTest = nameTest;
+ this.version = version;
+ this.nsMappings = nsMappings;
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- contextQuery.extractTerms(terms);
- }
+ /**
+ * Creates a <code>Weight</code> instance for this query.
+ *
+ * @param searcher the <code>Searcher</code> instance to use.
+ * @return a <code>ParentAxisWeight</code>.
+ */
+ protected Weight createWeight(Searcher searcher) {
+ return new ParentAxisWeight(searcher);
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (reader instanceof JcrIndexReader && contextQuery instanceof AbstractLuceneQuery)
- {
- ((AbstractLuceneQuery)contextQuery).setContextHolder(((JcrIndexReader)reader).getContextHolder());
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
-
- Query cQuery = contextQuery.rewrite(reader);
- if (cQuery == contextQuery)
- {
- return this;
- }
- else
- {
- AbstractLuceneQuery newQuery = new ParentAxisQuery(cQuery, nameTest, version, getNamespaceMappings());
- if (reader instanceof JcrIndexReader)
- {
- newQuery.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- return newQuery;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ contextQuery.extractTerms(terms);
+ }
- /**
- * Always returns 'ParentAxisQuery'.
- *
- * @param field the name of a field.
- * @return 'ParentAxisQuery'.
- */
- public String toString(String field)
- {
- return "ParentAxisQuery " + "nameTest=" + (nameTest != null ? nameTest.toString() : "null") + " contextQuery="
- + contextQuery.toString();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ Query cQuery = contextQuery.rewrite(reader);
+ if (cQuery == contextQuery) {
+ return this;
+ } else {
+ return new ParentAxisQuery(cQuery, nameTest, version, nsMappings);
+ }
+ }
- //-----------------------< ParentAxisWeight >-------------------------------
+ /**
+ * Always returns 'ParentAxisQuery'.
+ *
+ * @param field the name of a field.
+ * @return 'ParentAxisQuery'.
+ */
+ public String toString(String field) {
+ return "ParentAxisQuery "+"nameTest="+(nameTest!=null?nameTest.toString():"null")+" contextQuery="+contextQuery.toString();
+ }
- /**
- * The <code>Weight</code> implementation for this <code>ParentAxisQuery</code>.
- */
- private class ParentAxisWeight implements Weight
- {
+ //-----------------------< ParentAxisWeight >-------------------------------
- /**
- * The searcher in use
- */
- private final Searcher searcher;
+ /**
+ * The <code>Weight</code> implementation for this <code>ParentAxisQuery</code>.
+ */
+ private class ParentAxisWeight implements Weight {
- /**
- * Creates a new <code>ParentAxisWeight</code> instance using
- * <code>searcher</code>.
- *
- * @param searcher a <code>Searcher</code> instance.
- */
- private ParentAxisWeight(Searcher searcher)
- {
- this.searcher = searcher;
- }
+ /**
+ * The searcher in use
+ */
+ private final Searcher searcher;
- /**
- * Returns this <code>ParentAxisQuery</code>.
- *
- * @return this <code>ParentAxisQuery</code>.
- */
- public Query getQuery()
- {
- return ParentAxisQuery.this;
- }
+ /**
+ * Creates a new <code>ParentAxisWeight</code> instance using
+ * <code>searcher</code>.
+ *
+ * @param searcher a <code>Searcher</code> instance.
+ */
+ private ParentAxisWeight(Searcher searcher) {
+ this.searcher = searcher;
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue()
- {
- return 1.0f;
- }
+ /**
+ * Returns this <code>ParentAxisQuery</code>.
+ *
+ * @return this <code>ParentAxisQuery</code>.
+ */
+ public Query getQuery() {
+ return ParentAxisQuery.this;
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue() {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm)
- {
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return 1.0f;
+ }
- /**
- * Creates a scorer for this <code>ParentAxisQuery</code>.
- *
- * @param reader a reader for accessing the index.
- * @return a <code>ParentAxisScorer</code>.
- * @throws IOException if an error occurs while reading from the index.
- */
- public Scorer scorer(IndexReader reader) throws IOException
- {
- contextScorer = contextQuery.weight(searcher).scorer(reader);
- HierarchyResolver resolver = (HierarchyResolver)reader;
- return new ParentAxisScorer(searcher.getSimilarity(), reader, searcher, resolver);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm) {
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- return new Explanation();
- }
- }
+ /**
+ * Creates a scorer for this <code>ParentAxisQuery</code>.
+ *
+ * @param reader a reader for accessing the index.
+ * @return a <code>ParentAxisScorer</code>.
+ * @throws IOException if an error occurs while reading from the index.
+ */
+ public Scorer scorer(IndexReader reader) throws IOException {
+ contextScorer = contextQuery.weight(searcher).scorer(reader);
+ HierarchyResolver resolver = (HierarchyResolver) reader;
+ return new ParentAxisScorer(searcher.getSimilarity(),
+ reader, searcher, resolver);
+ }
- //--------------------------< ParentAxisScorer >----------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException {
+ return new Explanation();
+ }
+ }
- /**
- * Implements a <code>Scorer</code> for this <code>ParentAxisQuery</code>.
- */
- private class ParentAxisScorer extends Scorer
- {
+ //--------------------------< ParentAxisScorer >----------------------------
- /**
- * An <code>IndexReader</code> to access the index.
- */
- private final IndexReader reader;
+ /**
+ * Implements a <code>Scorer</code> for this <code>ParentAxisQuery</code>.
+ */
+ private class ParentAxisScorer extends Scorer {
- /**
- * The <code>HierarchyResolver</code> of the index.
- */
- private final HierarchyResolver hResolver;
+ /**
+ * An <code>IndexReader</code> to access the index.
+ */
+ private final IndexReader reader;
- /**
- * The searcher instance.
- */
- private final Searcher searcher;
+ /**
+ * The <code>HierarchyResolver</code> of the index.
+ */
+ private final HierarchyResolver hResolver;
- /**
- * BitSet storing the id's of selected documents
- */
- private BitSet hits;
+ /**
+ * The searcher instance.
+ */
+ private final Searcher searcher;
- /**
- * Map that contains the scores from matching documents from the context
- * query. To save memory only scores that are not equal to 1.0f are put
- * to this map.
- * <p/>
- * key=[Integer] id of selected document from context query<br>
- * value=[Float] score for that document
- */
- private final Map scores = new HashMap();
+ /**
+ * BitSet storing the id's of selected documents
+ */
+ private BitSet hits;
- /**
- * The next document id to return
- */
- private int nextDoc = -1;
+ /**
+ * Map that contains the scores from matching documents from the context
+ * query. To save memory only scores that are not equal to 1.0f are put
+ * to this map.
+ * <p/>
+ * key=[Integer] id of selected document from context query<br>
+ * value=[Float] score for that document
+ */
+ private final Map scores = new HashMap();
- /**
- * Creates a new <code>ParentAxisScorer</code>.
- *
- * @param similarity the <code>Similarity</code> instance to use.
- * @param reader for index access.
- * @param searcher the index searcher.
- * @param resolver the hierarchy resolver.
- */
- protected ParentAxisScorer(Similarity similarity, IndexReader reader, Searcher searcher,
- HierarchyResolver resolver)
- {
- super(similarity);
- this.reader = reader;
- this.searcher = searcher;
- this.hResolver = resolver;
- }
+ /**
+ * The next document id to return
+ */
+ private int nextDoc = -1;
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException
- {
- calculateParent();
- nextDoc = hits.nextSetBit(nextDoc + 1);
- return nextDoc > -1;
- }
+ /**
+ * Creates a new <code>ParentAxisScorer</code>.
+ *
+ * @param similarity the <code>Similarity</code> instance to use.
+ * @param reader for index access.
+ * @param searcher the index searcher.
+ * @param resolver the hierarchy resolver.
+ */
+ protected ParentAxisScorer(Similarity similarity,
+ IndexReader reader,
+ Searcher searcher,
+ HierarchyResolver resolver) {
+ super(similarity);
+ this.reader = reader;
+ this.searcher = searcher;
+ this.hResolver = resolver;
+ }
- /**
- * {@inheritDoc}
- */
- public int doc()
- {
- return nextDoc;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException {
+ calculateParent();
+ nextDoc = hits.nextSetBit(nextDoc + 1);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public float score() throws IOException
- {
- Float score = (Float)scores.get(new Integer(nextDoc));
- if (score == null)
- {
- score = DEFAULT_SCORE;
- }
- return score.floatValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc() {
+ return nextDoc;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException
- {
- calculateParent();
- nextDoc = hits.nextSetBit(target);
- return nextDoc > -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() throws IOException {
+ Float score = (Float) scores.get(new Integer(nextDoc));
+ if (score == null) {
+ score = DEFAULT_SCORE;
+ }
+ return score.floatValue();
+ }
- /**
- * {@inheritDoc}
- *
- * @throws UnsupportedOperationException this implementation always
- * throws an <code>UnsupportedOperationException</code>.
- */
- public Explanation explain(int doc) throws IOException
- {
- throw new UnsupportedOperationException();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException {
+ calculateParent();
+ nextDoc = hits.nextSetBit(target);
+ return nextDoc > -1;
+ }
- private void calculateParent() throws IOException
- {
- if (hits == null)
- {
- hits = new BitSet(reader.maxDoc());
+ /**
+ * {@inheritDoc}
+ *
+ * @throws UnsupportedOperationException this implementation always
+ * throws an <code>UnsupportedOperationException</code>.
+ */
+ public Explanation explain(int doc) throws IOException {
+ throw new UnsupportedOperationException();
+ }
- final IOException[] ex = new IOException[1];
- contextScorer.score(new HitCollector()
- {
+ private void calculateParent() throws IOException {
+ if (hits == null) {
+ hits = new BitSet(reader.maxDoc());
- private int[] docs = new int[1];
+ final IOException[] ex = new IOException[1];
+ contextScorer.score(new HitCollector() {
- public void collect(int doc, float score)
- {
- try
- {
- docs = hResolver.getParents(doc, docs);
- if (docs.length == 1)
- {
- // optimize single value
- hits.set(docs[0]);
- if (score != DEFAULT_SCORE.floatValue())
- {
- scores.put(new Integer(docs[0]), new Float(score));
+ private int[] docs = new int[1];
+
+ public void collect(int doc, float score) {
+ try {
+ docs = hResolver.getParents(doc, docs);
+ if (docs.length == 1) {
+ // optimize single value
+ hits.set(docs[0]);
+ if (score != DEFAULT_SCORE.floatValue()) {
+ scores.put(new Integer(docs[0]), new Float(score));
+ }
+ } else {
+ for (int i = 0; i < docs.length; i++) {
+ hits.set(docs[i]);
+ if (score != DEFAULT_SCORE.floatValue()) {
+ scores.put(new Integer(docs[i]), new Float(score));
+ }
+ }
+ }
+ } catch (IOException e) {
+ ex[0] = e;
}
- }
- else
- {
- for (int i = 0; i < docs.length; i++)
- {
- hits.set(docs[i]);
- if (score != DEFAULT_SCORE.floatValue())
- {
- scores.put(new Integer(docs[i]), new Float(score));
- }
- }
- }
- }
- catch (IOException e)
- {
- ex[0] = e;
- }
- }
- });
+ }
+ });
- if (ex[0] != null)
- {
- throw ex[0];
- }
+ if (ex[0] != null) {
+ throw ex[0];
+ }
- // filter out documents that do not match the name test
- if (nameTest != null)
- {
- Query nameQuery = new NameQuery(nameTest, version, getNamespaceMappings());
- Hits nameHits = new ScorerHits(nameQuery.weight(searcher).scorer(reader));
- for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1))
- {
- int doc = nameHits.skipTo(i);
- if (doc == -1)
- {
- // no more name tests, clear remaining
- hits.clear(i, hits.length());
- }
- else
- {
- // assert doc >= i
- if (doc > i)
- {
- // clear hits
- hits.clear(i, doc);
- i = doc;
- }
- }
- }
+ // filter out documents that do not match the name test
+ if (nameTest != null) {
+ Query nameQuery = new NameQuery(nameTest, version, nsMappings);
+ Hits nameHits = new ScorerHits(nameQuery.weight(searcher).scorer(reader));
+ for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
+ int doc = nameHits.skipTo(i);
+ if (doc == -1) {
+ // no more name tests, clear remaining
+ hits.clear(i, hits.length());
+ } else {
+ // assert doc >= i
+ if (doc > i) {
+ // clear hits
+ hits.clear(i, doc);
+ i = doc;
+ }
+ }
+ }
+ }
}
- }
- }
- }
+ }
+ }
}
Deleted: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryContextHolder.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryContextHolder.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryContextHolder.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2010 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.lucene;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.exoplatform.services.jcr.core.NamespaceAccessor;
-import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
-import org.exoplatform.services.jcr.impl.core.LocationFactory;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.RepositoryException;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: QueryContextHolder.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class QueryContextHolder
-{
- private ItemDataConsumer dataConsumer;
-
- private NamespaceAccessor namespaces;
-
- private LocationFactory locationFactory;
-
- private NamespaceMappings namespaceMappings;
-
- private Analyzer analyzer = null;
-
- public QueryContextHolder(ItemDataConsumer dataConsumer, NamespaceAccessor namespaces)
- {
- this(dataConsumer, namespaces, new LocationFactory(namespaces), null);
- }
-
- public QueryContextHolder(ItemDataConsumer dataConsumer, NamespaceAccessor namespaces,
- LocationFactory locationFactory)
- {
- this(dataConsumer, namespaces, locationFactory, null);
- }
-
- public QueryContextHolder(ItemDataConsumer dataConsumer, LocationFactory locationFactory)
- {
- this(dataConsumer, null, locationFactory, null);
- }
-
- public QueryContextHolder(ItemDataConsumer dataConsumer, NamespaceAccessor namespaces,
- LocationFactory locationFactory, NamespaceMappings namespaceMappings)
- {
- super();
- this.dataConsumer = dataConsumer;
- this.namespaces = namespaces;
- this.locationFactory = locationFactory;
- this.namespaceMappings = namespaceMappings == null ? new DefaultNamespaceMapping(namespaces) : namespaceMappings;
- }
-
- public ItemDataConsumer getDataManger()
- {
- assert dataConsumer != null;
- return dataConsumer;
- }
-
- public NamespaceAccessor getNamespaces()
- {
- assert namespaces != null;
- return namespaces;
- }
-
- public LocationFactory getLocationFactory()
- {
- assert locationFactory != null;
- return locationFactory;
- }
-
- public NamespaceMappings getNamespaceMappings()
- {
- assert namespaceMappings != null;
- return namespaceMappings;
- }
-
- private class DefaultNamespaceMapping extends AbstractNamespaceMappings
- {
-
- private NamespaceAccessor accessor;
-
- public DefaultNamespaceMapping(NamespaceAccessor accessor)
- {
- super();
- this.accessor = accessor;
- }
-
- public String[] getAllNamespacePrefixes() throws RepositoryException
- {
- return accessor.getAllNamespacePrefixes();
- }
-
- public String getNamespacePrefixByURI(String uri) throws NamespaceException, RepositoryException
- {
- return accessor.getNamespacePrefixByURI(uri);
- }
-
- public String getNamespaceURIByPrefix(String prefix) throws NamespaceException, RepositoryException
- {
- return accessor.getNamespaceURIByPrefix(prefix);
- }
- }
-
- protected void setNamespaces(NamespaceAccessor namespaces)
- {
- this.namespaces = namespaces;
- }
-
- protected void setLocationFactory(LocationFactory locationFactory)
- {
- this.locationFactory = locationFactory;
- }
-
- protected void setNamespaceMappings(NamespaceMappings namespaceMappings)
- {
- this.namespaceMappings = namespaceMappings;
- }
-
- public Analyzer getAnalyzer()
- {
- return analyzer;
- }
-
- protected void setAnalyzer(Analyzer analyzer)
- {
- this.analyzer = analyzer;
- }
-
-}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryHitsQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryHitsQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryHitsQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -16,6 +16,13 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
@@ -26,273 +33,227 @@
import org.apache.lucene.search.Similarity;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.Weight;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
/**
* <code>QueryHitsQuery</code> exposes a {@link QueryHits} implementation again
* as a Lucene Query.
*/
-public class QueryHitsQuery extends Query implements JcrQuery
-{
+public class QueryHitsQuery extends Query implements JcrQuery{
- /**
- * The underlying query hits.
- */
- private QueryHits hits;
+ /**
+ * The underlying query hits.
+ */
+ private final QueryHits hits;
- /**
- * for serialization
- */
- public QueryHitsQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Creates a new query based on {@link QueryHits}.
+ *
+ * @param hits the query hits.
+ */
+ public QueryHitsQuery(QueryHits hits) {
+ this.hits = hits;
+ }
- /**
- * Creates a new query based on {@link QueryHits}.
- *
- * @param hits the query hits.
- */
- public QueryHitsQuery(QueryHits hits)
- {
- this.hits = hits;
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Weight createWeight(Searcher searcher) throws IOException {
+ return new QueryHitsQueryWeight(searcher.getSimilarity());
+ }
- /**
- * {@inheritDoc}
- */
- protected Weight createWeight(Searcher searcher) throws IOException
- {
- return new QueryHitsQueryWeight(searcher.getSimilarity());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field) {
+ return "QueryHitsQuery";
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field)
- {
- return "QueryHitsQuery";
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ // no terms
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- // no terms
- }
+ //-----------------------< JackrabbitQuery >--------------------------------
- //-----------------------< JackrabbitQuery >--------------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public QueryHits execute(JcrIndexSearcher searcher,
+ SessionImpl session,
+ Sort sort) throws IOException {
+ if (sort.getSort().length == 0) {
+ return hits;
+ } else {
+ return null;
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public QueryHits execute(JcrIndexSearcher searcher, QueryContextHolder contextHolder, Sort sort) throws IOException
- {
- if (sort.getSort().length == 0)
- {
- return hits;
- }
- else
- {
- return null;
- }
- }
+ //------------------------< QueryHitsQueryWeight >--------------------------
- //------------------------< QueryHitsQueryWeight >--------------------------
+ /**
+ * The Weight implementation for this query.
+ */
+ public class QueryHitsQueryWeight implements Weight {
- /**
- * The Weight implementation for this query.
- */
- public class QueryHitsQueryWeight implements Weight
- {
+ /**
+ * The similarity.
+ */
+ private final Similarity similarity;
- /**
- * The similarity.
- */
- private final Similarity similarity;
+ /**
+ * Creates a new weight with the given <code>similarity</code>.
+ *
+ * @param similarity the similarity.
+ */
+ public QueryHitsQueryWeight(Similarity similarity) {
+ this.similarity = similarity;
+ }
- /**
- * Creates a new weight with the given <code>similarity</code>.
- *
- * @param similarity the similarity.
- */
- public QueryHitsQueryWeight(Similarity similarity)
- {
- this.similarity = similarity;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query getQuery() {
+ return QueryHitsQuery.this;
+ }
- /**
- * {@inheritDoc}
- */
- public Query getQuery()
- {
- return QueryHitsQuery.this;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue() {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue()
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm) {
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm)
- {
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Scorer scorer(IndexReader reader) throws IOException {
+ return new QueryHitsQueryScorer(reader, similarity);
+ }
- /**
- * {@inheritDoc}
- */
- public Scorer scorer(IndexReader reader) throws IOException
- {
- return new QueryHitsQueryScorer(reader, similarity);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException {
+ return new Explanation();
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- return new Explanation();
- }
- }
+ //-------------------< QueryHitsQueryScorer >-------------------------------
- //-------------------< QueryHitsQueryScorer >-------------------------------
+ /**
+ * the scorer implementation for this query.
+ */
+ public class QueryHitsQueryScorer extends Scorer {
- /**
- * the scorer implementation for this query.
- */
- public class QueryHitsQueryScorer extends Scorer
- {
+ /**
+ * Iterator over <code>Integer</code> instances identifying the
+ * lucene documents. Document numbers are iterated in ascending order.
+ */
+ private final Iterator docs;
- /**
- * Iterator over <code>Integer</code> instances identifying the
- * lucene documents. Document numbers are iterated in ascending order.
- */
- private final Iterator docs;
+ /**
+ * Maps <code>Integer</code> document numbers to <code>Float</code>
+ * scores.
+ */
+ private final Map scores = new HashMap();
- /**
- * Maps <code>Integer</code> document numbers to <code>Float</code>
- * scores.
- */
- private final Map scores = new HashMap();
+ /**
+ * The current document number.
+ */
+ private Integer currentDoc = null;
- /**
- * The current document number.
- */
- private Integer currentDoc = null;
+ /**
+ * Creates a new scorer.
+ *
+ * @param reader the index reader.
+ * @param similarity the similarity implementation.
+ * @throws IOException if an error occurs while reading from the index.
+ */
+ protected QueryHitsQueryScorer(IndexReader reader,
+ Similarity similarity)
+ throws IOException {
+ super(similarity);
+ ScoreNode node;
+ Set sortedDocs = new TreeSet();
+ try {
+ while ((node = hits.nextScoreNode()) != null) {
+ String uuid = node.getNodeId();
+ Term id = new Term(FieldNames.UUID, uuid);
+ TermDocs tDocs = reader.termDocs(id);
+ try {
+ if (tDocs.next()) {
+ Integer doc = new Integer(tDocs.doc());
+ sortedDocs.add(doc);
+ scores.put(doc, new Float(node.getScore()));
+ }
+ } finally {
+ tDocs.close();
+ }
+ }
+ } finally {
+ hits.close();
+ }
+ docs = sortedDocs.iterator();
+ }
- /**
- * Creates a new scorer.
- *
- * @param reader the index reader.
- * @param similarity the similarity implementation.
- * @throws IOException if an error occurs while reading from the index.
- */
- protected QueryHitsQueryScorer(IndexReader reader, Similarity similarity) throws IOException
- {
- super(similarity);
- ScoreNode node;
- Set sortedDocs = new TreeSet();
- try
- {
- while ((node = hits.nextScoreNode()) != null)
- {
- String uuid = node.getNodeId();
- Term id = new Term(FieldNames.UUID, uuid);
- TermDocs tDocs = reader.termDocs(id);
- try
- {
- if (tDocs.next())
- {
- Integer doc = new Integer(tDocs.doc());
- sortedDocs.add(doc);
- scores.put(doc, new Float(node.getScore()));
- }
- }
- finally
- {
- tDocs.close();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException {
+ if (docs.hasNext()) {
+ currentDoc = (Integer) docs.next();
+ return true;
}
- }
- finally
- {
- hits.close();
- }
- docs = sortedDocs.iterator();
- }
+ return false;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException
- {
- if (docs.hasNext())
- {
- currentDoc = (Integer)docs.next();
- return true;
- }
- return false;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc() {
+ return currentDoc.intValue();
+ }
- /**
- * {@inheritDoc}
- */
- public int doc()
- {
- return currentDoc.intValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() throws IOException {
+ return ((Float) scores.get(currentDoc)).floatValue();
+ }
- /**
- * {@inheritDoc}
- */
- public float score() throws IOException
- {
- return ((Float)scores.get(currentDoc)).floatValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException {
+ do {
+ if (!next()) {
+ return false;
+ }
+ } while (target > doc());
+ return true;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException
- {
- do
- {
- if (!next())
- {
- return false;
- }
- }
- while (target > doc());
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public Explanation explain(int doc) throws IOException
- {
- return new Explanation();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(int doc) throws IOException {
+ return new Explanation();
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RangeQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RangeQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/RangeQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -40,525 +40,449 @@
/**
* Implements a lucene range query.
*/
-public class RangeQuery extends Query implements Transformable
-{
+public class RangeQuery extends Query implements Transformable {
- /**
- * The lower term. May be <code>null</code> if <code>upperTerm</code> is not
- * <code>null</code>.
- */
- private Term lowerTerm;
+ /**
+ * The lower term. May be <code>null</code> if <code>upperTerm</code> is not
+ * <code>null</code>.
+ */
+ private Term lowerTerm;
- /**
- * The upper term. May be <code>null</code> if <code>lowerTerm</code> is not
- * <code>null</code>.
- */
- private Term upperTerm;
+ /**
+ * The upper term. May be <code>null</code> if <code>lowerTerm</code> is not
+ * <code>null</code>.
+ */
+ private Term upperTerm;
- /**
- * If <code>true</code> the range interval is inclusive.
- */
- private boolean inclusive;
+ /**
+ * If <code>true</code> the range interval is inclusive.
+ */
+ private boolean inclusive;
- /**
- * How the term enum is transformed before it is compared to lower and upper
- * term.
- */
- private int transform;
+ /**
+ * How the term enum is transformed before it is compared to lower and upper
+ * term.
+ */
+ private int transform = TRANSFORM_NONE;
- /**
- * for serialization
- */
- public RangeQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * Creates a new RangeQuery. The lower or the upper term may be
+ * <code>null</code>, but not both!
+ *
+ * @param lowerTerm the lower term of the interval, or <code>null</code>
+ * @param upperTerm the upper term of the interval, or <code>null</code>.
+ * @param inclusive if <code>true</code> the interval is inclusive.
+ */
+ public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive) {
+ this(lowerTerm, upperTerm, inclusive, TRANSFORM_NONE);
+ }
- /**
- * Creates a new RangeQuery. The lower or the upper term may be
- * <code>null</code>, but not both!
- *
- * @param lowerTerm the lower term of the interval, or <code>null</code>
- * @param upperTerm the upper term of the interval, or <code>null</code>.
- * @param inclusive if <code>true</code> the interval is inclusive.
- */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive)
- {
- this(lowerTerm, upperTerm, inclusive, TRANSFORM_NONE);
- }
+ /**
+ * Creates a new RangeQuery. The lower or the upper term may be
+ * <code>null</code>, but not both!
+ *
+ * @param lowerTerm the lower term of the interval, or <code>null</code>
+ * @param upperTerm the upper term of the interval, or <code>null</code>.
+ * @param inclusive if <code>true</code> the interval is inclusive.
+ * @param transform how term enums are transformed when read from the index.
+ */
+ public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, int transform) {
+ if (lowerTerm == null && upperTerm == null) {
+ throw new IllegalArgumentException("At least one term must be non-null");
+ }
+ if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field()) {
+ throw new IllegalArgumentException("Both terms must be for the same field");
+ }
- /**
- * Creates a new RangeQuery. The lower or the upper term may be
- * <code>null</code>, but not both!
- *
- * @param lowerTerm the lower term of the interval, or <code>null</code>
- * @param upperTerm the upper term of the interval, or <code>null</code>.
- * @param inclusive if <code>true</code> the interval is inclusive.
- * @param transform how term enums are transformed when read from the index.
- */
- public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive, int transform)
- {
- if (lowerTerm == null && upperTerm == null)
- {
- throw new IllegalArgumentException("At least one term must be non-null");
- }
- if (lowerTerm != null && upperTerm != null && lowerTerm.field() != upperTerm.field())
- {
- throw new IllegalArgumentException("Both terms must be for the same field");
- }
+ // if we have a lowerTerm, start there. otherwise, start at beginning
+ if (lowerTerm != null) {
+ this.lowerTerm = lowerTerm;
+ } else {
+ this.lowerTerm = new Term(upperTerm.field(), "");
+ }
- // if we have a lowerTerm, start there. otherwise, start at beginning
- if (lowerTerm != null)
- {
- this.lowerTerm = lowerTerm;
- }
- else
- {
- this.lowerTerm = new Term(upperTerm.field(), "");
- }
+ this.upperTerm = upperTerm;
+ this.inclusive = inclusive;
+ this.transform = transform;
+ }
- this.upperTerm = upperTerm;
- this.inclusive = inclusive;
- this.transform = transform;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setTransformation(int transformation) {
+ this.transform = transformation;
+ }
- /**
- * {@inheritDoc}
- */
- public void setTransformation(int transformation)
- {
- this.transform = transformation;
- }
+ /**
+ * Rewrites this query into a {@link ConstantScoreRangeQuery} if
+ * {@link #transform} is {@link #TRANSFORM_NONE}.
+ *
+ * @param reader the index reader.
+ * @return the rewritten query or this query if rewriting is not possible.
+ * @throws IOException if an error occurs.
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ if (transform == TRANSFORM_NONE) {
+ return new ConstantScoreRangeQuery(lowerTerm.field(),
+ lowerTerm.text(), upperTerm.text(), inclusive,
+ inclusive).rewrite(reader);
+ } else {
+ // always use our implementation when we need to transform the
+ // term enum
+ return this;
+ }
+ }
- /**
- * Rewrites this query into a {@link ConstantScoreRangeQuery} if
- * {@link #transform} is {@link #TRANSFORM_NONE}.
- *
- * @param reader the index reader.
- * @return the rewritten query or this query if rewriting is not possible.
- * @throws IOException if an error occurs.
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (transform == TRANSFORM_NONE)
- {
- return new ConstantScoreRangeQuery(lowerTerm.field(), lowerTerm.text(), upperTerm.text(), inclusive, inclusive)
- .rewrite(reader);
- }
- else
- {
- // always use our implementation when we need to transform the
- // term enum
- return this;
- }
- }
+ /**
+ * Creates the <code>Weight</code> for this query.
+ *
+ * @param searcher the searcher to use for the <code>Weight</code>.
+ * @return the <code>Weigth</code> for this query.
+ */
+ protected Weight createWeight(Searcher searcher) {
+ return new RangeQueryWeight(searcher);
+ }
- /**
- * Creates the <code>Weight</code> for this query.
- *
- * @param searcher the searcher to use for the <code>Weight</code>.
- * @return the <code>Weigth</code> for this query.
- */
- protected Weight createWeight(Searcher searcher)
- {
- return new RangeQueryWeight(searcher);
- }
+ /**
+ * Returns a string representation of this query.
+ * @param field the field name for which to create a string representation.
+ * @return a string representation of this query.
+ */
+ public String toString(String field) {
+ StringBuffer buffer = new StringBuffer();
+ if (!getField().equals(field)) {
+ buffer.append(getField());
+ buffer.append(":");
+ }
+ buffer.append(inclusive ? "[" : "{");
+ buffer.append(lowerTerm != null ? lowerTerm.text() : "null");
+ buffer.append(" TO ");
+ buffer.append(upperTerm != null ? upperTerm.text() : "null");
+ buffer.append(inclusive ? "]" : "}");
+ if (getBoost() != 1.0f) {
+ buffer.append("^");
+ buffer.append(Float.toString(getBoost()));
+ }
+ return buffer.toString();
+ }
- /**
- * Returns a string representation of this query.
- * @param field the field name for which to create a string representation.
- * @return a string representation of this query.
- */
- public String toString(String field)
- {
- StringBuffer buffer = new StringBuffer();
- if (!getField().equals(field))
- {
- buffer.append(getField());
- buffer.append(":");
- }
- buffer.append(inclusive ? "[" : "{");
- buffer.append(lowerTerm != null ? lowerTerm.text() : "null");
- buffer.append(" TO ");
- buffer.append(upperTerm != null ? upperTerm.text() : "null");
- buffer.append(inclusive ? "]" : "}");
- if (getBoost() != 1.0f)
- {
- buffer.append("^");
- buffer.append(Float.toString(getBoost()));
- }
- return buffer.toString();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms) {
+ // cannot extract terms
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms)
- {
- // cannot extract terms
- }
+ /**
+ * Returns the field name for this query.
+ */
+ private String getField() {
+ return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
+ }
- /**
- * Returns the field name for this query.
- */
- private String getField()
- {
- return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
- }
+ //--------------------------< RangeQueryWeight >----------------------------
- //--------------------------< RangeQueryWeight >----------------------------
+ /**
+ * The <code>Weight</code> implementation for this <code>RangeQuery</code>.
+ */
+ private class RangeQueryWeight extends AbstractWeight {
- /**
- * The <code>Weight</code> implementation for this <code>RangeQuery</code>.
- */
- private class RangeQueryWeight extends AbstractWeight
- {
+ /**
+ * Creates a new <code>RangeQueryWeight</code> instance using
+ * <code>searcher</code>.
+ *
+ * @param searcher a <code>Searcher</code> instance.
+ */
+ RangeQueryWeight(Searcher searcher) {
+ super(searcher);
+ }
- /**
- * Creates a new <code>RangeQueryWeight</code> instance using
- * <code>searcher</code>.
- *
- * @param searcher a <code>Searcher</code> instance.
- */
- RangeQueryWeight(Searcher searcher)
- {
- super(searcher);
- }
+ /**
+ * Creates a {@link RangeQueryScorer} instance.
+ *
+ * @param reader index reader
+ * @return a {@link RangeQueryScorer} instance
+ */
+ protected Scorer createScorer(IndexReader reader) {
+ return new RangeQueryScorer(searcher.getSimilarity(), reader);
+ };
- /**
- * Creates a {@link RangeQueryScorer} instance.
- *
- * @param reader index reader
- * @return a {@link RangeQueryScorer} instance
- */
- protected Scorer createScorer(IndexReader reader)
- {
- return new RangeQueryScorer(searcher.getSimilarity(), reader);
- };
+ /**
+ * Returns this <code>RangeQuery</code>.
+ *
+ * @return this <code>RangeQuery</code>.
+ */
+ public Query getQuery() {
+ return RangeQuery.this;
+ }
- /**
- * Returns this <code>RangeQuery</code>.
- *
- * @return this <code>RangeQuery</code>.
- */
- public Query getQuery()
- {
- return RangeQuery.this;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue() {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue()
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm) {
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm)
- {
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException {
+ return new Explanation();
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException
- {
- return new Explanation();
- }
- }
+ //------------------------< RangeQueryScorer >------------------------------
- //------------------------< RangeQueryScorer >------------------------------
+ /**
+ * Implements a <code>Scorer</code> for this <code>RangeQuery</code>.
+ */
+ private final class RangeQueryScorer extends Scorer {
- /**
- * Implements a <code>Scorer</code> for this <code>RangeQuery</code>.
- */
- private final class RangeQueryScorer extends Scorer
- {
+ /**
+ * The index reader to use for calculating the matching documents.
+ */
+ private final IndexReader reader;
- /**
- * The index reader to use for calculating the matching documents.
- */
- private final IndexReader reader;
+ /**
+ * The documents ids that match this range query.
+ */
+ private final BitSet hits;
- /**
- * The documents ids that match this range query.
- */
- private final BitSet hits;
+ /**
+ * Set to <code>true</code> when the hits have been calculated.
+ */
+ private boolean hitsCalculated = false;
- /**
- * Set to <code>true</code> when the hits have been calculated.
- */
- private boolean hitsCalculated = false;
+ /**
+ * The next document id to return
+ */
+ private int nextDoc = -1;
- /**
- * The next document id to return
- */
- private int nextDoc = -1;
+ /**
+ * The cache key to use to store the results.
+ */
+ private final String cacheKey;
- /**
- * The cache key to use to store the results.
- */
- private final String cacheKey;
+ /**
+ * The map to store the results.
+ */
+ private final Map resultMap;
- /**
- * The map to store the results.
- */
- private final Map resultMap;
+ /**
+ * Creates a new RangeQueryScorer.
+ * @param similarity the similarity implementation.
+ * @param reader the index reader to use.
+ */
+ RangeQueryScorer(Similarity similarity, IndexReader reader) {
+ super(similarity);
+ this.reader = reader;
+ StringBuffer key = new StringBuffer();
+ key.append(lowerTerm != null ? lowerTerm.field() : upperTerm.field());
+ key.append('\uFFFF');
+ key.append(lowerTerm != null ? lowerTerm.text() : "");
+ key.append('\uFFFF');
+ key.append(upperTerm != null ? upperTerm.text() : "");
+ key.append('\uFFFF');
+ key.append(inclusive);
+ key.append('\uFFFF');
+ key.append(transform);
+ this.cacheKey = key.toString();
+ // check cache
+ PerQueryCache cache = PerQueryCache.getInstance();
+ Map m = (Map) cache.get(RangeQueryScorer.class, reader);
+ if (m == null) {
+ m = new HashMap();
+ cache.put(RangeQueryScorer.class, reader, m);
+ }
+ resultMap = m;
- /**
- * Creates a new RangeQueryScorer.
- * @param similarity the similarity implementation.
- * @param reader the index reader to use.
- */
- RangeQueryScorer(Similarity similarity, IndexReader reader)
- {
- super(similarity);
- this.reader = reader;
- StringBuffer key = new StringBuffer();
- key.append(lowerTerm != null ? lowerTerm.field() : upperTerm.field());
- key.append('\uFFFF');
- key.append(lowerTerm != null ? lowerTerm.text() : "");
- key.append('\uFFFF');
- key.append(upperTerm != null ? upperTerm.text() : "");
- key.append('\uFFFF');
- key.append(inclusive);
- key.append('\uFFFF');
- key.append(transform);
- this.cacheKey = key.toString();
- // check cache
- PerQueryCache cache = PerQueryCache.getInstance();
- Map m = (Map)cache.get(RangeQueryScorer.class, reader);
- if (m == null)
- {
- m = new HashMap();
- cache.put(RangeQueryScorer.class, reader, m);
- }
- resultMap = m;
+ BitSet result = (BitSet) resultMap.get(cacheKey);
+ if (result == null) {
+ result = new BitSet(reader.maxDoc());
+ } else {
+ hitsCalculated = true;
+ }
+ hits = result;
+ }
- BitSet result = (BitSet)resultMap.get(cacheKey);
- if (result == null)
- {
- result = new BitSet(reader.maxDoc());
- }
- else
- {
- hitsCalculated = true;
- }
- hits = result;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException {
+ calculateHits();
+ nextDoc = hits.nextSetBit(nextDoc + 1);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException
- {
- calculateHits();
- nextDoc = hits.nextSetBit(nextDoc + 1);
- return nextDoc > -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc() {
+ return nextDoc;
+ }
- /**
- * {@inheritDoc}
- */
- public int doc()
- {
- return nextDoc;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() {
+ return 1.0f;
+ }
- /**
- * {@inheritDoc}
- */
- public float score()
- {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException {
+ calculateHits();
+ nextDoc = hits.nextSetBit(target);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException
- {
- calculateHits();
- nextDoc = hits.nextSetBit(target);
- return nextDoc > -1;
- }
+ /**
+ * Returns an empty Explanation object.
+ * @return an empty Explanation object.
+ */
+ public Explanation explain(int doc) {
+ return new Explanation();
+ }
- /**
- * Returns an empty Explanation object.
- * @return an empty Explanation object.
- */
- public Explanation explain(int doc)
- {
- return new Explanation();
- }
+ /**
+ * Calculates the ids of the documents matching this range query.
+ * @throws IOException if an error occurs while reading from the index.
+ */
+ private void calculateHits() throws IOException {
+ if (hitsCalculated) {
+ return;
+ }
- /**
- * Calculates the ids of the documents matching this range query.
- * @throws IOException if an error occurs while reading from the index.
- */
- private void calculateHits() throws IOException
- {
- if (hitsCalculated)
- {
- return;
- }
+ String testField = getField();
- String testField = getField();
+ boolean checkLower = false;
+ if (!inclusive || transform != TRANSFORM_NONE) {
+ // make adjustments to set to exclusive
+ checkLower = true;
+ }
- boolean checkLower = false;
- if (!inclusive || transform != TRANSFORM_NONE)
- {
- // make adjustments to set to exclusive
- checkLower = true;
- }
+ int propNameLength = FieldNames.getNameLength(lowerTerm.text());
+ String namePrefix = "";
+ if (propNameLength > 0) {
+ namePrefix = lowerTerm.text().substring(0, propNameLength);
+ }
+ List startTerms = new ArrayList(2);
- int propNameLength = FieldNames.getNameLength(lowerTerm.text());
- String namePrefix = "";
- if (propNameLength > 0)
- {
- namePrefix = lowerTerm.text().substring(0, propNameLength);
- }
- List startTerms = new ArrayList(2);
+ if (transform == TRANSFORM_NONE || lowerTerm.text().length() <= propNameLength) {
+ // use lowerTerm as is
+ startTerms.add(lowerTerm);
+ } else {
+ // first enumerate terms using lower case start character
+ StringBuffer termText = new StringBuffer(propNameLength + 1);
+ termText.append(lowerTerm.text().subSequence(0, propNameLength));
+ char startCharacter = lowerTerm.text().charAt(propNameLength);
+ termText.append(Character.toLowerCase(startCharacter));
+ startTerms.add(new Term(lowerTerm.field(), termText.toString()));
+ // second enumerate terms using upper case start character
+ termText.setCharAt(termText.length() - 1, Character.toUpperCase(startCharacter));
+ startTerms.add(new Term(lowerTerm.field(), termText.toString()));
+ }
- if (transform == TRANSFORM_NONE || lowerTerm.text().length() <= propNameLength)
- {
- // use lowerTerm as is
- startTerms.add(lowerTerm);
- }
- else
- {
- // first enumerate terms using lower case start character
- StringBuffer termText = new StringBuffer(propNameLength + 1);
- termText.append(lowerTerm.text().subSequence(0, propNameLength));
- char startCharacter = lowerTerm.text().charAt(propNameLength);
- termText.append(Character.toLowerCase(startCharacter));
- startTerms.add(new Term(lowerTerm.field(), termText.toString()));
- // second enumerate terms using upper case start character
- termText.setCharAt(termText.length() - 1, Character.toUpperCase(startCharacter));
- startTerms.add(new Term(lowerTerm.field(), termText.toString()));
- }
+ Iterator it = startTerms.iterator();
+ while (it.hasNext()) {
+ Term startTerm = (Term) it.next();
- Iterator it = startTerms.iterator();
- while (it.hasNext())
- {
- Term startTerm = (Term)it.next();
+ TermEnum terms = reader.terms(startTerm);
+ try {
+ TermDocs docs = reader.termDocs();
+ try {
+ do {
+ Term term = terms.term();
+ if (term != null
+ && term.field() == testField
+ && term.text().startsWith(namePrefix)) {
+ if (checkLower) {
+ int compare = termCompare(term.text(), lowerTerm.text(), propNameLength);
+ if (compare > 0 || compare == 0 && inclusive) {
+ // do not check lower term anymore if no
+ // transformation is done on the term enum
+ checkLower = transform == TRANSFORM_NONE ? false : true;
+ } else {
+ // continue with next term
+ continue;
+ }
+ }
+ if (upperTerm != null) {
+ int compare = termCompare(term.text(), upperTerm.text(), propNameLength);
+ // if beyond the upper term, or is exclusive and
+ // this is equal to the upper term
+ if ((compare > 0) || (!inclusive && compare == 0)) {
+ // only break out if no transformation
+ // was done on the term from the enum
+ if (transform == TRANSFORM_NONE) {
+ break;
+ } else {
+ // because of the transformation
+ // it is possible that the next
+ // term will be included again if
+ // we still enumerate on the same
+ // property name
+ if (term.text().startsWith(namePrefix)) {
+ continue;
+ } else {
+ break;
+ }
+ }
+ }
+ }
- TermEnum terms = reader.terms(startTerm);
- try
- {
- TermDocs docs = reader.termDocs();
- try
- {
- do
- {
- Term term = terms.term();
- if (term != null && term.field() == testField && term.text().startsWith(namePrefix))
- {
- if (checkLower)
- {
- int compare = termCompare(term.text(), lowerTerm.text(), propNameLength);
- if (compare > 0 || compare == 0 && inclusive)
- {
- // do not check lower term anymore if no
- // transformation is done on the term enum
- checkLower = transform == TRANSFORM_NONE ? false : true;
- }
- else
- {
- // continue with next term
- continue;
- }
- }
- if (upperTerm != null)
- {
- int compare = termCompare(term.text(), upperTerm.text(), propNameLength);
- // if beyond the upper term, or is exclusive and
- // this is equal to the upper term
- if ((compare > 0) || (!inclusive && compare == 0))
- {
- // only break out if no transformation
- // was done on the term from the enum
- if (transform == TRANSFORM_NONE)
- {
- break;
- }
- else
- {
- // because of the transformation
- // it is possible that the next
- // term will be included again if
- // we still enumerate on the same
- // property name
- if (term.text().startsWith(namePrefix))
- {
- continue;
- }
- else
- {
- break;
- }
- }
- }
- }
-
- docs.seek(terms);
- while (docs.next())
- {
- hits.set(docs.doc());
- }
- }
- else
- {
- break;
- }
- }
- while (terms.next());
- }
- finally
- {
- docs.close();
- }
+ docs.seek(terms);
+ while (docs.next()) {
+ hits.set(docs.doc());
+ }
+ } else {
+ break;
+ }
+ } while(terms.next());
+ } finally {
+ docs.close();
+ }
+ } finally {
+ terms.close();
+ }
}
- finally
- {
- terms.close();
- }
- }
- hitsCalculated = true;
- // put to cache
- resultMap.put(cacheKey, hits);
- }
+ hitsCalculated = true;
+ // put to cache
+ resultMap.put(cacheKey, hits);
+ }
- /**
- * Compares the <code>text</code> with the <code>other</code> String. This
- * implementation behaves like {@link String#compareTo(Object)} but also
- * respects the {@link RangeQuery#transform} property.
- *
- * @param text the text to compare to <code>other</code>. The
- * transformation function is applied to this parameter before
- * it is compared to <code>other</code>.
- * @param other the other String.
- * @param offset start comparing the two strings at <code>offset</code>.
- * @return see {@link String#compareTo(Object)}. But also respects {@link
- * RangeQuery#transform}.
- */
- private int termCompare(String text, String other, int offset)
- {
- OffsetCharSequence seq1 = new OffsetCharSequence(offset, text, transform);
- OffsetCharSequence seq2 = new OffsetCharSequence(offset, other);
- return seq1.compareTo(seq2);
- }
- }
+ /**
+ * Compares the <code>text</code> with the <code>other</code> String. This
+ * implementation behaves like {@link String#compareTo(Object)} but also
+ * respects the {@link RangeQuery#transform} property.
+ *
+ * @param text the text to compare to <code>other</code>. The
+ * transformation function is applied to this parameter before
+ * it is compared to <code>other</code>.
+ * @param other the other String.
+ * @param offset start comparing the two strings at <code>offset</code>.
+ * @return see {@link String#compareTo(Object)}. But also respects {@link
+ * RangeQuery#transform}.
+ */
+ private int termCompare(String text, String other, int offset) {
+ OffsetCharSequence seq1 = new OffsetCharSequence(offset, text, transform);
+ OffsetCharSequence seq2 = new OffsetCharSequence(offset, other);
+ return seq1.compareTo(seq2);
+ }
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNode.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNode.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/ScoreNode.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -17,7 +17,6 @@
package org.exoplatform.services.jcr.impl.core.query.lucene;
import java.io.IOException;
-import java.io.Serializable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
@@ -27,122 +26,96 @@
* <code>ScoreNode</code> implements a simple container which holds a mapping
* of {@link NodeId} to a score value.
*/
-public final class ScoreNode implements Serializable
-{
+public final class ScoreNode {
- /**
- * The id of a node.
- */
- private String id;
+ /**
+ * The id of a node.
+ */
+ private final String id;
- /**
- * The score of the node.
- */
- private float score;
+ /**
+ * The score of the node.
+ */
+ private final float score;
- /**
- * The lucene document number for this score node. Set to <code>-1</code> if
- * unknown.
- */
- private int doc;
+ /**
+ * The lucene document number for this score node. Set to <code>-1</code> if
+ * unknown.
+ */
+ private final int doc;
- /**
- * For serialization
- */
- public ScoreNode()
- {
- }
+ /**
+ * Creates a new <code>ScoreNode</code>.
+ *
+ * @param id the node id.
+ * @param score the score value.
+ */
+ public ScoreNode(String id, float score) {
+ this(id, score, -1);
+ }
- /**
- * Creates a new <code>ScoreNode</code>.
- *
- * @param id the node id.
- * @param score the score value.
- */
- public ScoreNode(String id, float score)
- {
- this(id, score, -1);
- }
+ /**
+ * Creates a new <code>ScoreNode</code>.
+ *
+ * @param id the node id.
+ * @param score the score value.
+ * @param doc the document number.
+ */
+ public ScoreNode(String id, float score, int doc) {
+ this.id = id;
+ this.score = score;
+ this.doc = doc;
+ }
- /**
- * Creates a new <code>ScoreNode</code>.
- *
- * @param id the node id.
- * @param score the score value.
- * @param doc the document number.
- */
- public ScoreNode(String id, float score, int doc)
- {
- this.id = id;
- this.score = score;
- this.doc = doc;
- }
+ /**
+ * @return the node id for this <code>ScoreNode</code>.
+ */
+ public String getNodeId() {
+ return id;
+ }
- /**
- * @return the node id for this <code>ScoreNode</code>.
- */
- public String getNodeId()
- {
- return id;
- }
+ /**
+ * @return the score for this <code>ScoreNode</code>.
+ */
+ public float getScore() {
+ return score;
+ }
- /**
- * @return the score for this <code>ScoreNode</code>.
- */
- public float getScore()
- {
- return score;
- }
-
- /**
- * Returns the document number for this score node.
- *
- * @param reader the current index reader to look up the document if
- * needed.
- * @return the document number.
- * @throws IOException if an error occurs while reading from the index or
- * the node is not present in the index.
- */
- public int getDoc(IndexReader reader) throws IOException
- {
- if (doc == -1)
- {
- TermDocs docs = reader.termDocs(new Term(FieldNames.UUID, id.toString()));
- try
- {
- if (docs.next())
- {
- return docs.doc();
+ /**
+ * Returns the document number for this score node.
+ *
+ * @param reader the current index reader to look up the document if
+ * needed.
+ * @return the document number.
+ * @throws IOException if an error occurs while reading from the index or
+ * the node is not present in the index.
+ */
+ public int getDoc(IndexReader reader) throws IOException {
+ if (doc == -1) {
+ TermDocs docs = reader.termDocs(new Term(FieldNames.UUID, id.toString()));
+ try {
+ if (docs.next()) {
+ return docs.doc();
+ } else {
+ throw new IOException("Node with id " + id + " not found in index");
+ }
+ } finally {
+ docs.close();
}
- else
- {
- throw new IOException("Node with id " + id + " not found in index");
- }
- }
- finally
- {
- docs.close();
- }
- }
- else
- {
- return doc;
- }
- }
+ } else {
+ return doc;
+ }
+ }
- public String toString()
- {
- StringBuffer sb = new StringBuffer(id.toString());
- sb.append("(");
- if (doc != -1)
- {
- sb.append(doc);
- }
- else
- {
- sb.append("?");
- }
- sb.append(")");
- return sb.toString();
- }
+ public String toString() {
+ StringBuffer sb = new StringBuffer(id.toString());
+ sb.append("(");
+ if (doc != -1) {
+ sb.append(doc);
+ } else {
+ sb.append("?");
+ }
+ sb.append(")");
+ return sb.toString();
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -889,9 +889,7 @@
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
- QueryContextHolder contextHolder =
- new QueryContextHolder(session.getTransientNodesManager(), session.getLocationFactory());
- JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader, getContext().getItemStateManager());
+ JcrIndexSearcher searcher = new JcrIndexSearcher(session, reader, getContext().getItemStateManager());
searcher.setSimilarity(getSimilarity());
return new FilterMultiColumnQueryHits(searcher.execute(query, sort, resultFetchHint,
QueryImpl.DEFAULT_SELECTOR_NAME))
@@ -940,9 +938,7 @@
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
final IndexReader reader = getIndexReader();
- QueryContextHolder contextHolder =
- new QueryContextHolder(session.getTransientNodesManager(), null, session.getLocationFactory(), nsMappings);
- JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader, getContext().getItemStateManager());
+ JcrIndexSearcher searcher = new JcrIndexSearcher(session, reader, getContext().getItemStateManager());
searcher.setSimilarity(getSimilarity());
return new FilterMultiColumnQueryHits(query.execute(searcher, sort, resultFetchHint))
{
@@ -2649,7 +2645,7 @@
* @throws IOException
* if this <code>SearchIndex</code> had been closed.
*/
- protected void checkOpen() throws IOException
+ private void checkOpen() throws IOException
{
if (closed)
{
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SimilarityQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SimilarityQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SimilarityQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -29,70 +29,52 @@
* <code>SimilarityQuery</code> implements a query that returns similar nodes
* for a given node UUID.
*/
-public class SimilarityQuery extends AbstractLuceneQuery
-{
+public class SimilarityQuery extends Query {
- /**
- * The UUID of the node for which to find similar nodes.
- */
- private String uuid;
+ /**
+ * The UUID of the node for which to find similar nodes.
+ */
+ private final String uuid;
- /**
- * for serialization
- */
- public SimilarityQuery()
- {
- // TODO Auto-generated constructor stub
- }
+ /**
+ * The analyzer in use.
+ */
+ private final Analyzer analyzer;
- public SimilarityQuery(String uuid, Analyzer analyzer)
- {
- super(analyzer);
- this.uuid = uuid;
- }
+ public SimilarityQuery(String uuid, Analyzer analyzer) {
+ this.uuid = uuid;
+ this.analyzer = analyzer;
+ }
- /**
- * {@inheritDoc}
- */
- public Query rewrite(IndexReader reader) throws IOException
- {
- if (reader instanceof JcrIndexReader)
- {
- this.setContextHolder(((JcrIndexReader)reader).getContextHolder());
- }
- MoreLikeThis more = new MoreLikeThis(reader);
- more.setAnalyzer(getAnalyzer());
- more.setFieldNames(new String[]{FieldNames.FULLTEXT});
- more.setMinWordLen(4);
- Query similarityQuery = null;
- TermDocs td = reader.termDocs(new Term(FieldNames.UUID, uuid));
- try
- {
- if (td.next())
- {
- similarityQuery = more.like(td.doc());
- }
- }
- finally
- {
- td.close();
- }
- if (similarityQuery != null)
- {
- return similarityQuery.rewrite(reader);
- }
- else
- {
- // return dummy query that never matches
- return new BooleanQuery();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query rewrite(IndexReader reader) throws IOException {
+ MoreLikeThis more = new MoreLikeThis(reader);
+ more.setAnalyzer(analyzer);
+ more.setFieldNames(new String[]{FieldNames.FULLTEXT});
+ more.setMinWordLen(4);
+ Query similarityQuery = null;
+ TermDocs td = reader.termDocs(new Term(FieldNames.UUID, uuid));
+ try {
+ if (td.next()) {
+ similarityQuery = more.like(td.doc());
+ }
+ } finally {
+ td.close();
+ }
+ if (similarityQuery != null) {
+ return similarityQuery.rewrite(reader);
+ } else {
+ // return dummy query that never matches
+ return new BooleanQuery();
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field)
- {
- return "rep:similar(" + uuid + ")";
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field) {
+ return "rep:similar(" + uuid + ")";
+ }
}
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/WildcardQuery.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/WildcardQuery.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/WildcardQuery.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -59,23 +59,23 @@
/**
* Name of the field to search.
*/
- private String field;
+ private final String field;
/**
* Name of the property to search.
*/
- private String propName;
+ private final String propName;
/**
* The wildcard pattern.
*/
- private String pattern;
+ private final String pattern;
/**
* How property values are tranformed before they are matched using the
* provided pattern.
*/
- private int transform;
+ private int transform = TRANSFORM_NONE;
/**
* The standard multi term query to execute wildcard queries. This is only
@@ -84,13 +84,6 @@
private Query multiTermQuery;
/**
- * for serialization
- */
- public WildcardQuery()
- {
- }
-
- /**
* Creates a new <code>WildcardQuery</code>.
*
* @param field the name of the field to search.
@@ -138,7 +131,6 @@
*/
public Query rewrite(IndexReader reader) throws IOException
{
-
Query stdWildcardQuery = new MultiTermQuery(new Term(field, pattern))
{
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/constraint/EvaluationContext.java
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/constraint/EvaluationContext.java 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/constraint/EvaluationContext.java 2010-12-09 12:58:49 UTC (rev 3634)
@@ -46,6 +46,11 @@
public IndexReader getIndexReader();
/**
+ * @return the session that executes the query.
+ */
+ public SessionImpl getSession();
+
+ /**
* @return the shared item state manager of the current workspace.
*/
public ItemDataConsumer getItemStateManager();
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-12-09 12:58:49 UTC (rev 3634)
@@ -55,7 +55,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws" />
<property name="changesfilter-class"
@@ -119,7 +119,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws1" />
<property name="changesfilter-class"
@@ -193,7 +193,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws2" />
<property name="changesfilter-class"
@@ -281,7 +281,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws3" />
<property name="changesfilter-class"
@@ -374,7 +374,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws" />
<property name="changesfilter-class"
@@ -455,7 +455,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws1" />
<property name="changesfilter-class"
@@ -534,7 +534,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws2" />
<property name="changesfilter-class"
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-09 12:58:49 UTC (rev 3634)
@@ -185,34 +185,7 @@
</properties-param>
</init-params>
</component>
-
- <component>
- <key>org.exoplatform.services.rpc.RPCService</key>
- <type>org.exoplatform.services.rpc.impl.RPCServiceImpl</type>
- <init-params>
- <value-param>
- <name>jgroups-configuration</name>
- <value>classpath:/udp.xml</value>
- </value-param>
- <value-param>
- <name>jgroups-cluster-name</name>
- <value>RPCService-Cluster</value>
- </value-param>
- <value-param>
- <name>jgroups-default-timeout</name>
- <value>0</value>
- </value-param>
- <value-param>
- <name>allow-failover</name>
- <value>true</value>
- </value-param>
- <value-param>
- <name>retry-timeout</name>
- <value>20000</value>
- </value-param>
- </init-params>
- </component>
-
+
<component>
<type>org.exoplatform.services.organization.impl.mock.DummyOrganizationService</type>
</component>
Modified: jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
===================================================================
--- jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2010-12-09 12:09:50 UTC (rev 3633)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2010-12-09 12:58:49 UTC (rev 3634)
@@ -71,7 +71,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws" />
<!-- property name="changesfilter-class" value="org.exoplatform.services.jcr.impl.core.query.jbosscache.JbossCacheIndexChangesFilter" />
@@ -123,7 +123,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws1" />
<property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" />
@@ -178,7 +178,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws2" />
<property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" />
@@ -261,7 +261,7 @@
</properties>
</cache>
<query-handler
- class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1/ws3" />
<property name="synonymprovider-class"
@@ -336,7 +336,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws" />
<property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" />
@@ -398,7 +398,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws1" />
<property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" />
@@ -459,7 +459,7 @@
<property name="jbosscache-shareable" value="${jbosscache-shareable}" />
</properties>
</cache>
- <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
+ <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
<properties>
<property name="index-dir" value="target/temp/index/db1tck/ws2" />
<property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" />
More information about the exo-jcr-commits
mailing list