[xquery-talk] search mechanism
Michael Kay
mhk at mhk.me.uk
Thu Apr 6 13:13:13 PDT 2006
Yes, you can certainly do this in a single query. I would be inclined to
generate the query dynamically rather than trying to write a generic query
driven by parameters. Just combine all the different search terms into a
single predicate or "where" clause with the terms joined by "and" and "or"
operators.
Splitting the result into pages can be a bit tricky. You have to choose
between two approaches: (a) running the whole query, placing the results
into some temporary document, and then allowing the user to page through
that document, and (b) re-running the query each time the user hits "next
page" and using a query parameter to filter the output positionally. (But
some XQuery engines might support some kind of cursor functionality which
makes this easier and more efficient - Tamino does, for example.)
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: talk-bounces at xquery.com
> [mailto:talk-bounces at xquery.com] On Behalf Of Peter Mueller
> Sent: 06 April 2006 11:10
> To: talk at xquery.com
> Subject: [xquery-talk] search mechanism
>
> Hello together,
>
> I am quite new to XQuery and could need some expert opinion.
>
> I am trying to implement a search mechanism like those in
> library systems
> where you can combine several queries with AND/OR-operators
> (for instance
> search for search_term1 in the titles AND search_term2 in the
> abstracts and
> so on ...
>
> So far I have been performing the following steps:
>
> 1) done several queries separately like the following:
>
> for $doc in //text/abstract
> &= 'search_string'
> return xs:string($doc/ancestor::text/@id)
>
> 2) stored the IDs of the documents in Java-Hashtables (one
> for each query)
>
> 3) combined these ID-Hashtables according to the operators
> set by the users
>
> 4) then searched the documents that belong to the accumulated
> IDs with the
> following query:
>
> for $doc in //text[@id='id1'] | //text[@id='id2'] ...
> order by fn:year-from-date($doc//date)
> descending return $doc
>
> This does work but seems rather complicated to me!
> What do you think?
> I would think that it should be possible (and better?) to do
> this entirely
> in one single XQuery ...?
>
>
> 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.
>
> Again, this seems rather complicated to me, but I can't think
> of anything
> else. Do you have any suggestions for me?
>
> Thanks for every hint!
>
> Ciao,
> Peter
>
> --
> Analog-/ISDN-Nutzer sparen mit GMX SmartSurfer bis zu 70%!
> Kostenlos downloaden: http://www.gmx.net/de/go/smartsurfer
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
>
More information about the talk
mailing list