我正在执行这个 JCR SQL2 查询:
SELECT * FROM [my:type] AS n
WHERE NAME(n) LIKE 'node_name_prefix.%'
AND n.deleted = CAST('false' AS BOOLEAN)
AND CONTAINS(n.user, '1f12f97d-6516-48b9-ae75-47d17ef6877f')
AND CONTAINS(n.state, 'executing')
OR CONTAINS(n.state, 'done')
并得到我应该创建索引的警告:
Traversed 1000 nodes with filter Filter(query=SELECT * FROM [my:type] AS n
WHERE NAME(n) LIKE 'node_name_prefix.%' AND n.deleted = CAST('false' AS
BOOLEAN) AND CONTAINS(n.user, '1f12f97d-6516-48b9-ae75-47d17ef6877f') AND
CONTAINS(n.state, 'executing') OR CONTAINS(n.state, 'done')
fullText=user:"1f12f97d-6516-48b9-ae75-47d17ef6877f" (state:"executing" OR
state:"done"), path=*, property=[:localname=[(node_name_prefix.%..],
deleted=[false], state=[is not null]]); consider creating an index or
changing the query
我做了,像这样:
NodeBuilder rootBuilder = this.segmentNodeStore.getRoot().builder();
NodeBuilder index = IndexUtils.getOrCreateOakIndex(rootBuilder);
NodeBuilder childNode = index.getChildNode(propertyName);
IndexUtils.createIndexDefinition(index, propertyName, true, uniqueValue, ImmutableList.of(propertyName), null);
CommitHook hook = new CompositeHook(new ConflictHook(JcrConflictHandler.createJcrConflictHandler()), new EditorHook(new ConflictValidatorProvider()));
try
{
this.segmentNodeStore.merge(rootBuilder, hook, CommitInfo.EMPTY);
}
catch(CommitFailedException ex)
{
throw new IOException(ex);
}
其中 propertyName 是以下字符串之一:deleted、state、jcr:localname、jcr:path、jcr:property、jcr:fullText、property、localname、path、user、fullText
但我仍然收到警告,我猜这意味着我的索引不会被使用。当我打印出所有可用的索引时,我得到以下信息:
可用索引:deleted, repMembers, counter, state, jcr:localname, jcr:path, acPrincipalName, jcr:property, jcr:fullText, uuid, property, localname, nodetype, reference, principalName, path, user, authorizableId, fullText
所以看起来我的索引是在一些 jcr 默认索引已经存在的地方创建的,比如 nodetype、acPrincipalName、reference、repMembers、authorizableId 和 counter
任何提示我在这里做错了什么?我只想确保查询尽可能快,所以我真的很想知道如何创建 Oak 将使用的索引。
我使用的是 Oak 1.5.12 版本,我的存储库是这样实例化的:
this.fileStore = FileStore.builder(new File("/path/to/my/repo")).withCacheSize(512).withMemoryMapping(true).build();
this.segmentNodeStore = SegmentNodeStore.builder(this.fileStore).build();
this.repository = new Jcr(new Oak(this.segmentNodeStore)).with(qes).withAsyncIndexing().createRepository();