I'm trying to do a simple string sort using the search API. The sorting seems to work correctly, but the total number of results reported seems incorrect. There is no search string, so I would expect all of the results to be returned, sorted by the title. All the results are returned sorted correctly, but the total attribute is reporting "2" rather than the expected "5". Is this a bug, or am I doing something wrong? As a work around I thought that I might just count the search results, but this has a fatal flaw since in a "real" search all of the results may not be returned. In my application the "total" attribute information is actually being used to drive the pagination of the search results, so it needs to be correct.
The code below can be used to demonstrate the problem: xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; (: Add 5 documents to the database :) let $doc := xdmp:document-insert("/myDocs/one.xml", <a><title>A title</title></a>) let $doc := xdmp:document-insert("/myDocs/two.xml", <a><title>B title</title></a>) let $doc := xdmp:document-insert("/myDocs/three.xml", <a><title>C title</title></a>) let $doc := xdmp:document-insert("/myDocs/four.xml", <a><title>D title</title></a>) let $doc := xdmp:document-insert("/myDocs/five.xml", <a><title>E title</title></a>) (: Sort the file based on the title :) let $searchOptions := <options xmlns="http://marklogic.com/appservices/search"> <sort-order direction="ascending" type="xs:string"> <element name="title"/> </sort-order> <searchable-expression>xdmp:directory("/myDocs/", "infinity")</searchable-expression> </options> return search:search("", $searchOptions) The results are shown below. Notice that the "total" attribute is reporting 2 rather than 5 <search:response total="2" start="1" page-length="10" xmlns:search="http://marklogic.com/appservices/search"> <search:result index="1" uri="/myDocs/one.xml" path="doc("/myDocs/one.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/myDocs/one.xml")/a">A title</search:match> </search:snippet> </search:result> <search:result index="2" uri="/myDocs/two.xml" path="doc("/myDocs/two.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/myDocs/two.xml")/a">B title</search:match> </search:snippet> </search:result> <search:result index="3" uri="/myDocs/three.xml" path="doc("/myDocs/three.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/myDocs/three.xml")/a">C title</search:match> </search:snippet> </search:result> <search:result index="4" uri="/myDocs/four.xml" path="doc("/myDocs/four.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/myDocs/four.xml")/a">D title</search:match> </search:snippet> </search:result> <search:result index="5" uri="/myDocs/five.xml" path="doc("/myDocs/five.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/myDocs/five.xml")/a">E title</search:match> </search:snippet> </search:result> <search:qtext/> <search:metrics> <search:query-resolution-time>PT0.029S</search:query-resolution-time> <search:facet-resolution-time>PT0S</search:facet-resolution-time> <search:snippet-resolution-time>PT0.01S</search:snippet-resolution-time> <search:total-time>PT0.041S</search:total-time> </search:metrics> </search:response> I am running version 4.1-1 on 32 bit Windows 7 Thanks David NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
