Hide Forgot
project_key: SOA String ftsExpression = "myfile*"; Query ftsQuery = qm.createQuery(ftsExpression, Query.JCR_SQL2); This results in javax.jcr.query.InvalidQueryException: The JCR-SQL2 query "myfile*" is not well-formed: Unexpected token 'myfile' at line 1, column 1 I have also tried single/double quoting the word, multiple words, the 'contains(...,...)' syntax but everything results in an InvalidQueryException. Am I doing anything wrong?
If you're trying to use the full-text search language, you need to pass the "Search" value (or the JcrRepository.QueryLanguage.SEARCH constant, if you have access to that package on your classpath) as the second parameter to "createQuery". As you've coded it, you're actually asking ModeShape to treat your query expression as JCR-SQL2. If you'd like to use JCR-SQL2, the equivalent query is: SELECT [jcr:primaryType] FROM [nt:base] WHERE CONTAINS( [nt:base].*, "myfile*" )
In other words, if you want to use the full-text search language, your code should either be: String ftsExpression = "myfile*"; Query ftsQuery = qm.createQuery(ftsExpression, JcrRepository.QueryLanguage.SEARCH); or String ftsExpression = "myfile*"; Query ftsQuery = qm.createQuery(ftsExpression, "Search"); or, if you do want to use JCR-SQL2, it should be this: String ftsExpression = "SELECT [jcr:primaryType] FROM [nt:base] WHERE CONTAINS( [nt:base].*, 'myfile*' )"; Query ftsQuery = qm.createQuery(ftsExpression, Query.JCR_SQL2);
Comment was provided as to how querying should be performed.
Thanks, that JCR 2 way works.