use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class SuggestionIntervalTest method getSuggestions.
Set<String> getSuggestions(String nodeType, String suggestFor) throws Exception {
Set<String> ret = Sets.newHashSet();
String suggQuery = createSuggestQuery(nodeType, suggestFor);
QueryEngine qe = root.getQueryEngine();
Result result = qe.executeQuery(suggQuery, Query.JCR_SQL2, null, null);
for (ResultRow row : result.getRows()) {
ret.add(row.getValue("suggestion").toString());
}
return ret;
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method explainXpath.
private String explainXpath(String query) throws ParseException {
String explain = "explain " + query;
Result result = executeQuery(explain, "xpath", NO_BINDINGS);
ResultRow row = Iterables.getOnlyElement(result.getRows());
return row.getValue("plan").getValue(Type.STRING);
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class IdentifierManager method getReferences.
/**
* Searches all reference properties to the specified {@code tree} that match
* the given name and node type constraints.
*
* @param weak if {@code true} only weak references are returned. Otherwise only
* hard references are returned.
* @param tree The tree for which references should be searched.
* @param propertyName A name constraint for the reference properties;
* {@code null} if no constraint should be enforced.
* @return A set of oak paths of those reference properties referring to the
* specified {@code tree} and matching the constraints.
*/
@Nonnull
public Iterable<String> getReferences(boolean weak, @Nonnull Tree tree, @Nullable final String propertyName) {
if (!effectiveNodeTypeProvider.isNodeType(tree, JcrConstants.MIX_REFERENCEABLE)) {
// shortcut
return Collections.emptySet();
}
final String uuid = getIdentifier(tree);
String reference = weak ? PropertyType.TYPENAME_WEAKREFERENCE : PropertyType.TYPENAME_REFERENCE;
String pName = propertyName == null ? "*" : QueryUtils.escapeForQuery(propertyName);
Map<String, ? extends PropertyValue> bindings = Collections.singletonMap("uuid", PropertyValues.newString(uuid));
try {
Result result = root.getQueryEngine().executeQuery("SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference + "') = $uuid" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS);
return findPaths(result, uuid, propertyName, weak);
} catch (ParseException e) {
log.error("query failed", e);
return Collections.emptySet();
}
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class IdentifierManager method resolveUUID.
private String resolveUUID(PropertyValue uuid) {
try {
Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid);
Result result = root.getQueryEngine().executeQuery("SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id " + "OPTION(INDEX NAME [uuid], INDEX TAG [uuid])" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS);
String path = null;
for (ResultRow rr : result.getRows()) {
if (path != null) {
log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath());
return null;
} else {
path = rr.getPath();
}
}
return path;
} catch (ParseException ex) {
log.error("query failed", ex);
return null;
}
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method getAllSelectedColumns.
@Test
public void getAllSelectedColumns() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
contentRoot.setProperty("foo", "is fox ifoxing");
contentRoot.setProperty("bar", "ifoxing fox");
contentRoot.setProperty("baz", "fox ifoxing");
root.commit();
List<String> columns = newArrayList("rep:excerpt", "rep:excerpt(.)", "rep:excerpt(foo)", "rep:excerpt(bar)");
String selectColumns = Joiner.on(",").join(columns.stream().map(col -> "[" + col + "]").collect(Collectors.toList()));
String query = "SELECT " + selectColumns + " FROM [nt:base] WHERE CONTAINS(*, 'fox')";
Result result = executeQuery(query, SQL2, NO_BINDINGS);
Iterator<? extends ResultRow> resultIter = result.getRows().iterator();
assertTrue(resultIter.hasNext());
ResultRow firstRow = resultIter.next();
PropertyValue excerptValue;
String excerpt;
for (String col : columns) {
excerptValue = firstRow.getValue(col);
assertNotNull(col + " not evaluated", excerptValue);
excerpt = excerptValue.getValue(STRING);
assertFalse(col + " didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains("i<strong>fox</foxing>ing"));
}
}
Aggregations