Author: nzamosenchuk
Date: 2010-12-09 03:57:47 -0500 (Thu, 09 Dec 2010)
New Revision: 3629
Added:
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/test-configuration.xml
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml
Log:
EXOJCR-1080 : First "quick and dirty" POC implementation. TCK in standalone
passed. But it has serious problems with serialization-deserialization flow between
separate JVM's. Debugging is near to impossible.
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 08:54:46 UTC (rev
3628)
+++ jcr/branches/1.14-IMPR/exo.jcr.component.core/pom.xml 2010-12-09 08:57:47 UTC (rev
3629)
@@ -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,6 +433,7 @@
<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>
@@ -580,7 +581,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>
@@ -657,7 +658,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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/InternalQName.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -20,6 +20,8 @@
import org.exoplatform.commons.utils.QName;
+import java.io.Serializable;
+
/**
* Created by The eXo Platform SAS.
*
@@ -27,10 +29,18 @@
* @version $Id: InternalQName.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class InternalQName extends QName
+public class InternalQName extends QName implements Serializable
{
/**
+ * for serialization
+ */
+ public InternalQName()
+ {
+ super();
+ }
+
+ /**
* InternalQName constructor.
*
* @param namespace
@@ -62,11 +72,15 @@
{
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);
@@ -79,10 +93,14 @@
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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPath.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -22,6 +22,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -35,7 +36,7 @@
* @version $Id: QPath.java 11907 2008-03-13 15:36:21Z ksm $
*/
-public class QPath implements Comparable<QPath>
+public class QPath implements Comparable<QPath>, Serializable
{
/**
* Logger.
@@ -45,17 +46,17 @@
/**
* QPath prefix delimiter.
*/
- public static final String PREFIX_DELIMITER = ":";
+ public final static String PREFIX_DELIMITER = ":";
/**
* Names storage.
*/
- private final QPathEntry[] names;
+ private QPathEntry[] names;
/**
* Path hash code.
*/
- private final int hashCode;
+ private int hashCode;
/**
* String representation of the path.
@@ -63,6 +64,13 @@
private String stringName;
/**
+ * For serialization
+ */
+ public QPath()
+ {
+ }
+
+ /**
* QPath constructor.
*
* @param names
@@ -89,9 +97,13 @@
public boolean isAbsolute()
{
if (names[0].getIndex() == 1 && names[0].getName().length() == 0 &&
names[0].getNamespace().length() == 0)
+ {
return true;
+ }
else
+ {
return false;
+ }
}
/**
@@ -137,8 +149,10 @@
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);
@@ -171,12 +185,16 @@
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;
}
@@ -194,13 +212,17 @@
// 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;
}
@@ -299,10 +321,14 @@
public boolean equals(Object o)
{
if (o == this)
+ {
return true;
+ }
if (!(o instanceof QPath))
+ {
return false;
+ }
return hashCode == o.hashCode();
}
@@ -313,7 +339,9 @@
public int compareTo(QPath compare)
{
if (compare.equals(this))
+ {
return 0;
+ }
QPathEntry[] e1 = names;
QPathEntry[] e2 = compare.getEntries();
@@ -358,10 +386,14 @@
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>();
@@ -380,7 +412,9 @@
uriStart = -1;
}
else
+ {
uriStart = tmp;
+ }
String localName = qPath.substring(uriFinish + 1, tmp);
int index = 0;
@@ -393,8 +427,10 @@
else
{
if (uriStart > -1)
+ {
throw new IllegalPathException("Bad internal path '" +
qPath
+ "' each intermediate name should have index");
+ }
}
entries.add(new QPathEntry(uri, localName, index));
@@ -486,10 +522,14 @@
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;
@@ -518,7 +558,9 @@
final QPathEntry[] names = new QPathEntry[parentEntries.length + 1];
int index = 0;
for (QPathEntry name : parentEntries)
+ {
names[index++] = name;
+ }
names[index] = relEntry;
@@ -537,11 +579,15 @@
{
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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/datamodel/QPathEntry.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -30,13 +30,21 @@
/**
* QPath index.
*/
- private final int index;
+ private int index;
private String cachedToString;
private String cachedToStringShowIndex;
/**
+ * For serialization
+ */
+ public QPathEntry()
+ {
+ super();
+ }
+
+ /**
* QPathEntry constructor.
*
* @param qName
@@ -111,7 +119,9 @@
public boolean isSame(QPathEntry obj)
{
if (super.equals(obj))
+ {
return index == obj.getIndex();
+ }
return false;
}
@@ -180,13 +190,17 @@
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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionFactory.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -121,7 +121,7 @@
* @return XASessionImpl if TransactionService present or SessionImpl otherwise
* @throws RepositoryException
*/
- SessionImpl createSession(ConversationState user) throws RepositoryException,
LoginException
+ public 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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SearchManager.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -27,6 +27,7 @@
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;
@@ -39,9 +40,11 @@
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;
@@ -54,6 +57,7 @@
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;
@@ -72,6 +76,7 @@
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;
@@ -140,7 +145,11 @@
* The unique name of the related workspace
*/
protected final String wsId;
-
+
+ protected SessionFactory sessionFactory;
+
+ protected final RPCService rpcService;
+
/**
* Creates a new <code>SearchManager</code>.
*
@@ -165,9 +174,10 @@
* @throws RepositoryConfigurationException
*/
- public SearchManager(WorkspaceEntry wsConfig, QueryHandlerEntry config,
NamespaceRegistryImpl nsReg, NodeTypeDataManager ntReg,
- WorkspacePersistentDataManager itemMgr, SystemSearchManagerHolder
parentSearchManager,
- DocumentReaderService extractor, ConfigurationManager cfm, final
RepositoryIndexSearcherHolder indexSearcherHolder)
+ 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)
throws RepositoryException, RepositoryConfigurationException
{
this.wsId = wsConfig.getUniqueName();
@@ -180,6 +190,9 @@
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);
@@ -277,7 +290,9 @@
try
{
if (reader != null)
+ {
reader.close();
+ }
}
catch (IOException e)
{
@@ -390,7 +405,9 @@
{
if (log.isDebugEnabled())
+ {
log.debug("start");
+ }
try
{
if (indexingTree == null)
@@ -412,7 +429,9 @@
{
ItemData excludeData =
itemMgr.getItemData(stringTokenizer.nextToken());
if (excludeData != null)
+ {
excludedPath.add(excludeData.getQPath());
+ }
}
catch (RepositoryException e)
{
@@ -429,7 +448,9 @@
{
ItemData indexingRootDataItem =
itemMgr.getItemData(rootNodeIdentifer);
if (indexingRootDataItem != null &&
indexingRootDataItem.isNode())
+ {
indexingRootData = (NodeData)indexingRootDataItem;
+ }
}
catch (RepositoryException e)
{
@@ -510,14 +531,20 @@
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)
@@ -708,13 +735,21 @@
// 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());
- Constructor constuctor = qHandlerClass.getConstructor(QueryHandlerEntry.class,
ConfigurationManager.class);
- handler = (QueryHandler)constuctor.newInstance(config, cfm);
+ // (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);
+
QueryHandler parentHandler = (this.parentSearchManager != null) ?
parentSearchManager.getHandler() : null;
QueryHandlerContext context = createQueryHandlerContext(parentHandler);
handler.setContext(context);
@@ -724,34 +759,61 @@
changesFilter = initializeChangesFilter();
}
}
- catch (SecurityException e)
+ catch (Exception e)
{
- throw new RepositoryException(e.getMessage(), e);
+ log.error("Problem creating CRT Search Index");
+ log.error(e);
+ e.printStackTrace();
}
- catch (IllegalArgumentException e)
+
+ if (handler == null)
{
- throw new RepositoryException(e.getMessage(), 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);
+ }
}
- 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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/SystemSearchManager.java 2010-12-09
08:57:47 UTC (rev 3629)
@@ -25,10 +25,13 @@
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;
@@ -57,11 +60,13 @@
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) throws RepositoryException,
RepositoryConfigurationException
+ 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
{
- super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm,
indexSearcherHolder);
+ super(wsConfig, config, nsReg, ntReg, itemMgr, null, service, cfm,
indexSearcherHolder, sessionFactory,
+ rpcService);
}
@Override
Added:
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
(rev 0)
+++
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
08:57:47 UTC (rev 3629)
@@ -0,0 +1,125 @@
+/*
+ * 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@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();
+ }
+ }
+}
Property changes on:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/AbstractLuceneQuery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
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
08:57:47 UTC (rev 3629)
@@ -0,0 +1,484 @@
+/*
+ * 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@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;
+ }
+ }
+
+}
Property changes on:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/CRTSearchIndex.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -39,7 +39,7 @@
* Indicates whether terms from the index should be lower-cased or
* upper-cased.
*/
- protected final int transform;
+ protected 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -31,7 +31,6 @@
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;
@@ -54,7 +53,7 @@
* Implements a lucene <code>Query</code> which returns the child nodes of
the
* nodes selected by another <code>Query</code>.
*/
-class ChildAxisQuery extends Query implements JcrQuery
+class ChildAxisQuery extends AbstractLuceneQuery implements JcrQuery
{
/**
@@ -69,11 +68,6 @@
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;
@@ -82,33 +76,36 @@
* The nameTest to apply on the child axis, or <code>null</code> if all
* child nodes should be selected.
*/
- private final InternalQName nameTest;
+ private InternalQName nameTest;
/**
* The context position for the selected child node, or
* {@link LocationStepQueryNode#NONE} if no position is specified.
*/
- private final int position;
+ private int position;
/**
* The index format version.
*/
- private final IndexFormatVersion version;
+ private IndexFormatVersion version;
/**
- * The internal namespace mappings.
+ * The scorer of the context query
*/
- private final NamespaceMappings nsMappings;
+ private transient Scorer contextScorer;
/**
- * The scorer of the context query
+ * The scorer of the name test query
*/
- private Scorer contextScorer;
+ private transient Scorer nameTestScorer;
/**
- * The scorer of the name test query
+ * for serialization
*/
- private Scorer nameTestScorer;
+ public ChildAxisQuery()
+ {
+ super();
+ }
/**
* Creates a new <code>ChildAxisQuery</code> based on a
<code>context</code>
@@ -144,12 +141,11 @@
ChildAxisQuery(ItemDataConsumer itemMgr, Query context, InternalQName nameTest, int
position,
IndexFormatVersion version, NamespaceMappings nsMapping)
{
- this.itemMgr = itemMgr;
+ super(itemMgr, nsMapping);
this.contextQuery = context;
this.nameTest = nameTest;
this.position = position;
this.version = version;
- this.nsMappings = nsMapping;
}
/**
@@ -210,6 +206,11 @@
*/
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)
@@ -226,7 +227,7 @@
}
else
{
- sub = new NameQuery(nameTest, version, nsMappings);
+ sub = new NameQuery(nameTest, version, getNamespaceMappings());
}
return new DescendantSelfAxisQuery(dsaq.getContextQuery(), sub,
dsaq.getMinLevels() + 1).rewrite(reader);
}
@@ -240,7 +241,17 @@
}
else
{
- return new ChildAxisQuery(itemMgr, cQuery, nameTest, position, version,
nsMappings);
+ 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;
}
}
@@ -268,12 +279,12 @@
/**
* {@inheritDoc}
*/
- public QueryHits execute(JcrIndexSearcher searcher, SessionImpl session, Sort sort)
throws IOException
+ public QueryHits execute(JcrIndexSearcher searcher, QueryContextHolder contextHolder,
Sort sort) throws IOException
{
if (sort.getSort().length == 0 && matchesAnyChildNode())
{
Query context = getContextQuery();
- return new ChildNodesQueryHits(searcher.evaluate(context), session);
+ return new ChildNodesQueryHits(searcher.evaluate(context), contextHolder);
}
else
{
@@ -350,7 +361,7 @@
contextScorer = contextQuery.weight(searcher).scorer(reader);
if (nameTest != null)
{
- nameTestScorer = new NameQuery(nameTest, version,
nsMappings).weight(searcher).scorer(reader);
+ nameTestScorer = new NameQuery(nameTest, version,
getNamespaceMappings()).weight(searcher).scorer(reader);
}
return new ChildAxisScorer(searcher.getSimilarity(), reader,
(HierarchyResolver)reader);
}
@@ -525,7 +536,7 @@
try
{
//NodeState state = (NodeState) itemMgr.getItemState(parentId);
- NodeData state = (NodeData)itemMgr.getItemData(parentId);
+ NodeData state = (NodeData)getDataManager().getItemData(parentId);
if (nameTest == null)
{
// only select this node if it is the child at
@@ -533,7 +544,7 @@
if (position == LocationStepQueryNode.LAST)
{
// only select last
- List<NodeData> childNodes = itemMgr.getChildNodesData(state);
+ List<NodeData> childNodes =
getDataManager().getChildNodesData(state);
if (childNodes.size() == 0 || !childNodes.get(childNodes.size() -
1).getIdentifier().equals(id))
{
return false;
@@ -541,7 +552,7 @@
}
else
{
- List<NodeData> childNodes = itemMgr.getChildNodesData(state);
+ List<NodeData> childNodes =
getDataManager().getChildNodesData(state);
if (position < 1 || childNodes.size() < position
|| !childNodes.get(position - 1).getIdentifier().equals(id))
{
@@ -565,7 +576,7 @@
else
{
// only use the last one
- List<NodeData> childNodes =
itemMgr.getChildNodesData(state);
+ List<NodeData> childNodes =
getDataManager().getChildNodesData(state);
if (childNodes.size() == 0 || !childNodes.get(childNodes.size() -
1).getIdentifier().equals(id))
{
return false;
@@ -574,7 +585,7 @@
}
else
{
- NodeData nodeData = (NodeData)itemMgr.getItemData(id);
+ NodeData nodeData = (NodeData)getDataManager().getItemData(id);
if (nodeData == null)
{
// no such child node, probably has been deleted meanwhile
@@ -583,7 +594,9 @@
else
{
if (nodeData.getQPath().getIndex() != position)
+ {
return false;
+ }
}
}
}
@@ -651,7 +664,7 @@
/**
* The context hits.
*/
- private final Hits contextHits = new AdaptingHits();
+ private transient final Hits contextHits = new AdaptingHits();
/**
* Creates a new simple children calculator.
@@ -694,14 +707,14 @@
try
{
long time = System.currentTimeMillis();
- NodeData state = (NodeData)itemMgr.getItemData(uuid);
+ NodeData state = (NodeData)getDataManager().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 = itemMgr.getChildNodesData(state);
+ List<NodeData> childs =
getDataManager().getChildNodesData(state);
List<NodeData> datas = new ArrayList<NodeData>();
if (childs != null)
@@ -709,7 +722,9 @@
for (NodeData nodeData : childs)
{
if (nameTest.equals(nodeData.getQPath().getName()))
+ {
datas.add(nodeData);
+ }
}
}
@@ -718,7 +733,7 @@
else
{
// get all children
- entries = itemMgr.getChildNodesData(state).iterator();
+ entries = getDataManager().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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,94 +16,110 @@
*/
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 SessionImpl session;
+ /**
+ * This session that executes the query.
+ */
+ private final QueryContextHolder contextHolder;
- /**
- * 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, SessionImpl session)
- throws IOException {
- this.parents = parents;
- this.session = session;
- 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, QueryContextHolder contextHolder) throws
IOException
+ {
+ this.parents = parents;
+ this.contextHolder = contextHolder;
+ 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);
- childHits = new NodeTraversingQueryHits(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);
+ 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;
+ }
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -17,13 +17,14 @@
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.
Added:
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
(rev 0)
+++
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
08:57:47 UTC (rev 3629)
@@ -0,0 +1,100 @@
+/*
+ * 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@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;
+ }
+ }
+ }
+
+}
Property changes on:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/DefaultMultiColumnQueryHits.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -39,311 +39,366 @@
* Implements a lucene <code>Query</code> which returns the nodes selected
by
* a reference property of the context node.
*/
-class DerefQuery extends Query {
+class DerefQuery extends AbstractLuceneQuery
+{
- /**
- * The context query
- */
- private final Query contextQuery;
+ /**
+ * The context query
+ */
+ private Query contextQuery;
- /**
- * The name of the reference property.
- */
- private final String refProperty;
+ /**
+ * The name of the reference property.
+ */
+ private String refProperty;
- /**
- * The nameTest to apply on target node, or <code>null</code> if all
- * target nodes should be selected.
- */
- private final InternalQName nameTest;
+ /**
+ * The nameTest to apply on target node, or <code>null</code> if all
+ * target nodes should be selected.
+ */
+ private InternalQName nameTest;
- /**
- * The index format version.
- */
- private final IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private IndexFormatVersion version;
- /**
- * The internal namespace mappings.
- */
- private final NamespaceMappings nsMappings;
+ /**
+ * The scorer of the context query
+ */
+ private transient Scorer contextScorer;
- /**
- * The scorer of the context query
- */
- private Scorer contextScorer;
+ /**
+ * The scorer of the name test query
+ */
+ private transient Scorer nameTestScorer;
- /**
- * The scorer of the name test query
- */
- private Scorer nameTestScorer;
+ /**
+ * for serialization
+ */
+ public DerefQuery()
+ {
+ super();
+ }
- /**
- * 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 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 <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 {
- Query cQuery = contextQuery.rewrite(reader);
- if (cQuery == contextQuery) {
- return this;
- } else {
- return new DerefQuery(cQuery, refProperty, nameTest, version, nsMappings);
- }
- }
+ /**
+ * {@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;
+ }
+ }
- //-------------------< 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,
nsMappings).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,
getNamespaceMappings()).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();
- }
- }
- // 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);
- }
+ // 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);
+ }
+ }
+ }
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -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.impl.core.SessionDataManager;
-import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.dataflow.ItemDataConsumer;
+import org.exoplatform.services.jcr.datamodel.NodeData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +37,6 @@
import java.util.Set;
import java.util.TreeMap;
-import javax.jcr.Node;
import javax.jcr.RepositoryException;
/**
@@ -56,30 +55,38 @@
/**
* The context query
*/
- private final Query contextQuery;
+ private Query contextQuery;
/**
* The scorer of the context query
*/
- private Scorer contextScorer;
+ private transient Scorer contextScorer;
/**
* The sub query to filter
*/
- private final Query subQuery;
+ private Query subQuery;
/**
* The minimal levels required between context and sub nodes for a sub node
* to match.
*/
- private final int minLevels;
+ private int minLevels;
/**
* The scorer of the sub query to filter
*/
- private Scorer subScorer;
+ private transient 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
@@ -216,6 +223,17 @@
*/
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)
@@ -242,7 +260,7 @@
/**
* {@inheritDoc}
*/
- public QueryHits execute(final JcrIndexSearcher searcher, final SessionImpl session,
final Sort sort)
+ public QueryHits execute(final JcrIndexSearcher searcher, final QueryContextHolder
contextHolder, final Sort sort)
throws IOException
{
// Query tt =
((BooleanClause)((BooleanQuery)subQuery).clauses().get(0)).getQuery();
@@ -262,7 +280,7 @@
// intermediate ChildNodesQueryHits are required.
for (int i = 2; i <= getMinLevels(); i++)
{
- result = new ChildNodesQueryHits(result, session);
+ result = new ChildNodesQueryHits(result, contextHolder);
}
ScoreNode sn;
@@ -271,8 +289,10 @@
while ((sn = result.nextScoreNode()) != null)
{
//Node node = session.getNodeById(sn.getNodeId());
- Node node =
(Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
- startingPoints.put(node.getPath(), sn);
+ 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);
}
}
catch (RepositoryException e)
@@ -308,7 +328,7 @@
private NodeTraversingQueryHits currentTraversal;
- private SessionDataManager itemMgr = session.getTransientNodesManager();
+ private ItemDataConsumer itemMgr =
contextHolder.getDataManger();//session.getTransientNodesManager();
{
fetchNextTraversal();
@@ -352,8 +372,9 @@
try
{
//Node node = session.getNodeById(sn.getNodeId());
- Node node =
(Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
- currentTraversal = new NodeTraversingQueryHits(node, getMinLevels()
== 0);
+ NodeData data =
(NodeData)contextHolder.getDataManger().getItemData(sn.getNodeId());
+ //Node node =
(Node)session.getTransientNodesManager().getItemByIdentifier(sn.getNodeId(), true);
+ currentTraversal = new NodeTraversingQueryHits(contextHolder, data,
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -22,48 +22,62 @@
* <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 final QueryHits hits;
+ /**
+ * The underlying query hits.
+ */
+ private QueryHits 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;
- }
+ /**
+ * For serialization
+ */
+ public FilterQueryHits()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException {
- hits.close();
- }
+ /**
+ * 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 int getSize() {
- return hits.getSize();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException
+ {
+ hits.close();
+ }
- /**
- * {@inheritDoc}
- */
- public ScoreNode nextScoreNode() throws IOException {
- return hits.nextScoreNode();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int getSize()
+ {
+ return hits.getSize();
+ }
- /**
- * {@inheritDoc}
- */
- public void skip(int n) throws IOException {
- hits.skip(n);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException
+ {
+ return hits.nextScoreNode();
+ }
+
+ /**
+ * {@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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,6 +16,7 @@
*/
package org.exoplatform.services.jcr.impl.core.query.lucene;
+import java.io.Serializable;
import java.util.Collection;
import org.apache.lucene.index.IndexReader;
@@ -39,77 +40,94 @@
* 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 {
+public class IndexFormatVersion implements Serializable
+{
- /**
- * 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 final int version;
+ /**
+ * The used version of the index format
+ */
+ private int version;
- /**
- * Creates a index format version.
- *
- * @param version The version of the index.
+ /**
+ * for serialization
*/
- private IndexFormatVersion(int version) {
- this.version = version;
- }
+ public IndexFormatVersion()
+ {
+ }
- /**
- * Returns the index format version
- * @return the index format version.
- */
- public int getVersion() {
- return version;
- }
+ /**
+ * Creates a index format version.
+ *
+ * @param version The version of the index.
+ */
+ private IndexFormatVersion(int version)
+ {
+ this.version = 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 the index format version
+ * @return the index format version.
+ */
+ public int getVersion()
+ {
+ return version;
+ }
- /**
- * @return a string representation of this index format version.
- */
- public String toString() {
- return String.valueOf(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 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 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;
+ }
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -32,7 +32,22 @@
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -22,7 +22,6 @@
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;
@@ -39,7 +38,7 @@
/**
* The session that executes the query.
*/
- private final SessionImpl session;
+ private final QueryContextHolder contextHolder;
/**
* The underlying index reader.
@@ -58,11 +57,15 @@
* @param r the index reader.
* @param ism the shared item state manager.
*/
- public JcrIndexSearcher(SessionImpl s, IndexReader r, ItemDataConsumer ism)
+ public JcrIndexSearcher(QueryContextHolder contextHolder, IndexReader r,
ItemDataConsumer ism)
{
super(r);
- this.session = s;
+ this.contextHolder = contextHolder;
this.reader = r;
+ if (this.reader instanceof JcrIndexReader)
+ {
+ ((JcrIndexReader)this.reader).setContextHolder(contextHolder);
+ }
this.ism = ism;
}
@@ -98,10 +101,16 @@
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, session,
sort);
+ hits = ((JcrQuery)localQuery).execute(JcrIndexSearcher.this,
contextHolder, sort);
}
if (hits == null)
{
@@ -134,14 +143,6 @@
}
/**
- * @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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -48,7 +48,7 @@
* @throws IOException if an error occurs while executing the query.
*/
public QueryHits execute(JcrIndexSearcher searcher,
- SessionImpl session,
+ QueryContextHolder contextHolder,
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -31,76 +31,94 @@
* <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;
- public JcrTermQuery(Term t) {
- super(t);
- }
+ /**
+ * for serialization
+ */
+ public JcrTermQuery()
+ {
+ super(null);
+ }
- protected Weight createWeight(Searcher searcher) throws IOException {
- return new JackrabbitTermWeight(searcher, super.createWeight(searcher));
- }
+ public JcrTermQuery(Term t)
+ {
+ super(t);
+ }
- /**
- * The weight implementation.
- */
- protected class JackrabbitTermWeight extends AbstractWeight {
+ protected Weight createWeight(Searcher searcher) throws IOException
+ {
+ return new JackrabbitTermWeight(searcher, super.createWeight(searcher));
+ }
- private static final long serialVersionUID = -2070964510010945854L;
+ /**
+ * The weight implementation.
+ */
+ protected class JackrabbitTermWeight extends AbstractWeight
+ {
- /**
- * The default lucene TermQuery weight.
- */
- private final Weight weight;
+ private static final long serialVersionUID = -2070964510010945854L;
- public JackrabbitTermWeight(Searcher searcher, Weight weight) {
- super(searcher);
- this.weight = weight;
- }
+ /**
+ * The default lucene TermQuery weight.
+ */
+ private final Weight weight;
- /**
- * {@inheritDoc}
- */
- protected Scorer createScorer(IndexReader reader) throws IOException {
- return weight.scorer(reader);
- }
+ public JackrabbitTermWeight(Searcher searcher, Weight weight)
+ {
+ super(searcher);
+ this.weight = weight;
+ }
- /**
- * {@inheritDoc}
- */
- public Query getQuery() {
- return JcrTermQuery.this;
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Scorer createScorer(IndexReader reader) throws IOException
+ {
+ return weight.scorer(reader);
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue() {
- return weight.getValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query getQuery()
+ {
+ return JcrTermQuery.this;
+ }
- /**
- * {@inheritDoc}
- */
- public float sumOfSquaredWeights() throws IOException {
- return weight.sumOfSquaredWeights();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float getValue()
+ {
+ return weight.getValue();
+ }
- /**
- * {@inheritDoc}
- */
- public void normalize(float norm) {
- weight.normalize(norm);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float sumOfSquaredWeights() throws IOException
+ {
+ return weight.sumOfSquaredWeights();
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws
- IOException {
- return weight.explain(reader, doc);
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm)
+ {
+ weight.normalize(norm);
+ }
+
+ /**
+ * {@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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -26,51 +26,66 @@
/**
* <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 final String localName;
+ /**
+ * The local name of a node.
+ */
+ private String localName;
- /**
- * The index format version.
- */
- private final IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private IndexFormatVersion 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;
- }
+ /**
+ * for serialization
+ */
+ public LocalNameQuery()
+ {
+ }
- /**
- * {@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");
- }
- }
+ /**
+ * 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 void extractTerms(Set terms) {
- }
+ /**
+ * {@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 String toString(String field) {
- return "local-name() = " + localName;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms)
+ {
+ }
+
+ /**
+ * {@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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -22,51 +22,67 @@
* <code>LocalNameRangeQuery</code> implements a range query on the local
name
* of nodes.
*/
-public class LocalNameRangeQuery extends RangeQuery {
+public class LocalNameRangeQuery extends RangeQuery
+{
- /**
- * 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);
- }
+ /**
+ * for serialization
+ */
+ public LocalNameRangeQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * 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 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 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 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);
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -23,67 +23,79 @@
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 final IndexReader reader;
+ /**
+ * The IndexReader in use by the lucene hits.
+ */
+ private IndexReader reader;
- /**
- * The scorer for the query.
- */
- private final Scorer scorer;
+ /**
+ * The scorer for the query.
+ */
+ private Scorer scorer;
- public LuceneQueryHits(IndexReader reader,
- IndexSearcher searcher,
- Query query)
- throws IOException {
- this.reader = reader;
- this.scorer = query.weight(searcher).scorer(reader);
- }
+ /**
+ * For serialization
+ */
+ public LuceneQueryHits()
+ {
+ }
- /**
- * {@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);
- }
+ public LuceneQueryHits(IndexReader reader, IndexSearcher searcher, Query query) throws
IOException
+ {
+ this.reader = reader;
+ this.scorer = query.weight(searcher).scorer(reader);
+ }
- /**
- * {@inheritDoc}
- */
- public void close() throws IOException {
- // make sure scorer frees resources
- scorer.skipTo(Integer.MAX_VALUE);
- }
+ /**
+ * {@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);
+ }
- /**
- * @return always -1.
- */
- public int getSize() {
- return -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void close() throws IOException
+ {
+ // make sure scorer frees resources
+ scorer.skipTo(Integer.MAX_VALUE);
+ }
- /**
- * {@inheritDoc}
- */
- public void skip(int n) throws IOException {
- while (n-- > 0) {
- if (nextScoreNode() == null) {
- return;
- }
- }
- }
+ /**
+ * @return always -1.
+ */
+ public int getSize()
+ {
+ return -1;
+ }
+
+ /**
+ * {@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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,36 +16,42 @@
*/
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,
- 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;
- }
- }
+ /**
+ * {@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;
+ }
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -26,47 +26,60 @@
* 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 final String field;
+ private String field;
- /**
- * 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();
- }
+ /**
+ * for serialization
+ */
+ public MatchAllQuery()
+ {
+ }
- /**
- * 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);
- }
+ /**
+ * 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 String "%".
- *
- * @param field default field for the query.
- * @return the String "%".
- */
- public String toString(String field) {
- return "%";
- }
+ /**
+ * 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);
+ }
- /**
- * Does nothing but simply returns. There are no terms to extract.
- */
- public void extractTerms(Set terms) {
- }
+ /**
+ * 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)
+ {
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -17,6 +17,7 @@
package org.exoplatform.services.jcr.impl.core.query.lucene;
import java.io.IOException;
+import java.io.Serializable;
import org.apache.lucene.search.Sort;
@@ -24,7 +25,7 @@
* <code>MultiColumnQuery</code> defines an interface for a query that
returns
* {@link MultiColumnQueryHits}.
*/
-public interface MultiColumnQuery {
+public interface MultiColumnQuery extends Serializable {
/**
* Executes this query and returns multi column query hits.
Added:
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
(rev 0)
+++
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
08:57:47 UTC (rev 3629)
@@ -0,0 +1,45 @@
+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
Property changes on:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiColumnQueryHitsList.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,9 +16,6 @@
*/
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;
@@ -27,82 +24,99 @@
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 Query {
+public class NameQuery extends AbstractLuceneQuery
+{
- /**
- * The node name.
- */
- private final InternalQName nodeName;
+ /**
+ * The node name.
+ */
+ private InternalQName nodeName;
- /**
- * The index format version.
- */
- private final IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private IndexFormatVersion version;
- /**
- * The internal namespace mappings of the index.
- */
- private final NamespaceMappings nsMappings;
+ /**
+ * for serialization
+ */
+ public NameQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * 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;
- }
+ /**
+ * 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;
+ }
- /**
- * @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 (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 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 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,10 +16,6 @@
*/
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;
@@ -29,38 +25,45 @@
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 Query
+public class NameRangeQuery extends AbstractLuceneQuery
{
/**
* The lower name. May be <code>null</code> if
<code>upperName</code> is not
* <code>null</code>.
*/
- private final InternalQName lowerName;
+ private InternalQName lowerName;
/**
* The upper name. May be <code>null</code> if
<code>lowerName</code> is not
* <code>null</code>.
*/
- private final InternalQName upperName;
+ private InternalQName upperName;
/**
* If <code>true</code> the range interval is inclusive.
*/
- private final boolean inclusive;
+ private boolean inclusive;
/**
* The index format version.
*/
- private final IndexFormatVersion version;
+ private IndexFormatVersion version;
/**
- * The internal namespace mappings.
+ * for serialization
*/
- private final NamespaceMappings nsMappings;
+ public NameRangeQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
/**
* Creates a new NameRangeQuery. The lower or the upper name may be
@@ -75,6 +78,7 @@
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");
@@ -87,7 +91,6 @@
this.upperName = upperName;
this.inclusive = inclusive;
this.version = version;
- this.nsMappings = nsMappings;
}
/**
@@ -95,12 +98,15 @@
*/
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);
}
@@ -179,11 +185,11 @@
String text;
if (lowerName == null)
{
- text = nsMappings.getNamespacePrefixByURI(upperName.getNamespace()) +
":";
+ text =
getNamespaceMappings().getNamespacePrefixByURI(upperName.getNamespace()) + ":";
}
else
{
- text = nsMappings.translateName(lowerName);
+ text = getNamespaceMappings().translateName(lowerName);
}
return new Term(FieldNames.LABEL, text);
}
@@ -208,11 +214,11 @@
String text;
if (upperName == null)
{
- text = nsMappings.getNamespacePrefixByURI(lowerName.getNamespace()) +
":\uFFFF";
+ text =
getNamespaceMappings().getNamespacePrefixByURI(lowerName.getNamespace()) +
":\uFFFF";
}
else
{
- text = nsMappings.translateName(upperName);
+ text = getNamespaceMappings().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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,160 +16,189 @@
*/
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(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.
+ */
+ 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.
- * @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();
- }
- }
+ /**
+ * 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();
+ }
+ }
- /**
- * {@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;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public ScoreNode nextScoreNode() throws IOException
+ {
+ if (nodes.hasNext())
+ {
+ NodeData n = (NodeData)nodes.next();
+ return new ScoreNode(n.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 Node currentNode;
+ /**
+ * The current <code>Node</code>, which acts as the starting point for
+ * the traversal.
+ */
+ private final NodeData currentNode;
- /**
- * The maximum depth of the traversal.
- */
- private final int maxDepth;
+ private final QueryContextHolder contextHolder;
- /**
- * The chain of iterators which includes the iterators of the children
- * of the current node.
- */
- private Iterator selfAndChildren;
+ /**
+ * The maximum depth of the traversal.
+ */
+ private final int 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(Node start, int maxDepth) {
- if (maxDepth < 0) {
- throw new IllegalArgumentException("maxDepth must be >=
0");
- }
- currentNode = start;
- this.maxDepth = maxDepth;
- }
+ /**
+ * The chain of iterators which includes the iterators of the children
+ * of the current node.
+ */
+ private Iterator selfAndChildren;
- /**
- * @exception UnsupportedOperationException always.
- */
- public void remove() {
- throw new UnsupportedOperationException("remove");
- }
+ /**
+ * 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;
+ }
- /**
- * @inheritDoc
- */
- public boolean hasNext() {
- init();
- return selfAndChildren.hasNext();
- }
+ /**
+ * @exception UnsupportedOperationException always.
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException("remove");
+ }
- /**
- * @inheritDoc
- */
- public Object next() {
- init();
- NodeImpl n = (NodeImpl) selfAndChildren.next();
- return n;
- }
+ /**
+ * @inheritDoc
+ */
+ public boolean hasNext()
+ {
+ init();
+ return selfAndChildren.hasNext();
+ }
- /**
- * 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);
+ /**
+ * @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
}
- }
- }
+ 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -33,211 +33,260 @@
* 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 final Query context;
+ /**
+ * The context query to invert.
+ */
+ private Query context;
- /**
- * The context scorer to invert.
- */
- private Scorer contextScorer;
+ /**
+ * The context scorer to invert.
+ */
+ private transient Scorer contextScorer;
- /**
- * Creates a new <code>NotQuery</code>.
- * @param context the context query.
- */
- NotQuery(Query context) {
- this.context = context;
- }
+ /**
+ * for serialization
+ */
+ public NotQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * {@inheritDoc}
- */
- protected Weight createWeight(Searcher searcher) {
- return new NotQueryWeight(searcher);
- }
+ /**
+ * Creates a new <code>NotQuery</code>.
+ * @param context the context query.
+ */
+ NotQuery(Query context)
+ {
+ this.context = context;
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field) {
- return "NotQuery";
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Weight createWeight(Searcher searcher)
+ {
+ return new NotQueryWeight(searcher);
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms) {
- context.extractTerms(terms);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field)
+ {
+ return "NotQuery";
+ }
- /**
- * {@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 void extractTerms(Set terms)
+ {
+ context.extractTerms(terms);
+ }
- /**
- * Implements a weight for this <code>NotQuery</code>.
- */
- private class NotQueryWeight implements Weight {
+ /**
+ * {@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);
+ }
+ }
- /**
- * The searcher to access the index.
- */
- private final Searcher searcher;
+ /**
+ * Implements a weight for this <code>NotQuery</code>.
+ */
+ private class NotQueryWeight implements Weight
+ {
- /**
- * Creates a new NotQueryWeight with a searcher.
- * @param searcher the searcher.
- */
- NotQueryWeight(Searcher searcher) {
- this.searcher = searcher;
- }
+ /**
+ * The searcher to access the index.
+ */
+ private final Searcher searcher;
- /**
- * @inheritDoc
- */
- public Query getQuery() {
- return NotQuery.this;
- }
+ /**
+ * Creates a new NotQueryWeight with a searcher.
+ * @param searcher the searcher.
+ */
+ NotQueryWeight(Searcher searcher)
+ {
+ this.searcher = searcher;
+ }
- /**
- * @inheritDoc
- */
- public float getValue() {
- return 1.0f;
- }
+ /**
+ * @inheritDoc
+ */
+ public Query getQuery()
+ {
+ return NotQuery.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;
+ }
- /**
- * @inheritDoc
- */
- public Scorer scorer(IndexReader reader) throws IOException {
- contextScorer = context.weight(searcher).scorer(reader);
- return new NotQueryScorer(reader);
- }
+ /**
+ * @inheritDoc
+ */
+ public void normalize(float norm)
+ {
+ }
- /**
- * @throws UnsupportedOperationException always
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException {
- throw new UnsupportedOperationException();
- }
- }
+ /**
+ * @inheritDoc
+ */
+ public Scorer scorer(IndexReader reader) throws IOException
+ {
+ contextScorer = context.weight(searcher).scorer(reader);
+ return new NotQueryScorer(reader);
+ }
- /**
- * Implements a scorer that inverts the document matches of the context
- * scorer.
- */
- private class NotQueryScorer extends Scorer {
+ /**
+ * @throws UnsupportedOperationException always
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
- /**
- * The index reader.
- */
- private final IndexReader reader;
+ /**
+ * Implements a scorer that inverts the document matches of the context
+ * scorer.
+ */
+ private class NotQueryScorer extends Scorer
+ {
- /**
- * Current document number.
- */
- private int docNo = -1;
+ /**
+ * The index reader.
+ */
+ private final IndexReader reader;
- /**
- * Current document number of the context scorer;
- */
- private int contextNo = -1;
+ /**
+ * Current document number.
+ */
+ private int docNo = -1;
- /**
- * Creates a new scorer
- * @param reader
- */
- NotQueryScorer(IndexReader reader) {
- super(Similarity.getDefault());
- this.reader = reader;
- }
+ /**
+ * Current document number of the context scorer;
+ */
+ private int contextNo = -1;
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException {
- if (docNo == -1) {
- // get first doc of context scorer
- if (contextScorer.next()) {
- contextNo = contextScorer.doc();
- }
+ /**
+ * 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();
}
- // 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();
- } else {
- contextNo = -1;
- }
+ // check with contextScorer
+ while (contextNo != -1 && contextNo == docNo)
+ {
+ docNo++;
+ if (contextScorer.next())
+ {
+ contextNo = contextScorer.doc();
}
- return docNo < reader.maxDoc();
- }
+ else
+ {
+ contextNo = -1;
+ }
+ }
+ 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();
- } else {
- contextNo = -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException
+ {
+ if (contextNo != -1 && contextNo < target)
+ {
+ if (contextScorer.skipTo(target))
+ {
+ contextNo = contextScorer.doc();
}
- docNo = target - 1;
- return next();
- }
+ else
+ {
+ contextNo = -1;
+ }
+ }
+ 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,12 +16,6 @@
*/
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;
@@ -30,339 +24,392 @@
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 Query {
+class ParentAxisQuery extends AbstractLuceneQuery
+{
- /**
- * 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 final Query contextQuery;
+ /**
+ * The context query
+ */
+ private Query contextQuery;
- /**
- * The nameTest to apply on the parent axis, or <code>null</code> if any
- * parent node should be selected.
- */
- private final InternalQName nameTest;
+ /**
+ * The nameTest to apply on the parent axis, or <code>null</code> if any
+ * parent node should be selected.
+ */
+ private InternalQName nameTest;
- /**
- * The index format version.
- */
- private final IndexFormatVersion version;
+ /**
+ * The index format version.
+ */
+ private IndexFormatVersion version;
- /**
- * The internal namespace mappings.
- */
- private final NamespaceMappings nsMappings;
+ /**
+ * The scorer of the context query
+ */
+ private transient Scorer contextScorer;
- /**
- * The scorer of the context query
- */
- private Scorer contextScorer;
+ /**
+ * 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;
+ }
- /**
- * 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;
- }
+ /**
+ * 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 <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 void extractTerms(Set terms)
+ {
+ contextQuery.extractTerms(terms);
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms) {
- contextQuery.extractTerms(terms);
- }
+ /**
+ * {@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 Query rewrite(IndexReader reader) throws IOException {
- Query cQuery = contextQuery.rewrite(reader);
- if (cQuery == contextQuery) {
- return this;
- } else {
- return new ParentAxisQuery(cQuery, nameTest, version, nsMappings);
- }
- }
+ /**
+ * 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();
+ }
- /**
- * 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();
- }
+ //-----------------------< ParentAxisWeight >-------------------------------
- //-----------------------< ParentAxisWeight >-------------------------------
+ /**
+ * The <code>Weight</code> implementation for this
<code>ParentAxisQuery</code>.
+ */
+ private class ParentAxisWeight implements Weight
+ {
- /**
- * The <code>Weight</code> implementation for this
<code>ParentAxisQuery</code>.
- */
- private class ParentAxisWeight implements Weight {
+ /**
+ * The searcher in use
+ */
+ private final Searcher searcher;
- /**
- * The searcher in use
- */
- private final Searcher searcher;
+ /**
+ * 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;
+ }
- /**
- * 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;
- }
+ /**
+ * Returns this <code>ParentAxisQuery</code>.
+ *
+ * @return this <code>ParentAxisQuery</code>.
+ */
+ public Query getQuery()
+ {
+ return ParentAxisQuery.this;
+ }
- /**
- * Returns this <code>ParentAxisQuery</code>.
- *
- * @return this <code>ParentAxisQuery</code>.
- */
- public Query getQuery() {
- return ParentAxisQuery.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>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);
+ }
- /**
- * 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 Explanation explain(IndexReader reader, int doc) throws IOException
+ {
+ return new Explanation();
+ }
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException {
- return new Explanation();
- }
- }
+ //--------------------------< ParentAxisScorer >----------------------------
- //--------------------------< ParentAxisScorer >----------------------------
+ /**
+ * Implements a <code>Scorer</code> for this
<code>ParentAxisQuery</code>.
+ */
+ private class ParentAxisScorer extends Scorer
+ {
- /**
- * Implements a <code>Scorer</code> for this
<code>ParentAxisQuery</code>.
- */
- private class ParentAxisScorer 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;
+ /**
+ * The <code>HierarchyResolver</code> of the index.
+ */
+ private final HierarchyResolver hResolver;
- /**
- * The <code>HierarchyResolver</code> of the index.
- */
- private final HierarchyResolver hResolver;
+ /**
+ * The searcher instance.
+ */
+ private final Searcher searcher;
- /**
- * The searcher instance.
- */
- private final Searcher searcher;
+ /**
+ * BitSet storing the id's of selected documents
+ */
+ private BitSet hits;
- /**
- * BitSet storing the id's of selected documents
- */
- private BitSet hits;
+ /**
+ * 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();
- /**
- * 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();
+ /**
+ * The next document id to return
+ */
+ private int nextDoc = -1;
- /**
- * The next document id to return
- */
- private int 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;
+ }
- /**
- * 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 boolean next() throws IOException
+ {
+ calculateParent();
+ nextDoc = hits.nextSetBit(nextDoc + 1);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException {
- calculateParent();
- 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
+ {
+ Float score = (Float)scores.get(new Integer(nextDoc));
+ if (score == null)
+ {
+ score = DEFAULT_SCORE;
+ }
+ return score.floatValue();
+ }
- /**
- * {@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 boolean skipTo(int target) throws IOException
+ {
+ calculateParent();
+ nextDoc = hits.nextSetBit(target);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException {
- calculateParent();
- 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 calculateParent() throws IOException
+ {
+ if (hits == null)
+ {
+ hits = new BitSet(reader.maxDoc());
- private void calculateParent() throws IOException {
- if (hits == null) {
- hits = new BitSet(reader.maxDoc());
+ final IOException[] ex = new IOException[1];
+ contextScorer.score(new HitCollector()
+ {
- final IOException[] ex = new IOException[1];
- contextScorer.score(new HitCollector() {
+ private int[] docs = new int[1];
- 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;
+ 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;
+ }
+ }
+ });
- 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, 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;
- }
- }
- }
- }
+ // 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;
+ }
+ }
+ }
}
- }
- }
+ }
+ }
+ }
}
Added:
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
(rev 0)
+++
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
08:57:47 UTC (rev 3629)
@@ -0,0 +1,148 @@
+/*
+ * 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@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;
+ }
+
+}
Property changes on:
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/QueryContextHolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -16,13 +16,6 @@
*/
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;
@@ -33,227 +26,273 @@
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 final QueryHits hits;
+ /**
+ * The underlying query hits.
+ */
+ private QueryHits hits;
- /**
- * Creates a new query based on {@link QueryHits}.
- *
- * @param hits the query hits.
- */
- public QueryHitsQuery(QueryHits hits) {
- this.hits = hits;
- }
+ /**
+ * for serialization
+ */
+ public QueryHitsQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * {@inheritDoc}
- */
- protected Weight createWeight(Searcher searcher) throws IOException {
- return new QueryHitsQueryWeight(searcher.getSimilarity());
- }
+ /**
+ * Creates a new query based on {@link QueryHits}.
+ *
+ * @param hits the query hits.
+ */
+ public QueryHitsQuery(QueryHits hits)
+ {
+ this.hits = hits;
+ }
- /**
- * {@inheritDoc}
- */
- public String toString(String field) {
- return "QueryHitsQuery";
- }
+ /**
+ * {@inheritDoc}
+ */
+ protected Weight createWeight(Searcher searcher) throws IOException
+ {
+ return new QueryHitsQueryWeight(searcher.getSimilarity());
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms) {
- // no terms
- }
+ /**
+ * {@inheritDoc}
+ */
+ public String toString(String field)
+ {
+ return "QueryHitsQuery";
+ }
- //-----------------------< JackrabbitQuery >--------------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms)
+ {
+ // no terms
+ }
- /**
- * {@inheritDoc}
- */
- public QueryHits execute(JcrIndexSearcher searcher,
- SessionImpl session,
- Sort sort) throws IOException {
- if (sort.getSort().length == 0) {
- return hits;
- } else {
- return null;
- }
- }
+ //-----------------------< JackrabbitQuery >--------------------------------
- //------------------------< QueryHitsQueryWeight >--------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public QueryHits execute(JcrIndexSearcher searcher, QueryContextHolder contextHolder,
Sort sort) throws IOException
+ {
+ if (sort.getSort().length == 0)
+ {
+ return hits;
+ }
+ else
+ {
+ return null;
+ }
+ }
- /**
- * The Weight implementation for this query.
- */
- public class QueryHitsQueryWeight implements Weight {
+ //------------------------< QueryHitsQueryWeight >--------------------------
- /**
- * The similarity.
- */
- private final Similarity similarity;
+ /**
+ * The Weight implementation for this query.
+ */
+ public class QueryHitsQueryWeight implements Weight
+ {
- /**
- * Creates a new weight with the given <code>similarity</code>.
- *
- * @param similarity the similarity.
- */
- public QueryHitsQueryWeight(Similarity similarity) {
- this.similarity = similarity;
- }
+ /**
+ * The similarity.
+ */
+ private final Similarity similarity;
- /**
- * {@inheritDoc}
- */
- public Query getQuery() {
- return QueryHitsQuery.this;
- }
+ /**
+ * Creates a new weight with the given <code>similarity</code>.
+ *
+ * @param similarity the similarity.
+ */
+ public QueryHitsQueryWeight(Similarity similarity)
+ {
+ this.similarity = similarity;
+ }
- /**
- * {@inheritDoc}
- */
- public float getValue() {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Query getQuery()
+ {
+ return QueryHitsQuery.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;
+ }
- /**
- * {@inheritDoc}
- */
- public Scorer scorer(IndexReader reader) throws IOException {
- return new QueryHitsQueryScorer(reader, similarity);
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm)
+ {
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException {
- return new Explanation();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public Scorer scorer(IndexReader reader) throws IOException
+ {
+ return new QueryHitsQueryScorer(reader, similarity);
+ }
- //-------------------< QueryHitsQueryScorer >-------------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException
+ {
+ return new Explanation();
+ }
+ }
- /**
- * the scorer implementation for this query.
- */
- public class QueryHitsQueryScorer extends Scorer {
+ //-------------------< QueryHitsQueryScorer >-------------------------------
- /**
- * Iterator over <code>Integer</code> instances identifying the
- * lucene documents. Document numbers are iterated in ascending order.
- */
- private final Iterator docs;
+ /**
+ * the scorer implementation for this query.
+ */
+ public class QueryHitsQueryScorer extends Scorer
+ {
- /**
- * Maps <code>Integer</code> document numbers to
<code>Float</code>
- * scores.
- */
- private final Map scores = new HashMap();
+ /**
+ * Iterator over <code>Integer</code> instances identifying the
+ * lucene documents. Document numbers are iterated in ascending order.
+ */
+ private final Iterator docs;
- /**
- * The current document number.
- */
- private Integer currentDoc = null;
+ /**
+ * Maps <code>Integer</code> document numbers to
<code>Float</code>
+ * scores.
+ */
+ private final Map scores = new HashMap();
- /**
- * 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();
- }
+ /**
+ * The current document number.
+ */
+ private Integer currentDoc = null;
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException {
- if (docs.hasNext()) {
- currentDoc = (Integer) docs.next();
- return true;
+ /**
+ * 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();
+ }
}
- return false;
- }
+ }
+ finally
+ {
+ hits.close();
+ }
+ docs = sortedDocs.iterator();
+ }
- /**
- * {@inheritDoc}
- */
- public int doc() {
- return currentDoc.intValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException
+ {
+ if (docs.hasNext())
+ {
+ currentDoc = (Integer)docs.next();
+ return true;
+ }
+ return false;
+ }
- /**
- * {@inheritDoc}
- */
- public float score() throws IOException {
- return ((Float) scores.get(currentDoc)).floatValue();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc()
+ {
+ return currentDoc.intValue();
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException {
- do {
- if (!next()) {
- return false;
- }
- } while (target > doc());
- return true;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score() throws IOException
+ {
+ return ((Float)scores.get(currentDoc)).floatValue();
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(int doc) throws IOException {
- return new Explanation();
- }
- }
+ /**
+ * {@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();
+ }
+ }
}
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -40,449 +40,525 @@
/**
* 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 = TRANSFORM_NONE;
+ /**
+ * How the term enum is transformed before it is compared to lower and upper
+ * term.
+ */
+ private int transform;
- /**
- * 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);
- }
+ /**
+ * 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.
- * @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.
+ */
+ public RangeQuery(Term lowerTerm, Term upperTerm, boolean inclusive)
+ {
+ this(lowerTerm, upperTerm, inclusive, TRANSFORM_NONE);
+ }
- // if we have a lowerTerm, start there. otherwise, start at beginning
- if (lowerTerm != null) {
- this.lowerTerm = lowerTerm;
- } else {
- this.lowerTerm = new Term(upperTerm.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");
+ }
- this.upperTerm = upperTerm;
- this.inclusive = inclusive;
- this.transform = transform;
- }
+ // if we have a lowerTerm, start there. otherwise, start at beginning
+ if (lowerTerm != null)
+ {
+ this.lowerTerm = lowerTerm;
+ }
+ else
+ {
+ this.lowerTerm = new Term(upperTerm.field(), "");
+ }
- /**
- * {@inheritDoc}
- */
- public void setTransformation(int transformation) {
- this.transform = transformation;
- }
+ this.upperTerm = upperTerm;
+ this.inclusive = inclusive;
+ this.transform = transform;
+ }
- /**
- * 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;
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void setTransformation(int transformation)
+ {
+ this.transform = transformation;
+ }
- /**
- * 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);
- }
+ /**
+ * 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;
+ }
+ }
- /**
- * 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();
- }
+ /**
+ * 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);
+ }
- /**
- * {@inheritDoc}
- */
- public void extractTerms(Set terms) {
- // cannot extract terms
- }
+ /**
+ * 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 the field name for this query.
- */
- private String getField() {
- return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void extractTerms(Set terms)
+ {
+ // cannot extract terms
+ }
- //--------------------------< RangeQueryWeight >----------------------------
+ /**
+ * Returns the field name for this query.
+ */
+ private String getField()
+ {
+ return (lowerTerm != null ? lowerTerm.field() : upperTerm.field());
+ }
- /**
- * The <code>Weight</code> implementation for this
<code>RangeQuery</code>.
- */
- private class RangeQueryWeight extends AbstractWeight {
+ //--------------------------< RangeQueryWeight >----------------------------
- /**
- * Creates a new <code>RangeQueryWeight</code> instance using
- * <code>searcher</code>.
- *
- * @param searcher a <code>Searcher</code> instance.
- */
- RangeQueryWeight(Searcher searcher) {
- super(searcher);
- }
+ /**
+ * The <code>Weight</code> implementation for this
<code>RangeQuery</code>.
+ */
+ private class RangeQueryWeight extends AbstractWeight
+ {
- /**
- * 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 new <code>RangeQueryWeight</code> instance using
+ * <code>searcher</code>.
+ *
+ * @param searcher a <code>Searcher</code> instance.
+ */
+ RangeQueryWeight(Searcher searcher)
+ {
+ super(searcher);
+ }
- /**
- * Returns this <code>RangeQuery</code>.
- *
- * @return this <code>RangeQuery</code>.
- */
- public Query getQuery() {
- return RangeQuery.this;
- }
+ /**
+ * 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);
+ };
- /**
- * {@inheritDoc}
- */
- public float getValue() {
- return 1.0f;
- }
+ /**
+ * Returns this <code>RangeQuery</code>.
+ *
+ * @return this <code>RangeQuery</code>.
+ */
+ public Query getQuery()
+ {
+ return RangeQuery.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;
+ }
- /**
- * {@inheritDoc}
- */
- public Explanation explain(IndexReader reader, int doc) throws IOException {
- return new Explanation();
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ public void normalize(float norm)
+ {
+ }
- //------------------------< RangeQueryScorer >------------------------------
+ /**
+ * {@inheritDoc}
+ */
+ public Explanation explain(IndexReader reader, int doc) throws IOException
+ {
+ return new Explanation();
+ }
+ }
- /**
- * Implements a <code>Scorer</code> for this
<code>RangeQuery</code>.
- */
- private final class RangeQueryScorer extends Scorer {
+ //------------------------< RangeQueryScorer >------------------------------
- /**
- * The index reader to use for calculating the matching documents.
- */
- private final IndexReader reader;
+ /**
+ * Implements a <code>Scorer</code> for this
<code>RangeQuery</code>.
+ */
+ private final class RangeQueryScorer extends Scorer
+ {
- /**
- * The documents ids that match this range query.
- */
- private final BitSet hits;
+ /**
+ * The index reader to use for calculating the matching documents.
+ */
+ private final IndexReader reader;
- /**
- * Set to <code>true</code> when the hits have been calculated.
- */
- private boolean hitsCalculated = false;
+ /**
+ * The documents ids that match this range query.
+ */
+ private final BitSet hits;
- /**
- * The next document id to return
- */
- private int nextDoc = -1;
+ /**
+ * Set to <code>true</code> when the hits have been calculated.
+ */
+ private boolean hitsCalculated = false;
- /**
- * The cache key to use to store the results.
- */
- private final String cacheKey;
+ /**
+ * The next document id to return
+ */
+ private int nextDoc = -1;
- /**
- * The map to store the results.
- */
- private final Map resultMap;
+ /**
+ * The cache key to use to store the results.
+ */
+ private final String cacheKey;
- /**
- * 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;
+ /**
+ * The map to store the results.
+ */
+ private final Map resultMap;
- BitSet result = (BitSet) resultMap.get(cacheKey);
- if (result == null) {
- result = new BitSet(reader.maxDoc());
- } else {
- hitsCalculated = true;
- }
- hits = result;
- }
+ /**
+ * 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;
- /**
- * {@inheritDoc}
- */
- public boolean next() throws IOException {
- calculateHits();
- nextDoc = hits.nextSetBit(nextDoc + 1);
- return nextDoc > -1;
- }
+ BitSet result = (BitSet)resultMap.get(cacheKey);
+ if (result == null)
+ {
+ result = new BitSet(reader.maxDoc());
+ }
+ else
+ {
+ hitsCalculated = true;
+ }
+ hits = result;
+ }
- /**
- * {@inheritDoc}
- */
- public int doc() {
- return nextDoc;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws IOException
+ {
+ calculateHits();
+ nextDoc = hits.nextSetBit(nextDoc + 1);
+ return nextDoc > -1;
+ }
- /**
- * {@inheritDoc}
- */
- public float score() {
- return 1.0f;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public int doc()
+ {
+ return nextDoc;
+ }
- /**
- * {@inheritDoc}
- */
- public boolean skipTo(int target) throws IOException {
- calculateHits();
- nextDoc = hits.nextSetBit(target);
- return nextDoc > -1;
- }
+ /**
+ * {@inheritDoc}
+ */
+ public float score()
+ {
+ return 1.0f;
+ }
- /**
- * Returns an empty Explanation object.
- * @return an empty Explanation object.
- */
- public Explanation explain(int doc) {
- return new Explanation();
- }
+ /**
+ * {@inheritDoc}
+ */
+ public boolean skipTo(int target) throws IOException
+ {
+ calculateHits();
+ nextDoc = hits.nextSetBit(target);
+ return nextDoc > -1;
+ }
- /**
- * 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;
- }
+ /**
+ * Returns an empty Explanation object.
+ * @return an empty Explanation object.
+ */
+ public Explanation explain(int doc)
+ {
+ return new Explanation();
+ }
- String testField = getField();
+ /**
+ * 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;
+ }
- boolean checkLower = false;
- if (!inclusive || transform != TRANSFORM_NONE) {
- // make adjustments to set to exclusive
- checkLower = true;
- }
+ String testField = getField();
- int propNameLength = FieldNames.getNameLength(lowerTerm.text());
- String namePrefix = "";
- if (propNameLength > 0) {
- namePrefix = lowerTerm.text().substring(0, propNameLength);
- }
- List startTerms = new ArrayList(2);
+ boolean checkLower = false;
+ if (!inclusive || transform != TRANSFORM_NONE)
+ {
+ // make adjustments to set to exclusive
+ checkLower = true;
+ }
- 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()));
- }
+ int propNameLength = FieldNames.getNameLength(lowerTerm.text());
+ String namePrefix = "";
+ if (propNameLength > 0)
+ {
+ namePrefix = lowerTerm.text().substring(0, propNameLength);
+ }
+ List startTerms = new ArrayList(2);
- Iterator it = startTerms.iterator();
- while (it.hasNext()) {
- Term startTerm = (Term) it.next();
+ 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()));
+ }
- 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;
- }
- }
- }
- }
+ Iterator it = startTerms.iterator();
+ while (it.hasNext())
+ {
+ Term startTerm = (Term)it.next();
- docs.seek(terms);
- while (docs.next()) {
- hits.set(docs.doc());
- }
- } else {
- break;
- }
- } while(terms.next());
- } finally {
- docs.close();
- }
- } finally {
- terms.close();
- }
+ 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();
+ }
}
+ 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -17,6 +17,7 @@
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;
@@ -26,96 +27,122 @@
* <code>ScoreNode</code> implements a simple container which holds a
mapping
* of {@link NodeId} to a score value.
*/
-public final class ScoreNode {
+public final class ScoreNode implements Serializable
+{
- /**
- * The id of a node.
- */
- private final String id;
+ /**
+ * The id of a node.
+ */
+ private String id;
- /**
- * The score of the node.
- */
- private final float score;
+ /**
+ * The score of the node.
+ */
+ private float score;
- /**
- * The lucene document number for this score node. Set to <code>-1</code>
if
- * unknown.
- */
- private final int doc;
+ /**
+ * The lucene document number for this score node. Set to <code>-1</code>
if
+ * unknown.
+ */
+ private int doc;
- /**
- * 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);
- }
+ /**
+ * For serialization
+ */
+ public ScoreNode()
+ {
+ }
- /**
- * 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.
+ */
+ public ScoreNode(String id, float score)
+ {
+ this(id, score, -1);
+ }
- /**
- * @return the node id for this <code>ScoreNode</code>.
- */
- public String getNodeId() {
- return id;
- }
+ /**
+ * 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 score for this <code>ScoreNode</code>.
- */
- public float getScore() {
- return score;
- }
+ /**
+ * @return the node id for this <code>ScoreNode</code>.
+ */
+ public String getNodeId()
+ {
+ return id;
+ }
- /**
- * 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();
+ /**
+ * @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();
}
- } else {
- return doc;
- }
- }
+ else
+ {
+ throw new IOException("Node with id " + id + " not found in
index");
+ }
+ }
+ finally
+ {
+ docs.close();
+ }
+ }
+ 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -889,7 +889,9 @@
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
- JcrIndexSearcher searcher = new JcrIndexSearcher(session, reader,
getContext().getItemStateManager());
+ QueryContextHolder contextHolder =
+ new QueryContextHolder(session.getTransientNodesManager(),
session.getLocationFactory());
+ JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader,
getContext().getItemStateManager());
searcher.setSimilarity(getSimilarity());
return new FilterMultiColumnQueryHits(searcher.execute(query, sort,
resultFetchHint,
QueryImpl.DEFAULT_SELECTOR_NAME))
@@ -938,7 +940,9 @@
Sort sort = new Sort(createSortFields(orderProps, orderSpecs));
final IndexReader reader = getIndexReader();
- JcrIndexSearcher searcher = new JcrIndexSearcher(session, reader,
getContext().getItemStateManager());
+ QueryContextHolder contextHolder =
+ new QueryContextHolder(session.getTransientNodesManager(), null,
session.getLocationFactory(), nsMappings);
+ JcrIndexSearcher searcher = new JcrIndexSearcher(contextHolder, reader,
getContext().getItemStateManager());
searcher.setSimilarity(getSimilarity());
return new FilterMultiColumnQueryHits(query.execute(searcher, sort,
resultFetchHint))
{
@@ -2645,7 +2649,7 @@
* @throws IOException
* if this <code>SearchIndex</code> had been closed.
*/
- private void checkOpen() throws IOException
+ protected 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -29,52 +29,70 @@
* <code>SimilarityQuery</code> implements a query that returns similar
nodes
* for a given node UUID.
*/
-public class SimilarityQuery extends Query {
+public class SimilarityQuery extends AbstractLuceneQuery
+{
- /**
- * The UUID of the node for which to find similar nodes.
- */
- private final String uuid;
+ /**
+ * The UUID of the node for which to find similar nodes.
+ */
+ private String uuid;
- /**
- * The analyzer in use.
- */
- private final Analyzer analyzer;
+ /**
+ * for serialization
+ */
+ public SimilarityQuery()
+ {
+ // TODO Auto-generated constructor stub
+ }
- public SimilarityQuery(String uuid, Analyzer analyzer) {
- this.uuid = uuid;
- this.analyzer = analyzer;
- }
+ public SimilarityQuery(String uuid, Analyzer analyzer)
+ {
+ super(analyzer);
+ this.uuid = uuid;
+ }
- /**
- * {@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 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 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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -59,23 +59,23 @@
/**
* Name of the field to search.
*/
- private final String field;
+ private String field;
/**
* Name of the property to search.
*/
- private final String propName;
+ private String propName;
/**
* The wildcard pattern.
*/
- private final String pattern;
+ private String pattern;
/**
* How property values are tranformed before they are matched using the
* provided pattern.
*/
- private int transform = TRANSFORM_NONE;
+ private int transform;
/**
* The standard multi term query to execute wildcard queries. This is only
@@ -84,6 +84,13 @@
private Query multiTermQuery;
/**
+ * for serialization
+ */
+ public WildcardQuery()
+ {
+ }
+
+ /**
* Creates a new <code>WildcardQuery</code>.
*
* @param field the name of the field to search.
@@ -131,6 +138,7 @@
*/
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
08:54:46 UTC (rev 3628)
+++
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
08:57:47 UTC (rev 3629)
@@ -46,11 +46,6 @@
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/test-configuration.xml
===================================================================
---
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-09
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-configuration.xml 2010-12-09
08:57:47 UTC (rev 3629)
@@ -185,7 +185,34 @@
</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
08:54:46 UTC (rev 3628)
+++
jcr/branches/1.14-IMPR/exo.jcr.component.core/src/test/resources/conf/standalone/test-jcr-config.xml 2010-12-09
08:57:47 UTC (rev 3629)
@@ -71,7 +71,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"
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.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="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.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="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.SearchIndex">
+ class="org.exoplatform.services.jcr.impl.core.query.lucene.CRTSearchIndex">
<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.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="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.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="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.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="synonymprovider-class"
value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider"
/>