Hi, Ryan:

Any chance your searchable expression could qualify the parent of div (with an 
XPath that includes a predicate that confirms the existence of a div child)?


Erik Hennum
________________________________
From: general-boun...@developer.marklogic.com 
[general-boun...@developer.marklogic.com] on behalf of Ryan Dew 
[ryan.j....@gmail.com]
Sent: Thursday, May 02, 2013 9:38 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] search:search and ordering by attribute on 
root element

Sorry, I used bad terminology. I said root element when I should have said the 
element returned by cts:search. In our example, the searchable expression that 
we set is "//div" so I believe that is what is being used to construct a 
cts:search that looks like "cts:search(//div, ...)" so the cts:search is 
actually returning the div element that matches the search. That div happens to 
also be the element that has the order attribute on it and I believe the order 
by is constructed so that it does "order by $result//div/@order" when we really 
want "order by $result/descendant-or-self::div/@order". Since the div elements 
we are looking for aren't root elements we don't have the option to jump up to 
the document level with something like "fn:collection()".

I'm thinking, for now, our best option would probably be to use search:parse to 
build the cts:queries to pass into cts:search and do our own ordering logic.

Thanks,
Ryan Dew


On Thu, May 2, 2013 at 10:20 AM, Colleen Whitney 
<colleen.whit...@marklogic.com<mailto:colleen.whit...@marklogic.com>> wrote:
The other issue that commonly causes sorting to look confusing is when you have 
multiple instances of an element in the same document.  Is there any 
possibility that this is the case with your data?
________________________________
From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 
[general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>]
 on behalf of Erik Hennum 
[erik.hen...@marklogic.com<mailto:erik.hen...@marklogic.com>]
Sent: Thursday, May 02, 2013 6:49 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] search:search and ordering by attribute on 
root element

Hi, Ryan:

cts:search() returns documents, so // will match the root element.

In my simple test, search:search() did sort on an attribute on the root element.

A few simple things to check -- is the div element in the XHTML namespace?  Is 
there a range index on the attribute in the same collation as the query?


Erik Hennum

________________________________
From: 
general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>
 
[general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com>]
 on behalf of Ryan Dew [ryan.j....@gmail.com<mailto:ryan.j....@gmail.com>]
Sent: Wednesday, May 01, 2013 3:02 PM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] search:search and ordering by attribute on 
root element

Hello everyone,

We have scenario where we are trying to sort on an attribute on the root 
element being returned. The simple use case is shown below. The div elements 
that we are returning have an order attribute.

let $options :=
    <options xmlns="http://marklogic.com/appservices/search";>
        <searchable-expression>//div</searchable-expression>
        <transform-results apply="raw"/>
        <sort-order type="xs:string" direction="ascending">
            <element ns="" name="div"/>
            <attribute ns="" name="order"/>
            <annotation>chronology</annotation>
        </sort-order>
  </options>

return search:search("faith",$options,1,10)

We don't get the results we would expect. After looking at the search:search 
code it appears that the root element isn't included in the XPath expression 
generated for the order by. It generates "$result//div/@order", but I would 
expect something like: "$result/descendant-or-self::div/@order". (Sorry if I'm 
digging more than I should.) Has anyone else encountered this problem and 
worked around it?

Thanks,
Ryan Dew

_______________________________________________
General mailing list
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
http://developer.marklogic.com/mailman/listinfo/general


_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to