Marklogic 中的分面过滤
Facet filtering in Marklogic
我有一个要求,我想显示以特定字符序列开头的构面。这可以做到吗?
例如:
如果我的 search:search
returns 关注
<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 个。所以,我想在获取构面本身的同时应用过滤器。这可以做到吗?
是的,您可以创建一个 custom constraint with a custom facet function。开箱即用,构面仅基于直接值比较,而不是通配符。您的自定义约束将是漂亮的样板文件(请参阅文档示例),并且您的 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)
};
如果您预先知道起始字符,则可以在搜索约束定义中使用存储桶,例如:
<bucket name="PAGE" ge="PAGE" lt="PAGF">PAGE</bucket>
另见 http://docs.marklogic.com/guide/search-dev/appendixa#id_80046
为了以更动态的方式获得它们,您将需要 wst 提到的自定义约束。
HTH!
我有一个要求,我想显示以特定字符序列开头的构面。这可以做到吗?
例如:
如果我的 search:search
returns 关注
<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 个。所以,我想在获取构面本身的同时应用过滤器。这可以做到吗?
是的,您可以创建一个 custom constraint with a custom facet function。开箱即用,构面仅基于直接值比较,而不是通配符。您的自定义约束将是漂亮的样板文件(请参阅文档示例),并且您的 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)
};
如果您预先知道起始字符,则可以在搜索约束定义中使用存储桶,例如:
<bucket name="PAGE" ge="PAGE" lt="PAGF">PAGE</bucket>
另见 http://docs.marklogic.com/guide/search-dev/appendixa#id_80046
为了以更动态的方式获得它们,您将需要 wst 提到的自定义约束。
HTH!