Marklogic:使用搜索:搜索在元素范围索引上进行Wilcard搜索 [英] Marklogic : Wilcard search on Element range Index with search:search

查看:84
本文介绍了Marklogic:使用搜索:搜索在元素范围索引上进行Wilcard搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Page1.xml

Page1.xml

<pages xmlns="http://marklogic.com/docs">
  <page>
    <elementNode>data1</elementNode>
    <textNode>text1</textNode>
  </page>
  <page>
    <elementNode>data2</elementNode>
    <textNode>text2</textNode>
  </page>
  <page>
    <elementNode>data3</elementNode>
    <textNode>text3</textNode>
  </page>
  <page>
    <elementNode>data4</elementNode>
    <textNode>text4</textNode>
  </page>
</pages>

我已经在elementNode上创建了一个元素范围索引,然后执行了以下XQuery:

I have created an element range index on elementNode, then executed the following XQuery:

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace ts= "http://marklogic.com/docs";
import module namespace search ="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

declare variable $options :=  
  <options xmlns="http://marklogic.com/appservices/search">
    <searchable-expression xmlns:ex="http://marklogic.com/docs">//ex:page</searchable-expression>
    <grammar>
      <starter strength="30" apply="grouping" delimiter=")">(</starter>
      <starter strength="40" apply="prefix" element="cts:not-query">NOT</starter>
      <joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</joiner>
      <joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</joiner>
      <joiner strength="50" apply="constraint">:</joiner>
    </grammar>
    <constraint name="elementNode">
      <range collation="http://marklogic.com/collation/" type="xs:string">
        <facet-option>limit=1000</facet-option>
        <element ns="http://marklogic.com/docs" name="elementNode"/>
        <searchable-expression xmlns:ex="http://marklogic.com/clover/docs-xml">//ex:elementNode</searchable-expression>
      </range>
    </constraint>
  </options>;

let $searchResult := search:search("elementNode:(*data*)", $options)
return $searchResult

在上述情况下,由于在这里使用了通配符星号[*],所以我没有得到任何结果.有什么方法可以启用具有元素范围约束的通配符搜索吗?预先感谢.

In the above case I am not getting any result because I have used wild card asterisk [*] here. Is there any way to enable wild card search with element range constraints? Thanks in advance.

推荐答案

范围约束使用cts:element-range-query(),它允许进行值比较,但不能使用通配符.但是,cts:element-value-match()设计为使用通配符表达式,因此一种解决方案是使用该API调用构建自定义约束:

Range constraints use cts:element-range-query(), which allows for value comparison but not wildcards. However, cts:element-value-match() is designed to use wildcard expressions, so one solution is to build a custom constraint with that API call:

declare function parse(
    $constraint-qtext as xs:string,
    $right as schema-element(cts:query))
as schema-element(cts:query)
{
    let $vals := cts:element-value-match(
        xs:QName("elementNode"),
        string($right//cts:text))
    return document { 
        cts:element-range-query(xs:QName("elementNode"),"=",$vals) }/*
};

然后在您的选项节点中声明:

And then declare that in your options node:

<options xmlns="http://marklogic.com/appservices/search">
    <constraint name="match-elementName">
        <custom facet="false">
            <parse apply="parse" ns="" at="/custom.xqy"/>
        </custom>
    </constraint>
</options>

但是,如果不需要范围索引,则在elementNode上创建字段然后使用字段约束可能会更简单:

If you don't need the range index, though, it might be simpler to create a field over elementNode and then use a field constraint:

<constraint name="elementNode">
    <term-option>wildcarded</term-option>
    <word>
        <field name="field-elementNode"/>
    </word>
</constraint>

这篇关于Marklogic:使用搜索:搜索在元素范围索引上进行Wilcard搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