我有以下兩個XML文件:MarkLogic:錯誤的總計數
Page1.xml
<pages xmlns="http://marklogic.com/docs">
<page>
<elementNode>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data3</elementNode>
<textNode>text3</textNode>
</page>
<page>
<elementNode>data4</elementNode>
<textNode>text4</textNode>
</page>
<pages>
Page2.xml
<pages xmlns="http://marklogic.com/docs">
<page>
<elementNode>data1</elementNode>
<textNode>text1</textNode>
</page>
<page>
<elementNode>data2</elementNode>
<textNode>text3</textNode>
</page>
<page>
<elementNode>data3</elementNode>
<textNode>text5</textNode>
</page>
<page>
<elementNode>data4</elementNode>
<textNode>text6</textNode>
</page>
<pages>
我已經創建了一個元素範圍「elementNode」上的索引,並將「page」元素定義爲片段根。我執行與SEARCHTEXT「text1」中
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">
<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"/>
</range>
</constraint>
</options>;
let $searchResult := search:search("text1", $options)
return $searchResult
下面的XQuery執行我得到了以下回應查詢之後:
<?xml version="1.0" encoding="UTF-8"?>
<search:response total="3" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<search:result index="1" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc.xml" path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")" score="22784" confidence="0.451657" fitness="0.663945">
<search:snippet>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")/*:pages/*:page[1]">
<search:highlight>text1</search:highlight>
</search:match>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc.xml")/*:pages/*:page[2]">
<search:highlight>text1</search:highlight>
</search:match>
</search:snippet>
</search:result>
<search:result index="2" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml" path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml")" score="22784" confidence="0.451657" fitness="0.663945">
<search:snippet>
<search:match path="fn:doc("/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml")/*:pages/*:page[1]">
<search:highlight>text1</search:highlight>
</search:match>
</search:snippet>
</search:result>
<search:facet name="elementNode">
<search:facet-value name="data1" count="3">data1</search:facet-value>
</search:facet>
<search:qtext>text1</search:qtext>
<search:metrics>
<search:query-resolution-time>PT0S</search:query-resolution-time>
<search:facet-resolution-time>PT0.015S</search:facet-resolution-time>
<search:snippet-resolution-time>PT0S</search:snippet-resolution-time>
<search:total-time>PT0.015S</search:total-time>
</search:metrics>
</search:response>
現在你可以看到這裏的「總」的search:response
屬性是「3 「這裏因爲我已經將」頁面「定義爲片段根[Marklogic Wrong count and Facet result Xquery。有沒有什麼辦法可以得到正確的總數,在這裏是「2」,因爲「text1」只存在於Page1.xml和Page2.xml中?另外,我得到的面「data2」的計數爲「3」,應該是「2」,因爲它存在於兩個XML文件中,如前一種情況。請幫助我。
實際上它將是用戶的選擇,他/她可以在整個文檔或單個頁面中進行搜索,因此我們的查詢應返回輸出。因此,如果用戶選擇在整個文檔中搜索計數結果應爲「2」·請建議 – user1660340
@ user1660340您有幾個選項。 1)你可以在''上分段,並根據用戶輸入更改選項節點: // pages searchable-expression>。然而,這個數字可能會很多 - 只有片段纔會被準確計數。 2)你可以在''和''上分段,但是對具有祖先/後代關係的元素進行分段可能會導致應用程序出現其他問題。 3)複製內容,將「」元素分解爲文檔。這將始終是準確的。 –
wst
我試過你的建議解決方案(1),但仍然給我總數「3」[片段數],而我期待數「2」,因爲只有2個XML文件具有相同的匹配。 – user1660340