我有一个要求,其中我想显示以特定字符序列开头的构面。可以这样做吗?
例如:
如果我的search:search
返回以下方面
<search:values-response name="facet" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:search="http://marklogic.com/appservices/search">
<search:distinct-value frequency="846">DMPK</search:distinct-value>
<search:distinct-value frequency="323">TNF</search:distinct-value>
<search:distinct-value frequency="301">IL6</search:distinct-value>
<search:distinct-value frequency="297">PAGE4</search:distinct-value>
<search:distinct-value frequency="296">INS</search:distinct-value>
<search:distinct-value frequency="291">PSD</search:distinct-value>
<search:distinct-value frequency="280">EGFR</search:distinct-value>
<search:distinct-value frequency="271">PAGE3</search:distinct-value>
<search:distinct-value frequency="270">PAGE5</search:distinct-value>
<search:distinct-value frequency="268">CD4</search:distinct-value>
<metrics xmlns="http://marklogic.com/appservices/search">
<values-resolution-time>PT0.012602S</values-resolution-time>
<total-time>PT0.014218S</total-time>
</metrics>
</search:values-response>
我想进一步过滤这个方面,只说让我从说PAGE
开始给我所有方面。我得到所有方面之后我无法应用滤镜,因为刻面可以在1000以内。因此,我希望在获取构面时应用滤镜。可以这样做吗?
答案 0 :(得分:1)
是的,您可以使用custom constraint创建custom facet function。开箱即用,facet仅基于直接值比较,而不是通配符。您的自定义约束非常类似(请参阅文档示例),您的facet函数将执行通配符:
declare function my:start-facet(
$constraint as element(search:constraint),
$query as cts:query?,
$facet-options as xs:string*,
$quality-weight as xs:double?,
$forests as xs:unsignedLong*)
as item()*
{
cts:element-value-match(
xs:QName("my:element"), "PAGE*",
$facet-options, $query, $quality-weight, $queries)
};
答案 1 :(得分:1)
如果您事先知道起始字符,则可以在搜索约束定义中使用存储区,例如:
<bucket name="PAGE" ge="PAGE" lt="PAGF">PAGE</bucket>
另见http://docs.marklogic.com/guide/search-dev/appendixa#id_80046
为了让它们更加动态,你需要一个自定义约束,如wst所述。
HTH!