You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by md...@apache.org on 2012/04/12 19:59:23 UTC

svn commit: r1325411 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src: main/java/org/apache/chemistry/opencmis/jcr/query/ test/java/org/apache/chemistry/opencmis/jcr/query/

Author: mduerig
Date: Thu Apr 12 17:59:22 2012
New Revision: 1325411

URL: http://svn.apache.org/viewvc?rev=1325411&view=rev
Log:
CMIS-511: Full text search still is incomplete

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/Evaluator.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorBase.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorXPath.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/Evaluator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/Evaluator.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/Evaluator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/Evaluator.java Thu Apr 12 17:59:22 2012
@@ -116,4 +116,19 @@ public interface Evaluator<T> {
 
     /** Handle {@link org.apache.chemistry.opencmis.server.support.query.CmisQlStrictLexer#COL} nodes */
     T col(String name);
+
+    /** Handle {@link org.apache.chemistry.opencmis.server.support.query.TextSearchLexer#TEXT_AND} */
+    T textAnd(List<T> ops);
+
+    /** Handle {@link org.apache.chemistry.opencmis.server.support.query.TextSearchLexer#TEXT_OR} */
+    T textOr(List<T> ops);
+
+    /** Handle {@link org.apache.chemistry.opencmis.server.support.query.TextSearchLexer#TEXT_MINUS} */
+    T textMinus(String text);
+
+    /** Handle {@link org.apache.chemistry.opencmis.server.support.query.TextSearchLexer#TEXT_SEARCH_WORD_LIT} */
+    T textWord(String word);
+
+    /** Handle {@link org.apache.chemistry.opencmis.server.support.query.TextSearchLexer#TEXT_SEARCH_PHRASE_STRING_LIT} */
+    T textPhrase(String phrase);
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorBase.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorBase.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorBase.java Thu Apr 12 17:59:22 2012
@@ -145,4 +145,23 @@ public abstract class EvaluatorBase<T> i
         throw new CmisNotSupportedException("Not supported in query: column name " + name);
     }
 
+    public T textAnd(List<T> ops) {
+        throw new CmisNotSupportedException("Not supported in query: text and");
+    }
+
+    public T textOr(List<T> ops) {
+        throw new CmisNotSupportedException("Not supported in query: text or");
+    }
+
+    public T textMinus(String text) {
+        throw new CmisNotSupportedException("Not supported in query: text minus");
+    }
+
+    public T textWord(String word) {
+        throw new CmisNotSupportedException("Not supported in query: text word");
+    }
+
+    public T textPhrase(String phrase) {
+        throw new CmisNotSupportedException("Not supported in query: text phrase");
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorXPath.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorXPath.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorXPath.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/EvaluatorXPath.java Thu Apr 12 17:59:22 2012
@@ -206,7 +206,7 @@ public class EvaluatorXPath extends Eval
 
     @Override
     public XPathBuilder contains(XPathBuilder op1, XPathBuilder op2) {
-        return new FunctionBuilder("jcr:contains", ".", op2);
+        return new ContainsBuilder(op2);
     }
 
     @Override
@@ -254,6 +254,31 @@ public class EvaluatorXPath extends Eval
         return new ColRefBuilder(name);
     }
 
