use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method indexedNonRequestedPropExcerpt.
@Test
public void indexedNonRequestedPropExcerpt() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
contentRoot.setProperty("foo", "is fox ifoxing");
root.commit();
String query = "SELECT [rep:excerpt] 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 nodeExcerpt;
String excerpt;
nodeExcerpt = firstRow.getValue("rep:excerpt(foo)");
assertNotNull("rep:excerpt(foo) not evaluated", nodeExcerpt);
excerpt = nodeExcerpt.getValue(STRING);
assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains("<strong>fox</strong>"));
assertTrue("rep:excerpt(foo) highlighting inside words - got '" + excerpt + "'", !excerpt.contains("i<strong>fox</strong>ing"));
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method binaryExcerpt.
@Test
public void binaryExcerpt() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
String binaryText = "is fox foxing as a fox cub";
Blob blob = new ArrayBasedBlob(binaryText.getBytes());
TestUtil.createFileNode(contentRoot, "binaryNode", blob, "text/plain");
root.commit();
String query = "SELECT [rep:excerpt] 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 nodeExcerpt;
String excerpt;
nodeExcerpt = firstRow.getValue("rep:excerpt");
assertNotNull("rep:excerpt not evaluated", nodeExcerpt);
excerpt = nodeExcerpt.getValue(STRING);
String expected = binaryText.replaceAll(" fox ", " <strong>fox</strong> ");
assertTrue("rep:excerpt didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains(expected));
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method nonIndexedNonRequestedPropExcerpt.
@Test
public void nonIndexedNonRequestedPropExcerpt() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
contentRoot.setProperty("foo", "fox");
contentRoot.setProperty("baz", "is fox ifoxing");
root.commit();
String query = "SELECT [rep:excerpt] 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 nodeExcerpt;
String excerpt;
nodeExcerpt = firstRow.getValue("rep:excerpt(baz)");
assertNotNull("rep:excerpt(baz) not evaluated", nodeExcerpt);
excerpt = nodeExcerpt.getValue(STRING);
assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", excerpt.contains("<strong>fox</strong>"));
assertTrue("rep:excerpt(baz) highlighting inside words - got '" + excerpt + "'", !excerpt.contains("i<strong>fox</strong>ing"));
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method propExcerpt.
@Test
public void propExcerpt() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
contentRoot.setProperty("foo", "is fox ifoxing");
root.commit();
String query = "SELECT [rep:excerpt(foo)] 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 nodeExcerpt;
String excerpt;
nodeExcerpt = firstRow.getValue("rep:excerpt(foo)");
assertNotNull("rep:excerpt(foo) not evaluated", nodeExcerpt);
excerpt = nodeExcerpt.getValue(STRING);
assertTrue("rep:excerpt(foo) didn't evaluate correctly - got '" + excerpt + "'", "is <strong>fox</strong> ifoxing".equals(excerpt));
}
use of org.apache.jackrabbit.oak.api.Result in project jackrabbit-oak by apache.
the class ExcerptTest method relativePropExcerpt.
@Test
public void relativePropExcerpt() throws Exception {
Tree contentRoot = root.getTree("/").addChild("testRoot");
contentRoot.addChild("relative").setProperty("baz", "is fox ifoxing");
root.commit();
String query = "SELECT [rep:excerpt(relative/baz)] FROM [nt:base] WHERE CONTAINS([relative/baz], 'fox')";
Result result = executeQuery(query, SQL2, NO_BINDINGS);
Iterator<? extends ResultRow> resultIter = result.getRows().iterator();
assertTrue(resultIter.hasNext());
ResultRow firstRow = resultIter.next();
PropertyValue nodeExcerpt;
String excerpt;
nodeExcerpt = firstRow.getValue("rep:excerpt(relative/baz)");
assertNotNull("rep:excerpt(relative/baz) not evaluated", nodeExcerpt);
excerpt = nodeExcerpt.getValue(STRING);
assertTrue("rep:excerpt(relative/baz) didn't evaluate correctly - got '" + excerpt + "'", "is <strong>fox</strong> ifoxing".equals(excerpt));
}
Aggregations