I don't think search:parse implements the grammar you want. Take a look at 
https://github.com/mblakele/xqysp - it is a bit more powerful and more flexible 
than search:parse. Once you have the cts:query you want, you can pass it to 
search:resolve and continue to use normal search API techniques.

-- Mike

On 17 Nov 2011, at 09:31 , Majid Valipour wrote:

> Hi all,
> 
> I need to have advanced queries within a field. For example for field
> "DOC" and query text "foo AND bar" the query text is expected to be
> parsed into the following query:
> <cts:and-query>
>   <cts:field-word-query>
>     <cts:field>DOC</cts:field>
>     <cts:text>foo</cts:text>
>  </cts:field-word-query>
>  <cts:field-word-query>
>      <cts:field>DOC</cts:field>
>      <cts:text>foo</cts:text>
>  </cts:field-word-query>
> </cts:and-query>
> 
> I very much prefer to use search:parse to achieve this because the
> parser should handle complex queries that may include phrase,
> grouping, and etc and search:parse does this quite well.
> However search:parse seems unable to parse the field queries the same
> way that it does text queries (see below for a demo). Is there any way
> to do this with search:parse or should I write my own parser?
> 
> Here is a simple script to demonstrate this.
> xquery version "1.0-ml";
> import module namespace search =
> "http://marklogic.com/appservices/search"; at
> "/MarkLogic/appservices/search/search.xqy";
> let $options :=<options xmlns="http://marklogic.com/appservices/search";>
>                 <constraint name="DOC">
>                     <word><field name="doc-field"/></word>
>                 </constraint>
>             </options>
> for $query in ('foo AND bar', 'DOC:foo AND bar', 'DOC:"foo AND bar"',
> 'DOC:(foo AND bar)')
> return fn:concat($query,' => ',xdmp:quote(search:parse($query, $options)))
> 
> results in:
> 
> foo AND bar => <cts:and-query qtextjoin="AND" strength="20"
> xmlns:cts="http://marklogic.com/cts";>
>  <cts:word-query qtextref="cts:text">
>    <cts:text>foo</cts:text>
>  </cts:word-query>
>  <cts:word-query qtextref="cts:text">
>    <cts:text>bar</cts:text>
>  </cts:word-query>
> </cts:and-query>
> DOC:foo AND bar => <cts:and-query qtextjoin="AND" strength="20"
> xmlns:cts="http://marklogic.com/cts";>
>  <cts:field-word-query qtextpre="DOC:" qtextref="cts:annotation">
>    <cts:annotation qtextref="following-sibling::cts:text"/>
>    <cts:field>doc-field</cts:field>
>    <cts:text>foo</cts:text>
>  </cts:field-word-query>
>  <cts:word-query qtextref="cts:text">
>    <cts:text>bar</cts:text>
>  </cts:word-query>
> </cts:and-query>
> DOC:"foo AND bar" => <cts:field-word-query qtextpre="DOC:"
> qtextref="cts:annotation" xmlns:cts="http://marklogic.com/cts";>
>  <cts:annotation qtextpre="&quot;"
> qtextref="following-sibling::cts:text" qtextpost="&quot;"/>
>  <cts:field>doc-field</cts:field>
>  <cts:text>foo AND bar</cts:text>
> </cts:field-word-query>
> DOC:(foo AND bar) => <cts:field-word-query qtextpre="DOC:"
> qtextref="cts:annotation" xmlns:cts="http://marklogic.com/cts";>
>  <cts:annotation qtextref="following-sibling::cts:text"/>
>  <cts:field>doc-field</cts:field>
>  <cts:text>foo bar</cts:text>
> </cts:field-word-query>
> 
> Best regards,
> Majid Valipour
> Scholars Portal
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to