Search in sources :

Example 36 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.

the class LuceneIndexDescendantSpellcheckTest method getSpellchecks.

private Set<String> getSpellchecks(String query) throws Exception {
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(query, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    Set<String> suggestions = newHashSet();
    while (rows.hasNext()) {
        suggestions.add(rows.nextRow().getValue("spellcheck").getString());
    }
    return suggestions;
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager)

Example 37 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit by apache.

the class IndexingRuleTest method testUseInExcerpt.

public void testUseInExcerpt() throws RepositoryException {
    Node node = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
    node.setProperty("rule", "excerpt");
    node.setProperty("title", "Apache Jackrabbit");
    // the value below is for testing https://issues.apache.org/jira/browse/JCR-3610
    node.setProperty("foo", "<some>markup</some>");
    node.setProperty("text", "Jackrabbit is a JCR implementation");
    testRootNode.save();
    String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'jackrabbit implementation')]/rep:excerpt(.)";
    RowIterator rows = executeQuery(stmt).getRows();
    assertTrue("No results returned", rows.hasNext());
    Value excerpt = rows.nextRow().getValue("rep:excerpt(.)");
    assertNotNull("No excerpt created", excerpt);
    assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Apache") == -1);
    assertTrue("Missing highlight", excerpt.getString().indexOf("<strong>implementation</strong>") != -1);
    stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'apache')]/rep:excerpt(.)";
    rows = executeQuery(stmt).getRows();
    assertTrue("No results returned", rows.hasNext());
    excerpt = rows.nextRow().getValue("rep:excerpt(.)");
    assertNotNull("No excerpt created", excerpt);
    assertTrue("Title must not be present in excerpt", excerpt.getString().indexOf("Apache") == -1);
}
Also used : Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value)

Example 38 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.

the class TextExtractionQueryTest method testScoreWithoutFulltext.

public void testScoreWithoutFulltext() throws Exception {
    System.out.println(Query.JCR_SQL2);
    QueryResult r = executeSQL2Query("select [jcr:path] from [nt:base] order by [jcr:score]");
    RowIterator it = r.getRows();
    while (it.hasNext()) {
        it.nextRow();
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator)

Example 39 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.

the class LuceneIndexSuggestionTest method suggestNodeName.

//OAK-3825
@Test
public void suggestNodeName() throws Exception {
    final String nodeType = "nt:unstructured";
    createSuggestIndex("lucene-suggest", nodeType, LuceneIndexConstants.PROPDEF_PROP_NODE_NAME);
    root.addNode("indexedNode", nodeType);
    session.save();
    String suggQuery = createSuggestQuery(nodeType, "indexedn");
    QueryManager queryManager = session.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    String value = null;
    while (rows.hasNext()) {
        Row firstRow = rows.nextRow();
        value = firstRow.getValue("suggestion").getString();
        break;
    }
    assertEquals("Node name should be suggested", "indexedNode", value);
}
Also used : QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) Test(org.junit.Test)

Example 40 with RowIterator

use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.

the class LuceneIndexSuggestionTest method checkSuggestions.

/**
     * Utility method to check suggestion over {@code queryNodeType} when the index definition is created for
     * {@code indexNodeType}
     */
private void checkSuggestions(final String indexNodeType, final String queryNodeType, final String indexPropName, final String indexPropValue, final boolean addFullText, final boolean useUserSession, final String suggestQueryText, final boolean shouldSuggest, final boolean suggestAnalyzed) throws Exception {
    createSuggestIndex("lucene-suggest", indexNodeType, indexPropName, addFullText, suggestAnalyzed);
    Node indexedNode = root.addNode("indexedNode1", queryNodeType);
    if (indexPropValue != null) {
        indexedNode.setProperty(indexPropName, indexPropValue + " 1");
        indexedNode = root.addNode("indexedNode2", queryNodeType);
        indexedNode.setProperty(indexPropName, indexPropValue + " 2");
    }
    if (useUserSession) {
        session.getUserManager().createUser(TEST_USER_NAME, TEST_USER_NAME);
    }
    session.save();
    Session userSession = session;
    if (useUserSession) {
        AccessControlUtils.allow(indexedNode, TEST_USER_NAME, Privilege.JCR_READ);
        session.save();
        userSession = repository.login(new SimpleCredentials(TEST_USER_NAME, TEST_USER_NAME.toCharArray()));
    }
    String suggQuery = createSuggestQuery(queryNodeType, suggestQueryText);
    QueryManager queryManager = userSession.getWorkspace().getQueryManager();
    QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
    RowIterator rows = result.getRows();
    String value = null;
    while (rows.hasNext()) {
        Row firstRow = rows.nextRow();
        value = firstRow.getValue("suggestion").getString();
    }
    if (shouldSuggest) {
        assertNotNull("There should be some suggestion", value);
    } else {
        assertNull("There shouldn't be any suggestion", value);
    }
    userSession.logout();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) QueryResult(javax.jcr.query.QueryResult) Node(javax.jcr.Node) RowIterator(javax.jcr.query.RowIterator) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) Session(javax.jcr.Session) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession)

Aggregations

RowIterator (javax.jcr.query.RowIterator)86 Node (javax.jcr.Node)48 QueryResult (javax.jcr.query.QueryResult)45 QueryManager (javax.jcr.query.QueryManager)27 Row (javax.jcr.query.Row)27 Query (javax.jcr.query.Query)25 Test (org.junit.Test)20 Session (javax.jcr.Session)17 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)15 RepositoryException (javax.jcr.RepositoryException)12 Value (javax.jcr.Value)11 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)8 ValueFactory (javax.jcr.ValueFactory)7 ArrayList (java.util.ArrayList)5 NodeIterator (javax.jcr.NodeIterator)5 NoSuchElementException (java.util.NoSuchElementException)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 RowIteratorAdapter (org.apache.jackrabbit.commons.iterator.RowIteratorAdapter)4 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3