+    @Override
+    public XPathBuilder textAnd(List<XPathBuilder> ops) {
+        return new TextOpBuilder(ops, " ");
+    }
+
+    @Override
+    public XPathBuilder textOr(List<XPathBuilder> ops) {
+        return new TextOpBuilder(ops, " OR ");
+    }
+
+    @Override
+    public XPathBuilder textMinus(String text) {
+        return new TextMinusBuilder(text);
+    }
+
+    @Override
+    public XPathBuilder textWord(String word) {
+        return new TextWordBuilder(word);
+    }
+
+    @Override
+    public XPathBuilder textPhrase(String phrase) {
+        return new TextPhraseBuilder(phrase);
+    }
+
     //------------------------------------------< protected >---
 
     /**
@@ -416,44 +441,113 @@ public class EvaluatorXPath extends Eval
 
     private static class FunctionBuilder extends PrimitiveBuilder {
         private final String function;
-        private String op1Str;
         private final XPathBuilder op1;
         private final XPathBuilder op2;
 
-        private FunctionBuilder(String function, String op1Str, XPathBuilder op1, XPathBuilder op2) {
+        private FunctionBuilder(String function, XPathBuilder op1, XPathBuilder op2) {
             this.function = function;
-            this.op1Str = op1Str;
             this.op1 = op1;
             this.op2 = op2;
         }
 
-        public FunctionBuilder(String function, XPathBuilder op1, XPathBuilder op2) {
-            this(function, null, op1, op2);
+        public FunctionBuilder(String function, XPathBuilder op1) {
+            this(function, op1, null);
         }
 
-        public FunctionBuilder(String function, XPathBuilder op1) {
-            this(function, null, op1, null);
+        public FunctionBuilder(XPathBuilder op1) {
+            this(null, op1, null);
+        }
+
+        public String xPath() {
+            return function == null
+                ? op1.xPath()
+                : function + "(" + op1.xPath() + (op2 == null ? "" : ", " + op2.xPath()) + ")";
         }
+    }
 
-        public FunctionBuilder(String function, String op1, XPathBuilder op2) {
-            this(function, op1, null, op2);
+    private static class ContainsBuilder extends PrimitiveBuilder {
+        private final XPathBuilder op;
 
+        public ContainsBuilder(XPathBuilder op) {
+            this.op = op;
         }
 
-        public FunctionBuilder(XPathBuilder op1) {
-            this(null, op1, null);
+        public String xPath() {
+            return "jcr:contains(jcr:content, '" + op.xPath() + "')";
+        }
+    }
+
+    private static class TextOpBuilder extends PrimitiveBuilder {
+        private final List<XPathBuilder> ops;
+        private final String relOp;
+
+        public TextOpBuilder(List<XPathBuilder> ops, String relOp) {
+            this.ops = ops;   
+            this.relOp = relOp;
         }
 
         public String xPath() {
-            if (op1Str == null) {
-                op1Str = op1.xPath();
+            StringBuilder sb = new StringBuilder();
+            String sep = "";
+            for (XPathBuilder op: ops) {
+                sb.append(sep).append(op.xPath());
+                sep = relOp;
             }
 
-            return function == null
-                    ? op1Str
-                    : function + "(" + op1Str + (op2 == null ? "" : ", " + op2.xPath()) + ")";
+            return sb.toString();
+        }
+    }
+    
+    private static class TextMinusBuilder extends PrimitiveBuilder {
+        private final String text;
+
+        public TextMinusBuilder(String text) {
+            this.text = text;
+        }
+
+        public String xPath() {
+            return "-" + escape(text);
+        }
+    }
+    
+    private static class TextWordBuilder extends PrimitiveBuilder {
+        private final String word;
+
+        public TextWordBuilder(String word) {
+            this.word = word;
         }
 
+        public String xPath() {
+            return escape(word);
+        }
+    }
+
+    private static class TextPhraseBuilder extends PrimitiveBuilder {
+        private final String phrase;
+
+        public TextPhraseBuilder(String phrase) {
+            this.phrase = phrase;
+        }
+
+        public String xPath() {
+            return "\"" + escape(phrase.substring(1, phrase.length() - 1)) + "\"";
+        }
     }
 
+    /**
+     * Within the searchexp literal instances of single quote ('), double quote (")
+     * and hyphen (-) must be escaped with a backslash (\). Backslash itself must
+     * therefore also be escaped, ending up as double backslash (\\).
+     */
+    private static String escape(String s) {
+        if (s == null) {
+            return "";
+        }
+
+        s = s.replaceAll("'", "\\'");
+        s = s.replaceAll("\"", "\\\"");
+        s = s.replaceAll("-", "\\-");
+        s = s.replaceAll("\\\\", "\\\\\\\\");
+        return s;
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/query/ParseTreeWalker.java Thu Apr 12 17:59:22 2012
@@ -286,29 +286,43 @@ public class ParseTreeWalker<T> implemen
         return evaluator.col(node.getChild(0).getText());
     }
 
