[exo-jcr-commits] exo-jcr SVN: r360 - in jcr/trunk/component/core: src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Oct 23 09:29:47 EDT 2009
Author: sergiykarpenko
Date: 2009-10-23 09:29:46 -0400 (Fri, 23 Oct 2009)
New Revision: 360
Modified:
jcr/trunk/component/core/known-issues.txt
jcr/trunk/component/core/pom.xml
jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryBuilder.java
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java
Log:
EXOJCR-193: similarity NPE fixed. TestSimilarity updated
Modified: jcr/trunk/component/core/known-issues.txt
===================================================================
--- jcr/trunk/component/core/known-issues.txt 2009-10-23 10:55:09 UTC (rev 359)
+++ jcr/trunk/component/core/known-issues.txt 2009-10-23 13:29:46 UTC (rev 360)
@@ -1,3 +0,0 @@
-
-// https://jira.jboss.org/jira/browse/EXOJCR-193
-org.exoplatform.services.jcr.impl.core.query.TestSimilarity.java
Modified: jcr/trunk/component/core/pom.xml
===================================================================
--- jcr/trunk/component/core/pom.xml 2009-10-23 10:55:09 UTC (rev 359)
+++ jcr/trunk/component/core/pom.xml 2009-10-23 13:29:46 UTC (rev 360)
@@ -361,14 +361,13 @@
<exclude>org/exoplatform/services/jcr/**/impl/**/Base*.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationStream.java</exclude>
<exclude>org/exoplatform/services/jcr/**/impl/**/TestJCRSerializationVersionRestore.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/impl/**/TestSimilarity.java</exclude>
<exclude>org/exoplatform/services/jcr/**/api/TestAll.java</exclude>
<exclude>org/exoplatform/services/jcr/**/usecases/**/RemoveSameNameSiblingTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/usecases/**/TestQueryWithNumberAndSpace.java</exclude>
<exclude>org/exoplatform/services/jcr/**/usecases/BaseUsecasesTest.java</exclude>
<exclude>org/exoplatform/services/jcr/**/api/**/TestSameNameItems.java</exclude>
- <exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
-
+ <exclude>org/exoplatform/services/jcr/**/api/**/TestVersionRestore.java</exclude>
+
<exclude>org/exoplatform/services/jcr/**/impl/**/TestSessionDataManager.java</exclude>
</excludes>
</configuration>
Modified: jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryBuilder.java
===================================================================
--- jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryBuilder.java 2009-10-23 10:55:09 UTC (rev 359)
+++ jcr/trunk/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/LuceneQueryBuilder.java 2009-10-23 13:29:46 UTC (rev 360)
@@ -775,18 +775,27 @@
}, null);
QPath relPath = node.getRelativePath();
+
+ InternalQName propName;
+
if (node.getOperation() == QueryConstants.OPERATION_SIMILAR)
{
// this is a bit ugly:
// add the name of a dummy property because relPath actually
// references a property. whereas the relPath of the similar
// operation references a node
- relPath = QPath.makeChildPath(relPath, Constants.JCR_PRIMARYTYPE);
+ //relPath = QPath.makeChildPath(relPath, Constants.JCR_PRIMARYTYPE);
+ propName = Constants.JCR_PRIMARYTYPE;
}
+ else
+ {
+ propName = relPath.getName();
+ }
+
String field = "";
try
{
- field = resolver.createJCRName(relPath.getName()).getAsString();
+ field = resolver.createJCRName(propName).getAsString();
}
catch (NamespaceException e)
{
@@ -795,7 +804,7 @@
}
// support for fn:name()
- InternalQName propName = relPath.getName();
+ //InternalQName propName = relPath.getName();
if (propName.getNamespace().equals(NS_FN_URI) && propName.getName().equals("name()"))
{
if (node.getValueType() != QueryConstants.TYPE_STRING)
@@ -1053,7 +1062,7 @@
}
}
- if (relPath.getEntries().length > 1)
+ if (relPath != null && relPath.getEntries().length > 1)
{
// child axis in relation
QPathEntry[] elements = relPath.getEntries();
Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java 2009-10-23 10:55:09 UTC (rev 359)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java 2009-10-23 13:29:46 UTC (rev 360)
@@ -21,6 +21,7 @@
import java.util.Calendar;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
@@ -38,7 +39,7 @@
public void testFindSimilarNodes() throws Exception
{
- // base node
+ //base node
Node file = testRootNode.addNode("baseFile", "nt:file");
Node resource = file.addNode("jcr:content", "nt:resource");
resource.setProperty("jcr:lastModified", Calendar.getInstance());
@@ -54,47 +55,55 @@
+ "Only terms that occur in at least 5 nodes are considered.");
session.save();
- // target node
+ // target nodes
Node target1 = testRootNode.addNode("target1", "nt:file");
Node resource1 = target1.addNode("jcr:content", "nt:resource");
resource1.setProperty("jcr:lastModified", Calendar.getInstance());
resource1.setProperty("jcr:encoding", "UTF-8");
resource1.setProperty("jcr:mimeType", "text/plain");
- resource1.setProperty("jcr:data", "There is term word.");
+ resource1.setProperty("jcr:data", "Similarity is determined by looking up terms that are common to nodes.");
Node target2 = testRootNode.addNode("target2", "nt:file");
Node resource2 = target2.addNode("jcr:content", "nt:resource");
resource2.setProperty("jcr:lastModified", Calendar.getInstance());
resource2.setProperty("jcr:encoding", "UTF-8");
resource2.setProperty("jcr:mimeType", "text/plain");
- resource2.setProperty("jcr:data", "You know what is not here");
+ resource2.setProperty("jcr:data", "There is no you know what");
Node target3 = testRootNode.addNode("target3", "nt:file");
Node resource3 = target3.addNode("jcr:content", "nt:resource");
resource3.setProperty("jcr:lastModified", Calendar.getInstance());
resource3.setProperty("jcr:encoding", "UTF-8");
resource3.setProperty("jcr:mimeType", "text/plain");
- resource3.setProperty("jcr:data", "Term occures here");
+ resource3.setProperty("jcr:data", "Terms occures here terms");
session.save();
- //Lets find similar
+ //Lets find similar nodes - will return base and similar target nodes
// make SQL query
QueryManager qman = session.getWorkspace().getQueryManager();
- // Query q =
- // qman.createQuery("select * from nt:resource where similar(., '/jcr:root/baseFile/jcr:content')", Query.SQL);
- // QueryResult result = q.execute();
- // checkResult(result, new Node[]{resource1, resource3});
+ Query q =
+ qman.createQuery("select * from nt:resource where similar(.,'/testroot/baseFile/jcr:content')", Query.SQL);
+ QueryResult result = q.execute();
+ assertEquals(3, result.getNodes().getSize());
+ checkResult(result, new Node[]{resource, resource1, resource3});
//make XPath query
Query xq =
- qman.createQuery("//element(*, nt:resource)[rep:similar(., '/jcr:root/baseFile/jcr:content')]", Query.XPATH);
+ qman.createQuery("//element(*, nt:resource)[rep:similar(., '/testroot/baseFile/jcr:content')]", Query.XPATH);
QueryResult xres = xq.execute();
- checkResult(xres, new Node[]{resource1, resource3});
+ assertEquals(3, xres.getNodes().getSize());
+ checkResult(xres, new Node[]{resource, resource1, resource3});
}
+ public void testSimilar() throws RepositoryException
+ {
+ executeQuery("//*[rep:similar(., '" + testRootNode.getPath() + "')]");
+ executeQuery("//*[rep:similar(node, '" + testRootNode.getPath() + "')]");
+ }
+
}
More information about the exo-jcr-commits
mailing list