[xquery-talk] Looking for help restricting results per input?

Andrew Welch andrew.j.welch at gmail.com
Mon Sep 24 01:59:21 PDT 2012

On 24 September 2012 07:47, Jeremy Botto <fishtankbeta at gmail.com> wrote:
> let $keywords := ("keyworda", "keywordb", "keywordc")
> for $keyword in $keywords,
> $v in doc('test')//document/item
> where $v/quote contains text {$keyword}
> return (<re>
> {$v/comment}
> {$v/buyer}</re>)
> There are three things I am trying to add to this query:
> 1) I'd like to get only two results per $keyword in $keywords, but I am
> currently getting 20-30 results per keyword.

You've got a "cartesian cross product" in your for expression.... is
that really what you want?

> 2) I'd like to search for case-insensitive keywords.

Covert both items to lower-case() before comparing, or use your xquery
vendors custom extensions.

> 3) Because I am trying to receive only 2 results, I want to prioritize
> results whose 'quote' element also contain round braces "(" and ")".

Use order by - if if the quote contains round brackets return 1 else
return 0, then sort by number descending.

Andrew Welch

More information about the talk mailing list