如何在Marlogic控制台上将Marklogic REST查询(qbe)转换为可执行查询?

时间:2019-07-15 08:24:11

标签: marklogic

这里是一个REST查询(使用python),我想将其转换为Marklogic控制台查询,以便我检查详细信息。

url = self.url + "qbe?collection=" + colName+ "&pageLength=50"

query = { "$query": { "$and" : [
                    {"id" : 1 },
                    {"name" : "Elizabeth" },
                    ]}
                }

response = requests.post(url=url, data=json.dumps(query), headers=headers, auth=self.auth)

,我应该在“查询类型”中输入什么。很抱歉这个新手问题。感谢您的回答。

1 个答案:

答案 0 :(得分:0)

这有点令人费解,但我不知道有什么替代方法。如果共享了更简单的替代方法,我可能会删除此答案。

首先,您需要将&view=structured&format=xml添加到您的URL。

您收到的回复将如下所示:

<search:search xmlns:search="http://marklogic.com/appservices/search">

<search:query>
<search:value-query>
<search:element ns="" name="author"/>
<search:text>Mark Twain</search:text>
<search:term-option>exact</search:term-option>
</search:value-query>
<search:value-query>
<search:element ns="" name="edition"/>
<search:attribute ns="" name="format"/>
<search:text>paperback</search:text>
<search:term-option>exact</search:term-option>
</search:value-query>
</search:query>

<search:options>
<search:search-option>unfiltered</search:search-option>
<search:search-option>format-xml</search:search-option>
<search:quality-weight>0</search:quality-weight>
<search:return-facets>true</search:return-facets>
<search:return-results>true</search:return-results>
</search:options>

</search:search>

使用此响应,您可以像这样在QConsole中通过XQuery运行search:resolve

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

search:resolve(
<search:query xmlns:search="http://marklogic.com/appservices/search">
<search:value-query>
<search:element ns="" name="author"/>
<search:text>Mark Twain</search:text>
<search:term-option>exact</search:term-option>
</search:value-query>
<search:value-query>
<search:element ns="" name="edition"/>
<search:attribute ns="" name="format"/>
<search:text>paperback</search:text>
<search:term-option>exact</search:term-option>
</search:value-query>
</search:query>,

<search:options xmlns:search="http://marklogic.com/appservices/search">
<search:search-option>unfiltered</search:search-option>
<search:quality-weight>0</search:quality-weight>
<search:return-facets>true</search:return-facets>
<search:return-results>true</search:return-results>
<search:debug>true</search:debug>
</search:options>
)

请注意,我在第二个XML参数中添加了<search:debug>true</search:debug>这很重要。

在此函数的结果中,您将看到一个名为search:report的元素,其中将包含QBE实际上正在运行的cts:query。

<search:report id="SEARCH-FLWOR">(cts:search(fn:collection(), cts:and-query((cts:element-value-query(fn:QName("","author"), "Mark Twain", ("case-sensitive","diacritic-sensitive","punctuation-sensitive","whitespace-sensitive","unstemmed","unwildcarded","lang=en"), 1), cts:element-attribute-value-query(fn:QName("","edition"), fn:QName("","format"), "paperback", ("case-sensitive","diacritic-sensitive","punctuation-sensitive","whitespace-sensitive","unstemmed","unwildcarded","lang=en"), 1)), ()), ("unfiltered",cts:score-order("descending")), 0))[1 to 10]</search:report>

您可以复制此元素的内容,并单独在QConsole中将其作为XQuery运行。