[xquery-talk] exist xquery search

Adam Retter adam.retter at googlemail.com
Thu Oct 25 05:24:20 PDT 2012


Im not quite sure what the context of your query is, but this really
does not look right to me. I would try inverting the order of
execution, you can often use the set operators like union or intersect
to bring together faceted queries -

e.g.

let $base := if($person) then
//foo/bar[contributions/person/@val = $person]
else
//foo/bar
return

let $next := if($other) then
//foo/bar[other = $other]
else
//foo/bar
return

subsequence($base intersect $next, $off, $num)

Another option is actually to build your predicates as a string using
concatenation, and then use util:eval to evaluate the query.


On 25 October 2012 12:37, Michael Jones <michaelj491 at gmail.com> wrote:
> Hi,
>
> I'm trying to write a faceted search with exist and xquery. What I have so
> far is:
>
> xquery version "1.0";
> declare namespace request="http://exist-db.org/xquery/request";
> declare namespace xs="http://www.w3.org/2001/XMLSchema";
> declare option exist:serialize "method=xml media-type=text/xml
> omit-xml-declaration=no indent=yes";
>
> let $label:= request:get-parameter("l",'0')
> let $dateTo:= request:get-parameter("dt",'0')
> let $dateFrom := request:get-parameter("df",'0')
> let $person := request:get-parameter("p",'0')
> let $officesHeld := request:get-parameter("o",'0')
> let $off := request:get-parameter("off",'0')
> let $num := request:get-parameter("num",'10')
>
> return
> <xml>
> {
> subsequence(//foo/bar[
>
> (: label :)
>   (if ($label = '0')
>   then (
>   *
> )else(
> label/@val = $label
> ))
>
> and
> (: person :)
> (if ($person = '0')
> then (
>   *
>   )else(
>   contributions/person/@val = $person
>   ))
> and
> (: offices held :)
> (if ($officesHeld = '0')
> then (
>   *
>   )else(
>   contributions/offices_held/@val = $officesHeld
>   ))
>   ],$off,$num)
> }
> </xml>
>
> On my local machine this runs fine but on my server I get FORG0001:
> xs:string(0) is not a sub-type of xs:double [at line 18, column 9]. Also the
> performance is really bad. Is there a better way to do a faceted search? I
> want to say, if there is a parameter in the URL that matches $person then
> search for a person that matches something similar to the value of the
> person element. And if the parameter isn't in the url don't search for it,
> the way I thought about getting around that is by putting in *, and then
> building up a search query based on that. But this seems really inefficient.
> I haven't fully done an index of the exist-db yet. But can anyone see a
> better way to do this search?
>
> Thanks
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk



-- 
Adam Retter

skype: adam.retter
tweet: adamretter
http://www.adamretter.org.uk


More information about the talk mailing list