-    private T walkTextAnd(Evaluator<T> evaluator2, Tree node) {
-        // TODO Auto-generated method stub
-        return null;
+    private T walkTextAnd(Evaluator<T> evaluator, Tree node) {
+        List<T> terms = new ArrayList<T>();
+        for (Tree term: getChildrenAsList(node)) {
+            terms.add(walkExprTextSearch(evaluator, term));
+        }
+
+        return evaluator.textAnd(terms);
     }
     
-    private T walkTextOr(Evaluator<T> evaluator2, Tree node) {
-        // TODO Auto-generated method stub
-        return null;
+    private T walkTextOr(Evaluator<T> evaluator, Tree node) {
+        List<T> terms = new ArrayList<T>();
+        for (Tree term: getChildrenAsList(node)) {
+            terms.add(walkExprTextSearch(evaluator, term));
+        }
+
+        return evaluator.textOr(terms);
     }
     
-    private T walkTextMinus(Evaluator<T> evaluator2, Tree node) {
-        // TODO Auto-generated method stub
-        return null;
+    private T walkTextMinus(Evaluator<T> evaluator, Tree node) {
+        return evaluator.textMinus(node.getChild(0).getText());
     }
     
-    private T walkTextWord(Evaluator<T> evaluator2, Tree node) {
-        // TODO Auto-generated method stub
-        return null;
+    private T walkTextWord(Evaluator<T> evaluator, Tree node) {
+        return evaluator.textWord(node.getText());
     }
     
-    private T walkTextPhrase(Evaluator<T> evaluator2, Tree node) {
-        // TODO Auto-generated method stub
-        return null;
+    private T walkTextPhrase(Evaluator<T> evaluator, Tree node) {
+        return evaluator.textPhrase(node.getText());
+    }
+
+    private static List<Tree> getChildrenAsList(Tree node) {
+        List<Tree> res = new ArrayList<Tree>(node.getChildCount());
+        for (int i=0; i<node.getChildCount(); i++) {
+            Tree childNode =  node.getChild(i);
+            res.add(childNode);
+        }
+        return res;
     }
 
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java Thu Apr 12 17:59:22 2012
@@ -83,49 +83,49 @@ public class QueryTranslatorTest {
     @Test
     public void testQueryTranslator() {
         assertEquals(
-            "/jcr:root//element(*,jcr:document)",
-            queryTranslator.translateToXPath("select * from cmis:document"));
+                "/jcr:root//element(*,jcr:document)",
+                queryTranslator.translateToXPath("select * from cmis:document"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo']",
-            queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion='foo'"));
+                "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo']",
+                queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion='foo'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[jcr:like(@jcr:isLatestVersion, 'foo')]",
-            queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion LIKE 'foo'"));
+                "/jcr:root//element(*,jcr:document)[jcr:like(@jcr:isLatestVersion, 'foo')]",
+                queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion LIKE 'foo'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[not(jcr:like(@jcr:isLatestVersion, 'foo'))]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where cmis:isLatestVersion NOT LIKE 'foo'"));
+                "/jcr:root//element(*,jcr:document)[not(jcr:like(@jcr:isLatestVersion, 'foo'))]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:isLatestVersion NOT LIKE 'foo'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo' and @jcr:name != 'baz']",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where cmis:isLatestVersion='foo' AND cmis:name<>'baz'"));
+                "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo' and @jcr:name != 'baz']",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:isLatestVersion='foo' AND cmis:name<>'baz'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[not((@jcr:isLatestVersion > 'foo' or @jcr:name < 1.0))]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where NOT (cmis:isLatestVersion>'foo' OR cmis:name< 1.0)"));
+                "/jcr:root//element(*,jcr:document)[not((@jcr:isLatestVersion > 'foo' or @jcr:name < 1.0))]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where NOT (cmis:isLatestVersion>'foo' OR cmis:name< 1.0)"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[(@jcr:name = 'foo' or @jcr:objectId = 'baz' and @jcr:createdBy = 'bar')]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where cmis:name = 'foo' or cmis:objectId = 'baz' " +
-                    "and cmis:createdBy = 'bar'"));
+                "/jcr:root//element(*,jcr:document)[(@jcr:name = 'foo' or @jcr:objectId = 'baz' and @jcr:createdBy = 'bar')]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:name = 'foo' or cmis:objectId = 'baz' " +
+                                "and cmis:createdBy = 'bar'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[(@jcr:name = 'foo' and @jcr:objectId = 'baz' or @jcr:createdBy = 'bar')]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where cmis:name = 'foo' and cmis:objectId = 'baz' " +
-                    "or cmis:createdBy = 'bar'"));
+                "/jcr:root//element(*,jcr:document)[(@jcr:name = 'foo' and @jcr:objectId = 'baz' or @jcr:createdBy = 'bar')]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:name = 'foo' and cmis:objectId = 'baz' " +
+                                "or cmis:createdBy = 'bar'"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:name = 'foo' and (@jcr:objectId = 'baz' or @jcr:createdBy = 'bar')]",
-            queryTranslator.translateToXPath(
-                "select * from cmis:document where cmis:name = 'foo' and (cmis:objectId = 'baz' " +
-                "or cmis:createdBy = 'bar')"));
+                "/jcr:root//element(*,jcr:document)[@jcr:name = 'foo' and (@jcr:objectId = 'baz' or @jcr:createdBy = 'bar')]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:name = 'foo' and (cmis:objectId = 'baz' " +
+                                "or cmis:createdBy = 'bar')"));
 
         assertEquals(
                 "/jcr:root/jcr:folderId/element(*,jcr:document)",
@@ -133,58 +133,78 @@ public class QueryTranslatorTest {
                         "select * from cmis:document where IN_FOLDER('folderId')"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)",
-            queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_FOLDER('folderId')))"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)",
+                queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_FOLDER('folderId')))"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId//element(*,jcr:document)",
-            queryTranslator.translateToXPath("select * from cmis:document where IN_TREE('folderId')"));
+                "/jcr:root/jcr:folderId//element(*,jcr:document)",
+                queryTranslator.translateToXPath("select * from cmis:document where IN_TREE('folderId')"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId//element(*,jcr:document)",
-            queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_TREE('folderId')))"));
+                "/jcr:root/jcr:folderId//element(*,jcr:document)",
+                queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_TREE('folderId')))"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:name <= 1]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where IN_FOLDER('folderId') AND cmis:name <= 1"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:name <= 1]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where IN_FOLDER('folderId') AND cmis:name <= 1"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:name >= 'name' and @jcr:name = true]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where IN_TREE('folderId') AND cmis:name >= 'name' " +
-                    "AND cmis:name = TRUE"));
+                "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:name >= 'name' and @jcr:name = true]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where IN_TREE('folderId') AND cmis:name >= 'name' " +
+                                "AND cmis:name = TRUE"));
 
         GregorianCalendar date = new GregorianCalendar();
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)[not(@jcr:creationDate = xs:dateTime('" +
-                    ISO8601.format(date) + "'))]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where NOT(NOT IN_FOLDER('folderId') OR cmis:creationDate = TIMESTAMP '" +
-                    CalendarHelper.toString(date) + "')"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)[not(@jcr:creationDate = xs:dateTime('" +
+                        ISO8601.format(date) + "'))]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where NOT(NOT IN_FOLDER('folderId') OR cmis:creationDate = TIMESTAMP '" +
+                                CalendarHelper.toString(date) + "')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, '\u4E2D\u6587')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('\u4E2D\u6587')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, 'foo bar')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('foo AND bar')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, 'foo OR bar')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('foo OR bar')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, 'foo -bar')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('foo -bar')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, 'foo \"bar phrase\"')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('foo \"bar phrase\"')"));
+
+        assertEquals(
+                "/jcr:root//element(*,jcr:document)[jcr:contains(jcr:content, 'foo -\"bar phrase\"')]",
+                queryTranslator.translateToXPath("select * from cmis:document where contains('foo -\"bar phrase\"')"));
 
-// TODO: adjust to full text parser
-//        assertEquals(
-//            "/jcr:root//element(*,jcr:document)[jcr:contains(., '\u4E2D\u6587')]",
-//            queryTranslator.translateToXPath("select * from cmis:document where contains('\u4E2D\u6587')"));
     }
 
     @Test
     public void testQueryWithOrderBy() {
         assertEquals(
-            "/jcr:root//element(*,jcr:document)order by @jcr:name ascending",
-            queryTranslator.translateToXPath("select * from cmis:document order by cmis:name"));
+                "/jcr:root//element(*,jcr:document)order by @jcr:name ascending",
+                queryTranslator.translateToXPath("select * from cmis:document order by cmis:name"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo']order by @jcr:name descending",
-            queryTranslator.translateToXPath(
-                "select * from cmis:document where cmis:isLatestVersion='foo' order by cmis:name desc"));
+                "/jcr:root//element(*,jcr:document)[@jcr:isLatestVersion = 'foo']order by @jcr:name descending",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:isLatestVersion='foo' order by cmis:name desc"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[jcr:like(@jcr:isLatestVersion, 'foo')]order by @jcr:name ascending," +
-                "@jcr:objectId descending",
-            queryTranslator.translateToXPath(
-                "select * from cmis:document where cmis:isLatestVersion LIKE 'foo' order by cmis:name asc, cmis:objectId desc"));
+                "/jcr:root//element(*,jcr:document)[jcr:like(@jcr:isLatestVersion, 'foo')]order by @jcr:name ascending," +
+                        "@jcr:objectId descending",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where cmis:isLatestVersion LIKE 'foo' order by cmis:name asc, cmis:objectId desc"));
     }
 
     @Test
@@ -192,75 +212,75 @@ public class QueryTranslatorTest {
         jcrTypeCondition = "@jcr:primaryType = nt:base";
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:primaryType = nt:base]",
-            queryTranslator.translateToXPath("select * from cmis:document"));
+                "/jcr:root//element(*,jcr:document)[@jcr:primaryType = nt:base]",
+                queryTranslator.translateToXPath("select * from cmis:document"));
 
         assertEquals(
-            "/jcr:root//element(*,jcr:document)[@jcr:primaryType = nt:base and @jcr:isLatestVersion = 'foo']",
-            queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion='foo'"));
+                "/jcr:root//element(*,jcr:document)[@jcr:primaryType = nt:base and @jcr:isLatestVersion = 'foo']",
+                queryTranslator.translateToXPath("select * from cmis:document where cmis:isLatestVersion='foo'"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base]",
-            queryTranslator.translateToXPath("select * from cmis:document where IN_FOLDER('folderId')"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base]",
+                queryTranslator.translateToXPath("select * from cmis:document where IN_FOLDER('folderId')"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base]",
-            queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_FOLDER('folderId')))"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base]",
+                queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_FOLDER('folderId')))"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:primaryType = nt:base]",
-            queryTranslator.translateToXPath("select * from cmis:document where IN_TREE('folderId')"));
+                "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:primaryType = nt:base]",
+                queryTranslator.translateToXPath("select * from cmis:document where IN_TREE('folderId')"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:primaryType = nt:base]",
-            queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_TREE('folderId')))"));
+                "/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:primaryType = nt:base]",
+                queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_TREE('folderId')))"));
 
         assertEquals(
-            "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base and @jcr:name <= 1]",
-            queryTranslator.translateToXPath(
-                    "select * from cmis:document where IN_FOLDER('folderId') AND cmis:name <= 1"));
+                "/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base and @jcr:name <= 1]",
+                queryTranslator.translateToXPath(
+                        "select * from cmis:document where IN_FOLDER('folderId') AND cmis:name <= 1"));
     }
 
     @Test
     public void testQueryTranslatorQueryTooSpecific() {
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where NOT IN_FOLDER('folderId')");
+                    "select * from cmis:document where NOT IN_FOLDER('folderId')");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }
 
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where NOT(NOT IN_FOLDER('folderId') AND cmis:name = 'name')");
+                    "select * from cmis:document where NOT(NOT IN_FOLDER('folderId') AND cmis:name = 'name')");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }
 
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where IN_FOLDER('folderId') OR cmis:name = 'name'");
+                    "select * from cmis:document where IN_FOLDER('folderId') OR cmis:name = 'name'");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }
 
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where NOT(IN_FOLDER('folderId') AND cmis:name = 'name')");
+                    "select * from cmis:document where NOT(IN_FOLDER('folderId') AND cmis:name = 'name')");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }
 
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where IN_FOLDER('folder1Id') OR IN_TREE('folder2Id')");
+                    "select * from cmis:document where IN_FOLDER('folder1Id') OR IN_TREE('folder2Id')");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }
 
         try {
             queryTranslator.translateToXPath(
-                "select * from cmis:document where IN_FOLDER('folder1Id') AND NOT IN_TREE('folder2Id')");
+                    "select * from cmis:document where IN_FOLDER('folder1Id') AND NOT IN_TREE('folder2Id')");
             fail();
         }
         catch (CmisInvalidArgumentException expected) { }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java?rev=1325411&r1=1325410&r2=1325411&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java Thu Apr 12 17:59:22 2012
