use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class ResultSizeTest method doTestResultSize.
private void doTestResultSize(boolean union, int expected) throws RepositoryException {
Session session = superuser;
QueryManager qm = session.getWorkspace().getQueryManager();
String xpath;
if (union) {
xpath = "/jcr:root//*[jcr:contains(@text, 'Hello') or jcr:contains(@text, 'World')]";
} else {
xpath = "/jcr:root//*[jcr:contains(@text, 'Hello World')]";
}
Query q;
long result;
NodeIterator it;
StringBuilder buff;
// fast (insecure) case
// enabled by default now, in LuceneOakRepositoryStub
System.clearProperty("oak.fastQuerySize");
q = qm.createQuery(xpath, "xpath");
it = q.execute().getNodes();
result = it.getSize();
assertTrue("size: " + result + " expected around " + expected, result > expected - 50 && result < expected + 50);
buff = new StringBuilder();
while (it.hasNext()) {
Node n = it.nextNode();
buff.append(n.getPath()).append('\n');
}
String fastSizeResult = buff.toString();
q = qm.createQuery(xpath, "xpath");
q.setLimit(90);
it = q.execute().getNodes();
assertEquals(90, it.getSize());
// default (secure) case
// manually disabled
System.setProperty("oak.fastQuerySize", "false");
q = qm.createQuery(xpath, "xpath");
it = q.execute().getNodes();
result = it.getSize();
assertEquals(-1, result);
buff = new StringBuilder();
while (it.hasNext()) {
Node n = it.nextNode();
buff.append(n.getPath()).append('\n');
}
String regularResult = buff.toString();
assertEquals(regularResult, fastSizeResult);
System.clearProperty("oak.fastQuerySize");
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class LuceneIndexSuggestionTest method avoidInfiniteSuggestions.
@Test
public void avoidInfiniteSuggestions() throws Exception {
final String nodeType = "nt:unstructured";
final String indexPropName = "description";
final String higherRankPropValue = "DD DD DD DD";
final String exceptionThrowingPropValue = "DD~@#$%^&*()_+{}\":?><`1234567890-=[]";
final String suggestQueryText = "dd";
createSuggestIndex("lucene-suggest", nodeType, indexPropName);
root.addNode("higherRankNode", nodeType).setProperty(indexPropName, higherRankPropValue);
root.addNode("exceptionThrowingNode", nodeType).setProperty(indexPropName, exceptionThrowingPropValue);
session.save();
String suggQuery = createSuggestQuery(nodeType, suggestQueryText);
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
int count = 0;
while (count < 3 && rows.hasNext()) {
count++;
rows.nextRow();
}
assertTrue("There must not be more than 2 suggestions", count <= 2);
}
use of javax.jcr.query.QueryManager in project jackrabbit-oak by apache.
the class HybridIndexClusterIT method queryResult.
private static List<String> queryResult(Session session, String indexedPropName, String value) throws RepositoryException {
session.refresh(false);
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("select * from [nt:base] where [" + indexedPropName + "] = $value", Query.JCR_SQL2);
q.bindValue("value", session.getValueFactory().createValue(value));
QueryResult result = q.execute();
List<String> paths = Lists.newArrayList();
for (Row r : JcrUtils.getRows(result)) {
paths.add(r.getPath());
}
return paths;
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class PathBasedQueryTest method runTest.
@Override
protected void runTest() throws Exception {
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery("/jcr:root" + root.getPath() + "/*/*[@count = 250]", Query.XPATH);
for (int i = 0; i < 10; i++) {
q.execute().getNodes().nextNode();
}
}
use of javax.jcr.query.QueryManager in project jackrabbit by apache.
the class SimpleSearchTest method runTest.
public void runTest() throws Exception {
QueryManager manager = session.getWorkspace().getQueryManager();
for (int i = 0; i < NODE_COUNT; i++) {
Query query = createQuery(manager, i);
NodeIterator iterator = query.execute().getNodes();
while (iterator.hasNext()) {
Node node = iterator.nextNode();
if (node.getProperty("testcount").getLong() != i) {
throw new Exception("Invalid test result: " + node.getPath());
}
}
}
}
Aggregations