野兔橡木索引
Jackrabbit Oak Indexing
我正在执行这个 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);
}
其中 属性Name 是以下字符串之一:deleted、state、jcr:localname、jcr:path、jcr:property、jcr:fullText、属性, 本地名, 路径, 用户, fullText
但我仍然收到警告,我猜这意味着我的索引将不会被使用。当我打印出所有可用索引时,我得到以下信息:
可用索引:已删除、repMembers、计数器、状态、jcr:localname、jcr:path、acPrincipalName、jcr:property、jcr:fullText、uuid、属性、 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();
根据您上面的查询,您应该在 /oak:index 下创建一个 lucene property index,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:my="TYPE THE MY TYPE DEFINITION URI" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="oak:Unstructured"
indexDescription="My Index Defition"
compatVersion="{Long}2"
type="lucene"
async="async">
<indexRules jcr:primaryType="nt:unstructured">
<my:type
jcr:primaryType="nt:unstructured"
indexNodeName="{Boolean}true">
<properties jcr:primaryType="nt:unstructured">
<deleted name="deleted" propertyIndex="{Boolean}true" type="Boolean" jcr:primaryType="nt:unstructured"/>
<user name="user" analyzed="{Boolean}true" nodeScopeIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
<state name="state" analyzed="{Boolean}true" nodeScopeIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
</properties>
</my:type>
</indexRules>
</jcr:root>
说明:
+ myCustomIndex
- type = "lucene" -> tells that your are defining lucene index
- async = "async" -> should be alsways set to "async" according the docs
+ indexRules -> defines the rules for this index
+ my:type -> defines the index rules for your custom node type
- indexNodeName = "true" -> indexes the node name and make "like" queries possible
+ properties -> the index rules for the properties on your my:type node
+ deleted
- name = "deleted" -> property name
- propertyIndex = "true" -> controls if this property is used for equality conditions
- type = "Boolean" -> property type
+ user
- name = "user" -> property name
- analyzed = "true" -> when used as part of contains
- nodeScopeIndex = "Boolean" -> control whether the value of a property should be part of fulltext index
+ state
- name = "state" -> property name
- analyzed = "true" -> when used as part of contains
- nodeScopeIndex = "Boolean" -> control whether the value of a property should be part of fulltext index
我正在执行这个 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);
}
其中 属性Name 是以下字符串之一:deleted、state、jcr:localname、jcr:path、jcr:property、jcr:fullText、属性, 本地名, 路径, 用户, fullText
但我仍然收到警告,我猜这意味着我的索引将不会被使用。当我打印出所有可用索引时,我得到以下信息:
可用索引:已删除、repMembers、计数器、状态、jcr:localname、jcr:path、acPrincipalName、jcr:property、jcr:fullText、uuid、属性、 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();
根据您上面的查询,您应该在 /oak:index 下创建一个 lucene property index,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:my="TYPE THE MY TYPE DEFINITION URI" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="oak:Unstructured"
indexDescription="My Index Defition"
compatVersion="{Long}2"
type="lucene"
async="async">
<indexRules jcr:primaryType="nt:unstructured">
<my:type
jcr:primaryType="nt:unstructured"
indexNodeName="{Boolean}true">
<properties jcr:primaryType="nt:unstructured">
<deleted name="deleted" propertyIndex="{Boolean}true" type="Boolean" jcr:primaryType="nt:unstructured"/>
<user name="user" analyzed="{Boolean}true" nodeScopeIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
<state name="state" analyzed="{Boolean}true" nodeScopeIndex="{Boolean}true" jcr:primaryType="nt:unstructured"/>
</properties>
</my:type>
</indexRules>
</jcr:root>
说明:
+ myCustomIndex
- type = "lucene" -> tells that your are defining lucene index
- async = "async" -> should be alsways set to "async" according the docs
+ indexRules -> defines the rules for this index
+ my:type -> defines the index rules for your custom node type
- indexNodeName = "true" -> indexes the node name and make "like" queries possible
+ properties -> the index rules for the properties on your my:type node
+ deleted
- name = "deleted" -> property name
- propertyIndex = "true" -> controls if this property is used for equality conditions
- type = "Boolean" -> property type
+ user
- name = "user" -> property name
- analyzed = "true" -> when used as part of contains
- nodeScopeIndex = "Boolean" -> control whether the value of a property should be part of fulltext index
+ state
- name = "state" -> property name
- analyzed = "true" -> when used as part of contains
- nodeScopeIndex = "Boolean" -> control whether the value of a property should be part of fulltext index