@@ -149,11 +149,35 @@ public class XPathBuilderTest {
                 list(),
                 null);
 
-// TODO: adjust to full text query parser       
-//        check("select * from cmis:document where CONTAINS('foo')",
-//                "jcr:contains(., 'foo')",
-//                list(),
-//                null);
+        check("select * from cmis:document where CONTAINS('foo')",
+                "jcr:contains(jcr:content, 'foo')",
+                list(),
+                null);
+
+        check("select * from cmis:document where CONTAINS('foo AND bar')",
+                "jcr:contains(jcr:content, 'foo bar')",
+                list(),
+                null);
+
+        check("select * from cmis:document where CONTAINS('foo OR bar')",
+                "jcr:contains(jcr:content, 'foo OR bar')",
+                list(),
+                null);
+
+        check("select * from cmis:document where CONTAINS('foo -bar')",
+                "jcr:contains(jcr:content, 'foo -bar')",
+                list(),
+                null);
+
+        check("select * from cmis:document where CONTAINS('foo AND \"bar phrase\"')",
+                "jcr:contains(jcr:content, 'foo \"bar phrase\"')",
+                list(),
+                null);
+
+        check("select * from cmis:document where CONTAINS('foo AND -\"bar phrase\"')",
+                "jcr:contains(jcr:content, 'foo -\"bar phrase\"')",
+                list(),
+                null);
     }
 
     @Test