And the fn:index-of function is useful for the order by expression. You pass
it the sequence you want to order by followed by the value to order. For
example:
xquery version "1.0-ml";
let $x := ("a", "b", "c", "d", "e")
let $y := ("c", "e", "a")
for $z at $i in $x
order by index-of($y, $z)
return
$z
=>
c
e
a
b
d
-Danny
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Lee, David
Sent: Thursday, June 10, 2010 4:44 AM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] String Array query
Once you have your result set you can do
for $s in $results
order by < some expression >
return $s
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Pragya
Kapoor
Sent: Thursday, June 10, 2010 12:24 AM
To: [email protected]
Subject: Re: [MarkLogic Dev General] String Array query
Hi David,
I tried for $token in $suggestionsXML//title/string() but this also give
me same results.
Is there any way to do custom sorting? If yes, how?
Attached file content:
xquery version "1.0-ml";
let $search := "XYZ"
let $Id := "title.xml"
let $suggestLimit :=10
let $strsearch := $search
let $search := fn:concat($strsearch,
$constant:WILDCARD_CHARACTER)
let $tokenId := fn:tokenize($Id, ",")
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<searchable-expression
//body/title
</searchable-expression>
<term>
<term-option>punctuation-sensitive</term-option>
<term-option>wildcarded</term-option>
<term-option>case-insensitive</term-option>
</term>
<return-facets>false</return-facets>
<return-metrics>false</return-metrics>
<transform-results apply="raw" />
<additional-query>
{cts:and-query((
cts:and-query(for $token in fn:tokenize($search, " ")
return
cts:element-word-query(xs:QName("title"),$token,
("case-insensitive","wildcarded"))),
cts:document-query(($tokenId))))
}
</additional-query>
</options>
let $suggestions := search:search($search, 1,
$suggestLimit)
let $suggestionsXML
:=suggestXML:suggestionsXML($suggestions,$strsearch)
for $token in $suggestionsXML//title/string()
return
let $flag := fn:starts-with($token,$strsearch)
let $result:=
if($flag eq fn:true())then $token else ()
let $result2 := if(fn:compare($strsearch, $token)eq 1) then $token
else ()
let $result3 := if(fn:compare($strsearch, $token)eq -1) then $token
else ()
return ($result,$result2)
Thanks,
Pragya
Date: Wed, 9 Jun 2010 05:21:12 -0700
From: "Lee, David" <[email protected]>
Subject: Re: [MarkLogic Dev General] String Array query
To: "General Mark Logic Developer Discussion"
<[email protected]>
Message-ID: <dd37f70d78609d4e9587d473fc61e0a71a0d1...@postoffice>
Content-Type: text/plain; charset="utf-8"
I cant tell for sure as your attachment didnt make it to the list (or
atleast my inbox).
but my guess is that you are getting "document order".
which is the default for xquery lists.
Since all of the tokens are *nodes* (not strinngs) they have a document
order which is preserved.
Suggest you construct strings and see if that works (wild guess but I'm
curious myself)
Just change the first line to
for $token in $suggestionsXML//title/string()
From: [email protected]
[mailto:[email protected]] On Behalf Of Pragya
Kapoor
Sent: Wednesday, June 09, 2010 7:54 AM
To: [email protected]
Subject: [MarkLogic Dev General] String Array query
Hi,
I am using the attached file.
Query : = ABC
for $token in $suggestionsXML//title/text()
return
let $flag := fn:starts-with($token,$strsearch)
let $result:=
if($flag eq fn:true())then $token else ()
let $result2 := if(fn:compare($strsearch, $token)eq 1) then $token
else ()
let $result3 := if(fn:compare($strsearch, $token)eq -1) then $token
else ()
return ($result,$result2)
Value of $result
XYZ
XYZ PERCENTAGE
XYZ RESULT
XYZ VALUE
Value of $result2
DIRECT XYZ RESULT
THE XYZ VALUE
Value of ($result,$result2) then it automatically sort in alphabetical
order which I don?t want.
DIRECT XYZ RESULT
THE XYZ VALUE
XYZ
XYZ PERCENTAGE
XYZ RESULT
XYZ VALUE
I want the result in following order:
XYZ
XYZ PERCENTAGE
XYZ RESULT
XYZ VALUE
DIRECT XYZ RESULT
THE XYZ VALUE
Please let me know how this can be achieved.
Thanks,
Pragya
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended
solely
for the use of the addressee(s). If you are not the intended recipient,
please
notify the sender by e-mail and delete the original message. Further,
you are not
to copy, disclose, or distribute this e-mail or its contents to any
other person and
any such actions are unlawful. This e-mail may contain viruses. Infosys
has taken
every reasonable precaution to minimize this risk, but is not liable for
any damage
you may sustain as a result of any virus in this e-mail. You should
carry out your
own virus checks before opening the e-mail or attachment. Infosys
reserves the
right to monitor and review the content of all messages sent to or from
this e-mail
address. Messages sent to or from this e-mail address may be stored on
the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://developer.marklogic.com/pipermail/general/attachments/20100609/40
634243/attachment.html
------------------------------
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
End of General Digest, Vol 72, Issue 15
***************************************
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general