Excellent advice - thanks!

I created the index and the number is indeed correct.

Thanks for taking the time to help out, it is very much appreciated.

David


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Wednesday, August 19, 2009 1:42 PM
To: General Mark Logic Developer Discussion
Subject: [MarkLogic Dev General] RE: search bug?

Hi David,

Here's a debugging hint:  turn the <debug> option on in your options node, and 
run search:check-options($options,true()) on it.  Like this:

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

(: 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>
            <debug>
      </options>

return search:check-options($searchOptions,true())

That will do several things:
1) check the structure of your options node (it's fine)
2) check to be sure you've got all the indexes you need based on your options
3) show the exact FLWOR expression that the SearchAPI has created and it using 
under the covers.

When I ran it on my local DB, I got the following reports along with my search 
results:

<search:report id="SEARCH-INDEXCONFIG" name="" 
type="sort-order"><error:format-string 
xmlns:error="http://marklogic.com/xdmp/error";>XDMP-ELEMRIDXNOTFOUND: 
cts:element-values(QName("", "title"), (), ()) -- No  element range index for 
QName("", "title") </error:format-string></search:report>
  <search:report id="SEARCH-FLWOR">(for $result in 
cts:search(xdmp:directory("/myDocs/", "infinity"), cts:and-query((), ()), 
("score-logtfidf"), 1) order by xs:string(($result//title)[1]) ascending return 
$result)[1 to 10]</search:report>

The first one shows that I need to add a range index on title to support the 
sorting specification.  I did that, and my totals were then correct.

Why?  There has already been some discussion on this list of @total; 
essentially @total uses cts:remainder, which is an estimate based on what can 
be resolved out of indexes. 

Does that help?

--Colleen




________________________________________
From: [email protected] 
[[email protected]] On Behalf Of David Scott Gurney 
[[email protected]]
Sent: Wednesday, August 19, 2009 10:34 AM
To: [email protected]
Subject: [MarkLogic Dev General] search bug?

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(&quot;/myDocs/one.xml&quot;)" score="0" confidence="0" fitness="0">
    <search:snippet>
      <search:match path="doc(&quot;/myDocs/one.xml&quot;)/a">A 
title</search:match>
    </search:snippet>
  </search:result>
  <search:result index="2" uri="/myDocs/two.xml" 
path="doc(&quot;/myDocs/two.xml&quot;)" score="0" confidence="0" fitness="0">
    <search:snippet>
      <search:match path="doc(&quot;/myDocs/two.xml&quot;)/a">B 
title</search:match>
    </search:snippet>
  </search:result>
  <search:result index="3" uri="/myDocs/three.xml" 
path="doc(&quot;/myDocs/three.xml&quot;)" score="0" confidence="0" fitness="0">
    <search:snippet>
      <search:match path="doc(&quot;/myDocs/three.xml&quot;)/a">C 
title</search:match>
    </search:snippet>
  </search:result>
  <search:result index="4" uri="/myDocs/four.xml" 
path="doc(&quot;/myDocs/four.xml&quot;)" score="0" confidence="0" fitness="0">
    <search:snippet>
      <search:match path="doc(&quot;/myDocs/four.xml&quot;)/a">D 
title</search:match>
    </search:snippet>
  </search:result>
  <search:result index="5" uri="/myDocs/five.xml" 
path="doc(&quot;/myDocs/five.xml&quot;)" score="0" confidence="0" fitness="0">
    <search:snippet>
      <search:match path="doc(&quot;/myDocs/five.xml&quot;)/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
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to