按复合字段的属性查询文档失败
Query documents by attributes of a compound field fail
我尝试创建一个包含文档列表的页面并向列表中添加筛选。
文档结构如下所示:
/content/documents/web/sale-exclusives/
<node name> [web:saleexclusive]
web:exclusive [web:exclusive] (@web:year)
因此,web:saleexclusive
类型的根文档具有 web:exclusive
类型和属性 web:year
的复合子文档。
我想通过其子复合节点的 web:year
属性过滤 web:saleexclusive
类型的文档。
为了实现这一点,我扩展了 EssentialsListComponent
并覆盖了 contributeAndFilters
方法(仅用于测试):
@Override
protected void contributeAndFilters(List<BaseFilter> filters, HstRequest request, HstQuery query) {
Filter filter = query.createFilter();
try {
filter.addGreaterOrEqualThan("web:exclusive/web:year", 1900L);
filters.add(filter);
} catch (FilterException e) {
LOGGER.error("", e);
}
}
问题是我得到的结果是空的,尽管有 web:year > 1900 的文档。没有过滤器,我得到的所有文档都在 sale-exclusives
.[=22= 下]
上面的过滤器产生以下 XPath 查询:
//*[(@hippo:paths='79a713cf-294d-4e99-9d63-fc50db10e43f') and (@hippo:availability='live') and not(@jcr:primaryType='nt:frozenNode') and (web:exclusive/web:year >= 1900)] order by @jcr:score descending
按 web:saleexclusive
自己的属性过滤效果很好。
我该如何解决?
addGreaterOrEqualThan 运算符适用于基于名称的元素。在您的情况下,您想要 select 一个节点的 属性,在 XPATH 中它总是以 @ 符号为前缀。
尝试使用以下表达式:
try {
filter.addGreaterOrEqualThan("web:exclusive/@web:year", 1900L);
filters.add(filter);
} catch (FilterException e) {
LOGGER.error("", e);
}
您始终可以在存储库 servlet 接口 (http://localhost:8080/cms/repository/) 中试验 XPath 查询。
在@Jeroen 的帮助下,我找到了解决方案。
讨论了同样的问题here:
1) According domain configuration, the 'liveuser' has no read access to nodes of type poll:poll. Since the domains are used to create the authorization query, this authorization query does not contain the nodes of type poll:poll, hence, they won't show up in search results
2) The AccessManager treats nodes below documents a bit different: If a node is below a Document that you are user are allowed to read, you are also allowed to read child nodes of that Document according the AccessManager, even if you do not have this configured in the domain rules
The two above rules are contradicting. You can 'fix' it yourself by adding domains for a liveuser that he is allowed to read nodes of type hippo:compound and hippostd:html.
解决方案在最后一段。添加安全域并向 liveuser
授予读取权限后,问题就解决了。
我尝试创建一个包含文档列表的页面并向列表中添加筛选。 文档结构如下所示:
/content/documents/web/sale-exclusives/
<node name> [web:saleexclusive]
web:exclusive [web:exclusive] (@web:year)
因此,web:saleexclusive
类型的根文档具有 web:exclusive
类型和属性 web:year
的复合子文档。
我想通过其子复合节点的 web:year
属性过滤 web:saleexclusive
类型的文档。
为了实现这一点,我扩展了 EssentialsListComponent
并覆盖了 contributeAndFilters
方法(仅用于测试):
@Override
protected void contributeAndFilters(List<BaseFilter> filters, HstRequest request, HstQuery query) {
Filter filter = query.createFilter();
try {
filter.addGreaterOrEqualThan("web:exclusive/web:year", 1900L);
filters.add(filter);
} catch (FilterException e) {
LOGGER.error("", e);
}
}
问题是我得到的结果是空的,尽管有 web:year > 1900 的文档。没有过滤器,我得到的所有文档都在 sale-exclusives
.[=22= 下]
上面的过滤器产生以下 XPath 查询:
//*[(@hippo:paths='79a713cf-294d-4e99-9d63-fc50db10e43f') and (@hippo:availability='live') and not(@jcr:primaryType='nt:frozenNode') and (web:exclusive/web:year >= 1900)] order by @jcr:score descending
按 web:saleexclusive
自己的属性过滤效果很好。
我该如何解决?
addGreaterOrEqualThan 运算符适用于基于名称的元素。在您的情况下,您想要 select 一个节点的 属性,在 XPATH 中它总是以 @ 符号为前缀。
尝试使用以下表达式:
try {
filter.addGreaterOrEqualThan("web:exclusive/@web:year", 1900L);
filters.add(filter);
} catch (FilterException e) {
LOGGER.error("", e);
}
您始终可以在存储库 servlet 接口 (http://localhost:8080/cms/repository/) 中试验 XPath 查询。
在@Jeroen 的帮助下,我找到了解决方案。
讨论了同样的问题here:
1) According domain configuration, the 'liveuser' has no read access to nodes of type poll:poll. Since the domains are used to create the authorization query, this authorization query does not contain the nodes of type poll:poll, hence, they won't show up in search results
2) The AccessManager treats nodes below documents a bit different: If a node is below a Document that you are user are allowed to read, you are also allowed to read child nodes of that Document according the AccessManager, even if you do not have this configured in the domain rules
The two above rules are contradicting. You can 'fix' it yourself by adding domains for a liveuser that he is allowed to read nodes of type hippo:compound and hippostd:html.
解决方案在最后一段。添加安全域并向 liveuser
授予读取权限后,问题就解决了。