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;
}
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);
}
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();
}
}
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);
}
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();
}
Aggregations