Search in sources :

Example 16 with Result

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"));
}
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)

Example 17 with Result

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));
}
Also used : ResultRow(org.apache.jackrabbit.oak.api.ResultRow) Blob(org.apache.jackrabbit.oak.api.Blob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) 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)

Example 18 with Result

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"));
}
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)

Example 19 with Result

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

Example 20 with Result

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