Hi Gurbeer, Have you looked at using the SearchAPI for this? Parsing the user's query string can get to be pretty messy, and the SearchAPI handles this well.
Specific to your question, I think you can use the following: cts:or-query(( cts:word-query((fn:tokenize($searchterm," ")), "case-insensitive"), cts:word-query($searchterm, "case-insensitive") )) But I wouldn't use fn:tokenize, I would use cts:tokenize so that the tokenization rules match what the indexer is using. That is only one of the tricky things you run into when trying to parse a user query string. :) Kelly Message: 3 Date: Fri, 24 Jun 2011 10:34:27 -0400 From: "Singh, Gurbeer" <[email protected]> Subject: [MarkLogic Dev General] dynamic cts OR Query To: <[email protected]> Message-ID: <0a864c62635cd34480d56e4f206d148cad90e75...@nywexmbx2123.msad.ms.com> Content-Type: text/plain; charset="us-ascii" Hi, I need to build a dynamic OR query Let's say my search term is "code of conduct" so output should be <cts:or-query> <cts:word-query> <cts:text>Code</cts:text> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> <cts:word-query> <cts:text>of</cts:text> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> <cts:word-query> <cts:text>Conduct</cts:text> <cts:option>case-insensitive</cts:option> <cts:option>wildcarded</cts:option> </cts:word-query> <cts:word-query> <cts:text xml:lang="en">code of conduct</cts:text> <cts:option>case-insensitive</cts:option> </cts:word-query> </cts:or-query> When I trying let $searchterm := "code of conduct" let $query :=cts:or-query((cts:word-query(fn:string-join($searchterm," "), "case-insensitive"), cts:word-query($searchterm, "case-insensitive"))) return $query <cts:or-query> <cts:word-query> <cts:text xml:lang="en">code of conduct</cts:text> <cts:option>case-insensitive</cts:option> </cts:word-query> <cts:word-query> <cts:text xml:lang="en">code of conduct</cts:text> <cts:option>case-insensitive</cts:option> </cts:word-query> </cts:or-query> I understand we should tokenize with " "and build the query, but we can't update variables in XQUERY right, that's why was wondering how to reach the solution ~Gurbeer _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
