*/
public Query createQuery( String expression,
String language,
Path storedAtPath ) throws InvalidQueryException {
// Look for a parser for the specified language ...
QueryParser parser = session.repository().queryParsers().getParserFor(language);
if (parser == null) {
Set<String> languages = session.repository().queryParsers().getLanguages();
throw new InvalidQueryException(JcrI18n.invalidQueryLanguage.text(language, languages));
}
if (parser.getLanguage().equals(FullTextSearchParser.LANGUAGE)) {
// This is a full-text search ...
return new JcrSearch(this.session, expression, parser.getLanguage(), storedAtPath);
}
TypeSystem typeSystem = session.executionContext.getValueFactories().getTypeSystem();
try {
// Parsing must be done now ...
QueryCommand command = parser.parseQuery(expression, typeSystem);
if (command == null) {
// The query is not well-formed and cannot be parsed ...
throw new InvalidQueryException(JcrI18n.queryCannotBeParsedUsingLanguage.text(language, expression));
}
PlanHints hints = new PlanHints();
hints.showPlan = true;
// If using XPath, we need to add a few hints ...
if (Query.XPATH.equals(language)) {
hints.hasFullTextSearch = true; // requires 'jcr:score' to exist
}
return new JcrQuery(this.session, expression, parser.getLanguage(), command, hints, storedAtPath);
} catch (ParsingException e) {
// The query is not well-formed and cannot be parsed ...
String reason = e.getMessage();
throw new InvalidQueryException(JcrI18n.queryCannotBeParsedUsingLanguage.text(language, expression, reason));
} catch (org.jboss.dna.graph.query.parse.InvalidQueryException e) {