Search in sources :

Example 11 with Result

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;
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) QueryEngine(org.apache.jackrabbit.oak.api.QueryEngine) Result(org.apache.jackrabbit.oak.api.Result)

Example 12 with Result

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);
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ExtractionResult(org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText.ExtractionResult) Result(org.apache.jackrabbit.oak.api.Result)

Example 13 with Result

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();
    }
}
Also used : ParseException(java.text.ParseException) Result(org.apache.jackrabbit.oak.api.Result) Nonnull(javax.annotation.Nonnull)

Example 14 with Result

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;
    }
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException) Result(org.apache.jackrabbit.oak.api.Result)

Example 15 with Result

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"));
    }
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) Result(org.apache.jackrabbit.oak.api.Result) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Aggregations

Result (org.apache.jackrabbit.oak.api.Result)36 ResultRow (org.apache.jackrabbit.oak.api.ResultRow)23 Test (org.junit.Test)20 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)15 Tree (org.apache.jackrabbit.oak.api.Tree)15 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)13 ParseException (java.text.ParseException)10 Root (org.apache.jackrabbit.oak.api.Root)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Nonnull (javax.annotation.Nonnull)4 ExtractionResult (org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText.ExtractionResult)3 ArrayList (java.util.ArrayList)2 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)2 QueryEngine (org.apache.jackrabbit.oak.api.QueryEngine)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)1 Closer (com.google.common.io.Closer)1 IOException (java.io.IOException)1 Principal (java.security.Principal)1 Collections (java.util.Collections)1