[exo-jcr-commits] exo-jcr SVN: r300 - in jcr/trunk/component/core: src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/spell and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Oct 19 09:36:48 EDT 2009
Author: sergiykarpenko
Date: 2009-10-19 09:36:47 -0400 (Mon, 19 Oct 2009)
New Revision: 300
Added:
jcr/trunk/component/core/known-issues.txt
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java
Modified:
jcr/trunk/component/core/pom.xml
jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/spell/SpellCheckerTest.java
Log:
EXOJCR-180: TestSimilarity.java added known-issues added
Added: jcr/trunk/component/core/known-issues.txt
===================================================================
--- jcr/trunk/component/core/known-issues.txt (rev 0)
+++ jcr/trunk/component/core/known-issues.txt 2009-10-19 13:36:47 UTC (rev 300)
@@ -0,0 +1,6 @@
+
+// https://jira.jboss.org/jira/browse/EXOJCR-193
+org.exoplatform.services.jcr.impl.core.query.TestSimilarity.java
+
+//https://jira.jboss.org/jira/browse/EXOJCR-192
+org.exoplatform.services.jcr.api.core.query.lucene.spell.SpellCheckerTest.java
\ No newline at end of file
Modified: jcr/trunk/component/core/pom.xml
===================================================================
--- jcr/trunk/component/core/pom.xml 2009-10-19 13:33:51 UTC (rev 299)
+++ jcr/trunk/component/core/pom.xml 2009-10-19 13:36:47 UTC (rev 300)
@@ -365,6 +365,8 @@
</includes>
<excludes>
<exclude>**/TestQueryUsecases.java</exclude>
+ <exclude>**/SpellCheckerTest.java</exclude>
+ <exclude>**/TestSimilarity.java</exclude>
<exclude>**/TestImport.java</exclude>
<exclude>**/TestRollbackBigFiles.java</exclude>
<exclude>**/TestErrorMultithreading.java</exclude>
@@ -600,7 +602,7 @@
<include>org/exoplatform/services/jcr/integration/PrepareTestRepository.java</include>
</includes>
</configuration>
- </execution
+ </execution
-->
<execution>
<id>execution4 - pause 10 sec</id>
Modified: jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/spell/SpellCheckerTest.java
===================================================================
--- jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/spell/SpellCheckerTest.java 2009-10-19 13:33:51 UTC (rev 299)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/api/core/query/lucene/spell/SpellCheckerTest.java 2009-10-19 13:36:47 UTC (rev 300)
@@ -17,7 +17,11 @@
package org.exoplatform.services.jcr.api.core.query.lucene.spell;
import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import java.util.Calendar;
+
+import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.query.Query;
@@ -31,49 +35,6 @@
public class SpellCheckerTest extends AbstractJCRTest
{
- // protected void setUp() throws Exception {
- // super.setUp();
- // if (repository == null) {
- // ClassLoader cl = getClass().getClassLoader();
- // // PropertyConfigurator.configure(cl.getResource("log4j.properties"));
- // // InputStream in = cl.getResourceAsStream("repository.xml");
- // // RepositoryConfig config;
- // // try {
- // // config = RepositoryConfig.create(in, "target/repo-home");
- // // } finally {
- // // in.close();
- // // }
- // // repository = new TransientRepository(config);
- // //session = repository.login(new SimpleCredentials("user",
- // "password".toCharArray()));
- // String text = "the quick brown fox jumps over the lazy dog";
- // session.getRootNode().setProperty("prop", text);
- // session.save();
- // // wait a couple of seconds, refresh interval in test config is 5 seconds
- // try {
- // Thread.sleep(5 * 1000);
- // // perform a dummy check
- // performCheck("quick", "quick");
- // // wait again because refresh is done asynchronous
- // Thread.sleep(1 * 1000);
- // } catch (InterruptedException e) {
- // // ignore
- // }
- // }
- // if (session == null) {
- // session = repository.login(new SimpleCredentials("user",
- // "password".toCharArray()));
- // }
- // }
- //
- // protected void tearDown() throws Exception {
- // if (session != null) {
- // session.logout();
- // }
- // session = null;
- // super.tearDown();
- // }
-
public void testSpellChecker() throws RepositoryException
{
String text = "the quick brown fox jumps over the lazy dog";
@@ -116,6 +77,34 @@
performCheck("quik OR (-foo bar)", "quick OR (-fox bar)");
}
+ public void testSpellCheckerComplexQuery2() throws RepositoryException
+ {
+
+ String text = "the quick brown fox jumps over the lazy dog";
+
+ Node doc = testRootNode.addNode("file", "nt:file");//.setProperty("prop", text);
+ NodeImpl cont = (NodeImpl)doc.addNode("jcr:content", "nt:resource");
+ cont.setProperty("jcr:mimeType", "text/plain");
+ cont.setProperty("jcr:lastModified", Calendar.getInstance());
+ cont.setProperty("jcr:data", text);
+
+ superuser.save();
+ // wait a couple of seconds, refresh interval in test config is 5 seconds
+ try
+ {
+ Thread.sleep(5 * 1000);
+ // perform a dummy check
+ performCheck("quick", "quick");
+ // wait again because refresh is done asynchronous
+ Thread.sleep(1 * 1000);
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+ performCheck("quik % # &&& AND (-foo bar)", "quick % # &&& AND (-fox bar)");
+ }
+
public void testSpellCheckerCorrectWords() throws RepositoryException
{
String text = "the quick brown fox jumps over the lazy dog";
@@ -137,6 +126,44 @@
performCheck("quick", "quick");
}
+ public void testSpellCheckerIncorrectWords() throws RepositoryException
+ {
+ String text = "the quick brown fox jumps over the lazy dog";
+ testRootNode.setProperty("prop", text);
+ superuser.save();
+ // wait a couple of seconds, refresh interval in test config is 5 seconds
+ try
+ {
+ Thread.sleep(5 * 1000);
+ // perform a dummy check
+ performCheck("quick", "quick");
+ // wait again because refresh is done asynchronous
+ Thread.sleep(1 * 1000);
+ }
+ catch (InterruptedException e)
+ {
+ // ignore
+ }
+
+ String statement = "gismeteo";
+ QueryManager qm = superuser.getWorkspace().getQueryManager();
+ Query query = qm.createQuery("/jcr:root[rep:spellcheck('" + statement + "')]/(rep:spellcheck())", Query.XPATH);
+ RowIterator rows = query.execute().getRows();
+ assertEquals("no results returned", 1, rows.getSize());
+ Row r = rows.nextRow();
+ Value v = r.getValue("rep:spellcheck()");
+ assertNull("must not return a suggestion", v);
+
+ query =
+ qm.createQuery("select rep:spellcheck() from nt:base where " + "jcr:path = '/' and spellcheck('" + statement
+ + "')", Query.SQL);
+ rows = query.execute().getRows();
+ assertEquals("no results returned", 1, rows.getSize());
+ r = rows.nextRow();
+ v = r.getValue("rep:spellcheck()");
+ assertNull("must not return a suggestion", v);
+ }
+
protected void performCheck(String statement, String expected) throws RepositoryException
{
QueryManager qm = superuser.getWorkspace().getQueryManager();
Added: 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 (rev 0)
+++ jcr/trunk/component/core/src/test/java/org/exoplatform/services/jcr/impl/core/query/TestSimilarity.java 2009-10-19 13:36:47 UTC (rev 300)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.impl.core.query;
+
+import org.exoplatform.services.jcr.api.core.query.AbstractIndexingTest;
+
+import java.util.Calendar;
+
+import javax.jcr.Node;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy at gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestSimilarity.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestSimilarity extends AbstractIndexingTest
+{
+
+ public void testFindSimilarNodes() throws Exception
+ {
+ // base node
+ Node file = testRootNode.addNode("baseFile", "nt:file");
+ Node resource = file.addNode("jcr:content", "nt:resource");
+ resource.setProperty("jcr:lastModified", Calendar.getInstance());
+ resource.setProperty("jcr:encoding", "UTF-8");
+ resource.setProperty("jcr:mimeType", "text/plain");
+ resource
+ .setProperty(
+ "jcr:data",
+ "Similarity is determined by looking up terms that are common to nodes. "
+ + "There are some conditions that must be met for a term to be considered. This is required to limit the number possibly relevant terms."
+ + "Only terms with at least 4 characters are considered."
+ + "Only terms that occur at least 2 times in the source node are considered."
+ + "Only terms that occur in at least 5 nodes are considered.");
+ session.save();
+
+ // target node
+ 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.");
+
+ 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");
+
+ 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");
+
+ session.save();
+
+ //Lets find similar
+
+ // 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});
+
+ //make XPath query
+
+ Query xq =
+ qman.createQuery("//element(*, nt:resource)[rep:similar(., '/jcr:root/baseFile/jcr:content')]", Query.XPATH);
+ QueryResult xres = xq.execute();
+ checkResult(xres, new Node[]{resource1, resource3});
+
+ }
+
+}
More information about the exo-jcr-commits
mailing list