[
https://issues.apache.org/jira/browse/CMIS-511?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13251688#comment-13251688
]
Jose Carlos Campanero commented on CMIS-511:
--------------------------------------------
I think I found one possible implementation of such functionality. This
functionality involves replacing the method walkExprTextSearch(Evaluator<T>
evaluator, Tree node) with the following:
{code}
private T walkExprTextSearch(Evaluator<T> evaluator, Tree node) {
String value = walkExprTextSearch(node);
return evaluator.value(value);
}
private String walkExprTextSearch(Tree node) {
switch (node.getType()) {
case TextSearchLexer.TEXT_AND:
return walkTextAnd(node);
case TextSearchLexer.TEXT_OR:
return walkTextOr(node);
case TextSearchLexer.TEXT_MINUS:
return walkTextMinus(node);
case TextSearchLexer.TEXT_SEARCH_WORD_LIT:
return walkTextWord(node);
case TextSearchLexer.TEXT_SEARCH_PHRASE_STRING_LIT:
return walkTextPhrase(node);
default:
throw new CmisRuntimeException("Unknown node type: " +
node.getType() + " (" + node.getText() + ")");
}
}
{code}
And drop the different walkTextXXX(Evaluator<T> evaluator, Tree node) methods
and use the following implementation instead:
{code}
private String walkTextAnd(Tree node) {
List<Tree> terms = getChildrenAsList(node);
StringBuilder sb = new StringBuilder();
String sep = "";
for (Tree term: terms) {
sb.append(sep).append(walkExprTextSearch(term));
sep = " ";
}
return sb.toString();
}
private String walkTextOr(Tree node) {
List<Tree> terms = getChildrenAsList(node);
StringBuilder sb = new StringBuilder();
String sep = "";
for (Tree term: terms) {
sb.append(sep).append(walkExprTextSearch(term));
sep = " OR ";
}
return sb.toString();
}
private String walkTextMinus(Tree node) {
return "-" + escape(node.getChild(0).getText());
}
private String walkTextWord(Tree node) {
String text = node.getText();
return escape(text);
}
private String walkTextPhrase(Tree node) {
String phrase = node.getText();
return "\"" + escape(phrase.substring(1, phrase.length()-1)) + "\"";
}
private List<Tree> getChildrenAsList(Tree node) {
List<Tree> res = new ArrayList<Tree>(node.getChildCount());
for (int i=0; i<node.getChildCount(); i++) {
Tree childNnode = node.getChild(i);
res.add(childNnode);
}
return res;
}
// 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 String escape(String s)
{
if (s == null)
{
return "";
}
s = s.replaceAll("'", "\\'");
s = s.replaceAll("\"", "\\\"");
s = s.replaceAll("-", "\\-");
s = s.replaceAll("\\\\", "\\\\\\\\");
return s;
}
{code}
Finally, the {{contains}} method in {{EvaluatorXPath}} must set the search axis
to "jcr.content" instead of self ("."):
{code}
@Override
public XPathBuilder contains(XPathBuilder op1, XPathBuilder op2) {
return new FunctionBuilder("jcr:contains", "jcr:content", op2);
}
{code}
> Full text search still is incomplete
> ------------------------------------
>
> Key: CMIS-511
> URL: https://issues.apache.org/jira/browse/CMIS-511
> Project: Chemistry
> Issue Type: Improvement
> Components: opencmis-server-jcr
> Reporter: Jose Carlos Campanero
>
> Full text search still is incomplete: it's not possible query by content.
> In org.apache.chemistry.opencmis.jcr.query.ParseTreeWalker you can find:
> private T walkTextAnd(Evaluator<T> evaluator2, Tree node) {
> // TODO Auto-generated method stub
> return null;
> }
>
> private T walkTextOr(Evaluator<T> evaluator2, Tree node) {
> // TODO Auto-generated method stub
> return null;
> }
>
> private T walkTextMinus(Evaluator<T> evaluator2, Tree node) {
> // TODO Auto-generated method stub
> return null;
> }
>
> private T walkTextWord(Evaluator<T> evaluator2, Tree node) {
> // TODO Auto-generated method stub
> return null;
> }
>
> private T walkTextPhrase(Evaluator<T> evaluator2, Tree node) {
> // TODO Auto-generated method stub
> return null;
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira