Hi Marco,

there's a bunch of stuff you are doing wrong. Here's a cleaned version of
your example:

public class CustomRI implements RepositoryInitializer {
    @Override
    public void initialize(NodeBuilder builder) {
        NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
        IndexUtils.createIndexDefinition(index, "starredIndex", true, false,
                ImmutableList.of("custom:starProp"), null);
    }
}

to name a few bad things:
 * no need to extend the InitialContent (actually this is a bad idea)
 * use the provided builder directly, don't do this: 'NodeBuilder root =
builder.getBaseState().builder();'
 * don't recreate the default indexes (ie. don't mess with the reference
index).

to check that your index ends up where it needs to and has some content
under it, you can always use the oak console or oak explorer.

hope this helps,
alex




On Wed, Sep 7, 2016 at 3:55 PM, Marco Piovesana <[email protected]>
wrote:

> Hi,
> I'm trying to define an index on a custom property to speedup my query, but
> it looks like is not used.
> The query I'm running extracts all the nodes having a certain value for a
> custom property:
>
> Query query = queryManager.createQuery("SELECT p.* FROM
> [custom:starrable] AS p WHERE p.[custom:starProp] = 'marco'",
> Query.JCR_SQL2);
>
>
> I create the index defining my custom IndexInitializer like this:
>
> public class RepositoryIndexInitializer extends InitialContent {
>
>     public void initialize(NodeBuilder builder) {
>         super.initialize(builder);
>         NodeBuilder root = builder.getBaseState().builder();
>         NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
>
>         NodeBuilder nt = IndexUtils.createIndexDefinition(index,
> "starredIndex", true, false, ImmutableList.of("custom:starProp"),
> null);
>         IndexUtils.createReferenceIndex(index);
>     }
>
> }
>
>  And here is how i define my repository:
>
> Jcr jcr = new Jcr(nodeStore).with(new InitialContent()).with(new
> SecurityProviderImpl()).with(new RepositoryIndexInitializer());
>
> Repository repository = jcr.createRepository();
>
> But when i execute the query I always get the warning message:
>
> WARN org.apache.jackrabbit.oak.spi.query.Cursors$TraversingCursor -
> Traversed 1000 nodes with filter Filter(query=SELECT p.* FROM
> [custom:starrable] AS p WHERE ISDESCENDANTNODE('/myfolder/') AND
> p.[custom:starProp] = 'marco', path=/myfolder//*,
> property=[custom:starProp=[marco]]); consider creating an index or
> changing
> the query
>
>
> What am I doing wrong?
>
> Marco.
>

Reply via email to