You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Sandeep Ambule <sa...@gmail.com> on 2019/10/04 06:26:46 UTC

Fwd: Lucene index: getting empty result while query

Hi ,
I am trying to query with Lucene index but getting the empty result and
below errors in the log,
Traversal query (query without index): select [jcr:path] from [nt:base]
where isdescendantnode('/test') and name='World'; consider creating an index
[async] The index update failed
org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing
index provider detected for type [counter] on index [/oak:index/counter]

can you help me to find what wrong I am doing here,

public class SimpleTest {
    @Test
    public void simpleTest() throws Exception {
        NodeStore store = new MemoryNodeStore();

        //create reposiotory
        LuceneIndexProvider provider = new LuceneIndexProvider();
        ContentRepository repository = new Oak(store)
                .with(new OpenSecurityProvider())
                .with(new InitialContent())
                .with(new NodeCounterEditorProvider())
                .with((QueryIndexProvider) provider)
                .with((Observer) provider)
                .with(new LuceneIndexEditorProvider())
                .withAsyncIndexing("async",
                        5).createContentRepository();

        //login reposiotory and retrive session
        ContentSession contentSession = repository.login(null, null);
        Root root = contentSession.getLatestRoot();

        //create lucene index
        IndexDefinitionBuilder idxBuilder = new
IndexDefinitionBuilder().async("async");
        idxBuilder.indexRule("nt:base").property("name").propertyIndex();

idxBuilder.build(root.getTree("/").addChild("oak:index").addChild("lucene"));
        root.commit();

        //Create TestNode
        String h = "Hello";
        String w = "World";

        Tree test = root.getTree("/").addChild("test");
        test.addChild("a").setProperty("name", Arrays.asList(new String[] {
h, w }), Type.STRINGS);
        test.addChild("b").setProperty("name", h);
        root.commit();

        // wait for async indexing cycle (avoiding more elegant ways)
        Thread.sleep(TimeUnit.SECONDS.toMillis(10));

        //Search
        String query = "select [jcr:path] from [nt:base] where
isdescendantnode('/test') and name='World' option(traversal fail)";

        List<String> paths = executeQuery(root, query);
        for (String path : paths) {
            System.out.println("Path=" + path);
        }
    }

    private List<String> executeQuery(Root root, String query) throws
ParseException {
        Result result = root.getQueryEngine()
                .executeQuery(query, "JCR-SQL2", QueryEngine.NO_BINDINGS,
QueryEngine.NO_MAPPINGS);

        return StreamSupport.stream(result.getRows().spliterator(), false)
                .map(row -> row.getPath())
                .collect(Collectors.toList());
    }
}

Regards,
Sandeep Ambule

Re: Lucene index: getting empty result while query

Posted by Vikas Saurabh <vi...@gmail.com>.
On Mon, Oct 7, 2019 at 12:26 PM Sandeep Ambule <sa...@gmail.com> wrote:
>
> I am trying to query with Lucene index but getting the empty result and
> below errors in the log,
> Traversal query (query without index): select [jcr:path] from [nt:base]
> where isdescendantnode('/test') and name='World'; consider creating an index
> [async] The index update failed
> org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing
> index provider detected for type [counter] on index [/oak:index/counter]
>
> can you help me to find what wrong I am doing here,
>

I pasted your code as is at my end and the test passes with following
in console output
----
Path=/test/a
----

For me indexing wasn't failing:
----
19:10:06.044 INFO  [async-index-update-async]
FulltextBinaryTextExtractor.java:332 Loaded default Tika Config from
classpath file:/home/vsaurabh/depot/git/CQ-misc/jackrabbit-oak/oak-search/target/classes/org/apache/jackrabbit/oak/plugins/index/search/spi/editor/tika-config.xml
19:10:06.328 INFO  [async-index-update-async]
IndexingProgressReporter.java:123 Indexing report
    - /oak:index/counter*(4)
    - /oak:index/lucene*(2)

19:10:06.328 INFO  [async-index-update-async]
IndexingProgressReporter.java:124 Reindexing completed
19:10:06.332 INFO  [async-index-update-async]
AsyncIndexUpdate.java:778 [async] Reindexing completed for indexes:
[/oak:index/counter*(4), /oak:index/lucene*(2)] in 2.407 s (2407 ms)
----

I'm at:
----
commit fcefd93d08040cac6726ba35d1188dd59698ae62 (HEAD -> trunk,
origin/trunk, origin/HEAD)
Author: Julian Reschke <re...@apache.org>
Date:   Wed Oct 9 11:10:08 2019 +0000

    OAK-8685: Deprecate Guava based APIs in WhiteboardUtils

    git-svn-id:
https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1868176
13f79535-47bb-0310-9956-ffa450edef68
----

Could you double check that you're indeed running things correctly?

Thanks,
Vikas