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 [general-boun...@developer.marklogic.com] on behalf of Ryan Dew [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/ annotationchronology/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 http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
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 [general-boun...@developer.marklogic.com] on behalf of Erik Hennum [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 [general-boun...@developer.marklogic.com] on behalf of Ryan Dew [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/ annotationchronology/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 http://developer.marklogic.com/mailman/listinfo/general
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 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 [ general-boun...@developer.marklogic.com] on behalf of Erik Hennum [ 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 [ general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ 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/ annotationchronology/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 http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
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.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j@gmail.commailto: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/ annotationchronology/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.commailto: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
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
Hi Ryan, I'm able to reproduce the problem you're having. Take out searchable-expression, it works as designed. Put it in, ordering doesn't hit this attribute. The order by expression for both queries is the same order by xs:string(($result//div/@id)[1]) So I think you're right, that this expression will not catch the right attribute if $result doesn't have a child named div. I'm not sure what to do about this -- maybe put @order on some other child? I can't think of any workaround to immediately help Charles On 05/02/2013 09:50 AM, Erik Hennum wrote: 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.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j@gmail.commailto: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/ annotationchronology/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.commailto:General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general ___ General mailing list General@developer.marklogic.com
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
Ryan, I've logged a bug for this. I'm not sure what we can do about it, but at least we'll be able to give this some serious thought. Maybe if there's a searchable expression we'll just have to reference the doc root in the order by expression. Charles On 05/02/2013 10:18 AM, Charles Greer wrote: Hi Ryan, I'm able to reproduce the problem you're having. Take out searchable-expression, it works as designed. Put it in, ordering doesn't hit this attribute. The order by expression for both queries is the same order by xs:string(($result//div/@id)[1]) So I think you're right, that this expression will not catch the right attribute if $result doesn't have a child named div. I'm not sure what to do about this -- maybe put @order on some other child? I can't think of any workaround to immediately help Charles On 05/02/2013 09:50 AM, Erik Hennum wrote: 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.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j@gmail.commailto: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/ annotationchronology/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
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
Instead of doing a $result//div/@order you could do result/descendant-or-self:div/@order like Ryan suggested. On Thu, May 2, 2013 at 11:28 AM, Charles Greer cgr...@marklogic.com wrote: Ryan, I've logged a bug for this. I'm not sure what we can do about it, but at least we'll be able to give this some serious thought. Maybe if there's a searchable expression we'll just have to reference the doc root in the order by expression. Charles On 05/02/2013 10:18 AM, Charles Greer wrote: Hi Ryan, I'm able to reproduce the problem you're having. Take out searchable-expression, it works as designed. Put it in, ordering doesn't hit this attribute. The order by expression for both queries is the same order by xs:string(($result//div/@id)[1]) So I think you're right, that this expression will not catch the right attribute if $result doesn't have a child named div. I'm not sure what to do about this -- maybe put @order on some other child? I can't think of any workaround to immediately help Charles On 05/02/2013 09:50 AM, Erik Hennum wrote: 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.commailto:colleen.whit...@marklogic.comcolleen.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.comgeneral-boun...@developer.marklogic.com[ general-boun...@developer.marklogic.com mailto:general-boun...@developer.marklogic.comgeneral-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.com mailto:erik.hen...@marklogic.com 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.comgeneral-boun...@developer.marklogic.com[ general-boun...@developer.marklogic.com mailto:general-boun...@developer.marklogic.comgeneral-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j@gmail.commailto:ryan.j@gmail.comryan.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;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/
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
Hi, Ryan: A couple of belated thoughts besides revising the XPath for searchable expression. If you're using ML6 and you can express the query as a structured search instead of a string search, you can move the existential query for div out of the searchable expression: search:resolve( query xmlns=http://marklogic.com/appservices/search; element-constraint-query constraint-namedivcontainer/constraint-name and-query/ /element-constraint-query /query, options xmlns=http://marklogic.com/appservices/search; constraint name=divcontainer element-query ns= name=root/ /constraint ... /options) For string search, you can also express the existential query on div with an equivalent cts:element-query() in the search:additional-query element. Hoping that's useful, Erik Hennum From: general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.com] Sent: Thursday, May 02, 2013 9:50 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] search:search and ordering by attribute on root element 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.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Erik Hennum [erik.hen...@marklogic.commailto: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.commailto:general-boun...@developer.marklogic.com [general-boun...@developer.marklogic.commailto:general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ryan.j@gmail.commailto: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/ annotationchronology/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
Re: [MarkLogic Dev General] search:search and ordering by attribute on root element
I'll look into that. Thanks everyone! On Thu, May 2, 2013 at 11:59 AM, Erik Hennum erik.hen...@marklogic.comwrote: Hi, Ryan: A couple of belated thoughts besides revising the XPath for searchable expression. If you're using ML6 and you can express the query as a structured search instead of a string search, you can move the existential query for div out of the searchable expression: search:resolve( query xmlns=http://marklogic.com/appservices/search; element-constraint-query constraint-namedivcontainer/constraint-name and-query/ /element-constraint-query /query, options xmlns=http://marklogic.com/appservices/search; constraint name=divcontainer element-query ns= name=root/ /constraint ... /options) For string search, you can also express the existential query on div with an equivalent cts:element-query() in the search:additional-query element. Hoping that's useful, Erik Hennum -- *From:* general-boun...@developer.marklogic.com [ general-boun...@developer.marklogic.com] on behalf of Erik Hennum [ erik.hen...@marklogic.com] *Sent:* Thursday, May 02, 2013 9:50 AM *To:* MarkLogic Developer Discussion *Subject:* Re: [MarkLogic Dev General] search:search and ordering by attribute on root element 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 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 [ general-boun...@developer.marklogic.com] on behalf of Erik Hennum [ 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 [ general-boun...@developer.marklogic.com] on behalf of Ryan Dew [ 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/ annotationchronology/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