通配符搜索不适用于路径索引

Wildcard search not working for path-index

这是给出所需结果的查询:

import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

search:search("( ( collectionId: ( "54930050DETB6CP71D38" ) )  )  sort:documentCreationDateDES", 
<options xmlns="http://marklogic.com/appservices/search">

    <term>
        <empty apply="all-results"/>
        <term-option>unstemmed</term-option>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>

    <additional-query>{cts:directory-query('/dir/subdir01/', "1")}</additional-query>

    <transform-results apply="transformed-result" ns="http://searchgui/search" at="/customResultSet.xqy"/>

    (:
    Constraints or Search Criteria.
    - collectionId
    - creationDate
    :)

    <search:constraint name="collectionId">
        <search:range type="xs:string" facet="false" collation="http://marklogic.com/collation/en">
            <search:path-index ns="http://any.anyns.com/2013/doc">
                //cd:documentCollections/cd:collection/cd:id
            </search:path-index>
        </search:range>
    </search:constraint>

    <search:constraint name="creationDateRange">
        <search:range type="xs:dateTime" facet="false">
            <search:bucket ge="0" lt="0" name="documentCreationDate">
                Search by Document Creation date / uploaded date
            </search:bucket>
            <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            <facet-option>limit=10</facet-option>
            <facet-option>item-order</facet-option>
            <facet-option>descending</facet-option>
        </search:range>
    </search:constraint>

    (:
    Sorting options:
    - collectionId
    - creationDate
    :)
    <search:operator name="sort">

        (: Document Collection Id :)
        <search:state name="collectionIdASC">
            <search:sort-order direction="ascending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>
        <search:state name="collectionIdDES">
            <search:sort-order direction="descending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>

        (: Creation Date :)
        <search:state name="documentCreationDateASC">
            <search:sort-order direction="ascending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>
        <search:state name="documentCreationDateDES">
            <search:sort-order direction="descending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>

    </search:operator>
</options>, 1, 100);

但是当我如下用通配符替换搜索条件时,return 没有任何结果:

"( ( collectionId: ( &quot;* *54930050DETB6CP71D38* *&quot; ) )  )  sort:documentCreationDateDES"

虽然我将 <term-option> 设置为 wildcarded 仍然不起作用,任何关于我可能遗漏的建议或指示都会有所帮助.

我尝试将其他 term-optionsensitive 更改为 insensitive 并以不同的组合更改回来,但它不起作用,stemmedunstemmed 有效。

术语选项不适用于范围限制,只有面选项适用。并且 facet-option wildcarded 不存在。范围约束是选择范围的理想选择,例如num GT x AND num LT y,但不适合中串匹配。

我认为您必须为同一路径创建一个词或值约束才能在其上使用通配符。不幸的是,您不能像在 collectionId 约束中那样在特定路径上创建单词或值约束。您必须使用该路径创建一个字段。

HTH!

以下描述回答了如何,它是@grtjn 对 的补充。

这是查询中更改的部分:

<search:constraint name="collectionId">
    <search:word>
        <search:field name="collectionIdField"/>
        <search:term-option>case-insensitive</search:term-option>
        <search:term-option>unstemmed</search:term-option>
        <search:term-option>wildcarded</search:term-option>
        <search:term-option>punctuation-insensitive</search:term-option>
    </search:word>
</search:constraint>

我可以在我的查询中使用上面的内容,因为我 created a field - collectionIdField 类型 - path,路径为 //cd:documentCollections/cd:collection/cd:id.

这是用于创建字段的查询,也可以从管理控制台完成,但我更喜欢查询方式:

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";

(:
  get admin configuration
:)
let $config := admin:get-configuration()

(:
    Specify the database where you want to create this field
:)
let $dbid := xdmp:database("My-Database")

(:
    The field you want to create
:)
let $field-name := "collectionIdField"

(:
    Since you are creating a path-field, specify the path.
    Multiple field-paths can be specified
:)
let $field-paths := (
                      admin:database-field-path("//cd:documentCollections/cd:collection/cd:id", xs:double(1.0))
                    )
(:
    Link database-field with field-path
:)
let $fieldspec := admin:database-path-field($field-name, $field-paths)

let $addFieldConfig := admin:database-add-field($config, $dbid, $fieldspec)

(:
    Save the new database-add-field configuration to create the field
:)
return admin:save-configuration($addFieldConfig)

所以这是我最后一个实际有效的查询:

import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

search:search("( ( collectionId: ( &quot;54930050DETB6CP71D38&quot; ) )  )  sort:documentCreationDateDES", 
<options xmlns="http://marklogic.com/appservices/search">

    <term>
        <empty apply="all-results"/>
        <term-option>unstemmed</term-option>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>

    <additional-query>{cts:directory-query('/dir/subdir01/', "1")}</additional-query>

    <transform-results apply="transformed-result" ns="http://searchgui/search" at="/customResultSet.xqy"/>

    (:
    Constraints or Search Criteria.
    - collectionId
    - creationDate
    :)

    <search:constraint name="collectionId">
        <search:word>
            <search:field name="collectionIdField"/>
            <search:term-option>case-insensitive</search:term-option>
            <search:term-option>unstemmed</search:term-option>
            <search:term-option>wildcarded</search:term-option>
            <search:term-option>punctuation-insensitive</search:term-option>
        </search:word>
    </search:constraint>

    <search:constraint name="creationDateRange">
        <search:range type="xs:dateTime" facet="false">
            <search:bucket ge="0" lt="0" name="documentCreationDate">
                Search by Document Creation date / uploaded date
            </search:bucket>
            <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            <facet-option>limit=10</facet-option>
            <facet-option>item-order</facet-option>
            <facet-option>descending</facet-option>
        </search:range>
    </search:constraint>

    (:
    Sorting options:
    - collectionId
    - creationDate
    :)
    <search:operator name="sort">

        (: Document Collection Id :)
        <search:state name="collectionIdASC">
            <search:sort-order direction="ascending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>
        <search:state name="collectionIdDES">
            <search:sort-order direction="descending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>

        (: Creation Date :)
        <search:state name="documentCreationDateASC">
            <search:sort-order direction="ascending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>
        <search:state name="documentCreationDateDES">
            <search:sort-order direction="descending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>

    </search:operator>
</options>, 1, 100);

Field 有助于通配符,它​​有自己的术语选项,可在 <word> 元素中提供,如上所示。