admin管理员组

文章数量:1202393

I am using Marklogic's Structured Query definition for searching document in my database. As a part of this I am trying to use container query for searching a term within a specific hierarchy in my document. While doing so, I found that the search API returns the result even if the term is present anywhere within the document instead of the specified hierarchy. On debugging further we found that the structured query XML (generated through code) works fine and gives proper result when we execute it through ML Query Console. Below is the structured query XML we are using for querying database:

<query xmlns="; xmlns:xs="; xmlns:search="; xmlns:xsi=";>
    <search:and-query>
        <search:and-query>
            <search:container-query>
                <search:element ns="" name="citations"></search:element>
                <search:term-query>
                    <search:text>Abdallah</search:text>
                    <search:weight>0.0</search:weight>
                </search:term-query>
            </search:container-query>
        </search:and-query>
        <search:collection-query>
            <search:uri>bmv</search:uri>
        </search:collection-query>
    </search:and-query>
</query>

Below is the ML Query Console function details we executed:

xquery version "1.0-ml";

import module namespace search = "; at "/MarkLogic/appservices/search/search.xqy";

let $query :=
<query xmlns="; xmlns:xs="; xmlns:search="; xmlns:xsi=";>
    <search:and-query>
        <search:and-query>
            <search:container-query>
                <search:element ns="" name="citations"></search:element>
                <search:term-query>
                    <search:text>Abdallah</search:text>
                    <search:weight>0.0</search:weight>
                </search:term-query>
            </search:container-query>
        </search:and-query>
        <search:collection-query>
            <search:uri>bmv</search:uri>
        </search:collection-query>
    </search:and-query>
</query>

let $options :=
    <options xmlns="xdmp:eval">
      <user-id>{xdmp:user("patent_poc-writer")}</user-id>
    </options>

return xdmp:invoke-function(function(){search:resolve($query)}, $options)

Above we want to get result only if the term is present within citations element which works fine when I execute the query through Marklogic Query Console, but when I hit the same XML using MarkLogic search API endpoint it gives the result back even if the term is not present within the citations element but present anywhere within the document.

本文标签: