Matt, You might also try using search:parse() and search:resolve(). Together they are like search:search(), but search:resolve() takes the parsed xml representation of the query, so you can avoid un-parsing the manipulated query and send it straight to search:resolve.
Yours, Damon From: [email protected] [mailto:[email protected]] On Behalf Of Will Thompson Sent: Friday, June 22, 2012 2:13 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] using search:parse/search:unparse and thsr:query-lookup/thsr:expand The output of thsr:expand() is a cts:query item. Unparse accepts a schema-element(cts:query) item, the XML-serialized form of the cts:query item. Most cts: functions take cts:query items as parameters, while search: functions usually take XML. If you want to unparse it you just need to convert it to XML: search:unparse(document{$qexpanded}/*) -Will From: [email protected] [mailto:[email protected]] On Behalf Of Treskon, Matthew Sent: Friday, June 22, 2012 10:45 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] using search:parse/search:unparse and thsr:query-lookup/thsr:expand let $qexpanded := thsr:expand(cts:query($qparsed),thsr:query-lookup("/myThsrDocs/NALT3.xml",cts:query($qparsed)),(),(),()) let $qout2 := search:unparse($qexpanded) [1.0-ml] XDMP-AS: (err:XPTY0004) $qtree as element() -- Invalid coercion: cts:and-query(( ... ________________________________ From: [email protected]<mailto:[email protected]> [[email protected]] on behalf of Treskon, Matthew [[email protected]] Sent: Friday, June 22, 2012 1:41 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] using search:parse/search:unparse and thsr:query-lookup/thsr:expand Yes. the output of thsr:expand (which looks right) is not an element (according to search:unparse). Matthew ________________________________ From: [email protected]<mailto:[email protected]> [[email protected]] on behalf of Will Thompson [[email protected]] Sent: Friday, June 22, 2012 1:23 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] using search:parse/search:unparse and thsr:query-lookup/thsr:expand Have you tried thsr:expand()? -Will From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Treskon, Matthew Sent: Friday, June 22, 2012 10:03 AM To: [email protected]<mailto:[email protected]> Subject: [MarkLogic Dev General] using search:parse/search:unparse and thsr:query-lookup/thsr:expand Developer Forum, I am looking to expand our users' queries using a thesaurus. We are using search:search with an extensive options node. I am looking to avoid having to recreate all parsing structures using string processing. Although string-join may work for simple queries, it becomes considerably more difficult when contending with nested sets (parenthesis), phrases (quotes, beginning and ending), and Boolean/other operators. Subsequently, I was hoping to use search:parse -> thsr:expand/thsr:query-lookup -> search:unparse. However, I am running into mixed-content type and annotation errors. This is basically what I am trying to do: let $q := <q>"tile drainage" AND (phosphorous OR nitrogen)</q> let $qparsed := search:parse($q,$OPTIONS) let $qexpanded := thsr:query-lookup("/myThsrDocs/NALT3.xml",$qparsed) let $qout := search:unparse(search:parse($qexpanded,$OPTIONS)) return $qout Is there a way to do this? So you don't have to see our options node, $qparsed equals ' <cts:and-query qtextjoin="AND" strength="20" xmlns:cts="http://marklogic.com/cts"> <cts:word-query qtextpre=""" qtextref="cts:text" qtextpost="""> <cts:text>tile drainage</cts:text> <cts:option>punctuation-sensitive</cts:option> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> <cts:or-query qtextjoin="OR" strength="10"> <cts:word-query qtextref="cts:text"> <cts:text>phosphorous</cts:text> <cts:option>punctuation-sensitive</cts:option> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> <cts:word-query qtextref="cts:text"> <cts:text>nitrogen</cts:text> <cts:option>punctuation-sensitive</cts:option> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> </cts:or-query> </cts:and-query> ' Thank you, Matthew ______________________________________ Matthew Treskon Digital Services Librarian--DigiTop National Agricultural Library US Department of Agriculture, ARS [email protected]<mailto:[email protected]> 765-494-8692 (Phone) 765-494-1705 (Fax) ...advancing access to global information for agriculture. ______________________________________ This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
_______________________________________________ General mailing list [email protected] http://community.marklogic.com/mailman/listinfo/general
