[xquery-talk] making a search case-insensitive

Michael Kay mhk at mhk.me.uk
Thu Jul 27 10:55:21 PDT 2006

The correct way to do this is to search using a caseblind collation, but
I've no idea whether that's a feature that your product supports. 

$keyword and upper-case($keyword) are both strings; you can't apply the "or"
operator to two strings, it works only with boolean operands. So "$keyword
or upper-case($keyword)" will give you a type error.

Similarly, te contains() function tests whether one string is a substring of
another. I suspect when you write contains($text, $kwds) you are imagining
that $kwds is a set of strings and that the function will return true if
$text contains any of them.


(a) to make $kwds be a set (sequence) of strings, do

$kwds := ($keyword, upper-case($keyword), lower-case($keyword), $mixedkwd)

(b) to test if $text contains any of them, do

some $k in $kwds satisfies contains($text, $k)

But wouldn't it be easier simply to test

contains(upper-case($text), upper-case($keyword))


Michael Kay

> -----Original Message-----
> From: talk-bounces at xquery.com 
> [mailto:talk-bounces at xquery.com] On Behalf Of Cindy Girard
> Sent: 27 July 2006 02:18
> To: talk at xquery.com
> Subject: [xquery-talk] making a search case-insensitive
> Hi,
>   I'm using Berkely XMLDB as my search database for one of my
>   projects, and I can't seem to find anything that allows me to
>   specify if I want the search case-sensitive or not. And it's
>   case-sensitive by default.
>   Well, I need it to be case-insensitive, so I'm trying to do it in
>   the xquery instead.
>   I have the following snippet:
>  let $mixedkwd := (concat (upper-case(substring($keyword, 1, 
> 1)), lower-case(substring($keyword, 2)))),
>      $kwds := ($keyword or upper-case($keyword) or 
> lower-case($keyword) or $mixedkwd),
>      $hits :=
>            for $entries in collection($collctn)//tei.2
>                                          let $docname := 
> concat($entries/@id, '.xml')
>                                          let $text := $entries/text
>                                          where contains($text, $kwds)
>    I'm getting an ItemType matching failed error. Can someone correct
>    my syntax, or is there a better way to do this?
>    Thanks,
> -----
> - Cindy  
> Cynthia M. Girard
> IATH, University of Virginia
> clm6u at virginia.edu
> "Danger? I laugh in the face of danger!
> ...and then I hide until it goes away."
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk

More information about the talk mailing list