[xquery-talk] search mechanism
Peter Mueller
Peter.Mueller10 at gmx.de
Thu Apr 6 20:15:58 PDT 2006
Hi Wolfgang,
> Guessing from the unusual &= operator, I assume you are using eXist,
true! :-)
> which provides a nice "eval" function. To handle dynamic expressions
> like these, it is sometimes easier to construct the user query as a
> string, then pass it to util:eval to get an intermediate result, which
> can be further processed by the main XQuery. For example:
>
> let $query := construct-query-from-params()
> let $result := util:eval($query)
> for $doc in $result
> order by fn:year-from-date($doc//date) descending
> return $doc
What about this query?
for $doc in //text
where $doc//abstract &= 'peter' and $doc//date &= 'java'
order by $doc//date
return xs:string($doc/@id)
At least it seems to do what I want it to. I would just create this entire
query string and then pass it to the service.compile() method. Is there
something wrong with doing it this way?
> > Second, I only want to show the first 10 hits to the user and generate
> links
> > ( [11-20] [21-30] etc.) to allow accessing the rest.
> >
> > So far I am thinking about storing the start- and stop-position plus all
> (up
> > to 4 queries) that have led to the results with each link.
>
> If this is going to be a web application, one possibility would be to
> store the results in the HTTP session. This should not be a problem if
> you are just keeping references to nodes stored in the db. Again,
> there are functions for this job. For example, my little sandbox app
> (http://demo.exist-db.org/sandbox/sandbox.xql - code is in the
> distribution) first only returns the number of hits for the query and
> stores the result set into the session:
>
> let $results := util:eval($qu)
> return (
> request:set-session-attribute("cached", $results),
> <result hits="{count($results)}" />
> )
>
> Later, the items are retrieved asychronously by a background
> Javascript and passed to a stylesheet:
>
> let $cached := request:get-session-attribute("cached")
> let $item :=
> <item num="{$num}">
> {$cached[$num]}
> </item>
> return
> transform:transform($item, doc($sandbox:XML_HIGHLIGHT_STYLE), ())
Thank you for your hint! But couldn't this approach cause problems if a user
opens up a second window (e.g. in IE) and starts a second search within the
same session?
Best regards,
Peter
--
GMX Produkte empfehlen und ganz einfach Geld verdienen!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
More information about the talk
mailing list