From: Kemal P. <ke...@pa...> - 2012-01-07 23:46:27
|
Thank you for your reply Ron, it certainly was of great help. The code you supplied worked very well except in cases where a match was found more than once within the same XML element (for instance if the actor’s name was “Christian Bale Christian” :) ). In this case $ancestor//exist:match has two elements which clashes with the cardinality of a function called inside kwic:get-summary. As I see it I have two options here, neither of which is optimal: 1. I can simply call kwic:get-summary with just one of the matches like $ancestor//exist:match[1] This means that I will only highlight the one match. 2. I can use an nested for loop to include all of the matches like for $match in $ancestor//exist:match However this will return a context for each of the matches and they will often even overlap. This gives me a challenge for when I want to display the context and highlight the matches, because ideally I only want to show the text once with all the matches highlighted. 2012/1/7 Ron Van den Branden <ron...@ka...> > Hi, > > > Is it possible to limit the summary returned by kwic:summarize to just >> the XML element where the match was found. >> > > For this, you'll need the more advanced kwic:get-summary() function (< > http://demo.exist-db.org/**exist/functions/kwic/get-**summary<http://demo.exist-db.org/exist/functions/kwic/get-summary> > >). > > > Consider this: <Film> <Title>The Dark Knight</Title> >> <Director>Christopher Nolan</Director> <Star>Christian Bale</Star> >> <Star>Heath Ledger</Star> <Star>Aaron Eckhart</Star> </Film> >> >> Now, if I run this query //Film[ft:query(Star, "Christian")] I would like >> kwic to return <p> <span class="previous"></span> <span >> class="hi">Christian</span> <span class="following"> Bale</span> </p> and >> not give me a chunk of the Director or the next Star elements. >> >> > You could try something like: > > import module namespace kwic="http://exist-db.org/**xquery/kwic<http://exist-db.org/xquery/kwic> > "; > let $nodes := //Film[ft:query(Star, 'Christian')] > let $matches := util:expand($nodes)//exist:**match > for $ancestor in $matches/ancestor::*[1] > return kwic:get-summary($ancestor, $ancestor//exist:match,<config > width="40"/>, ()) > > (based on the example at the top of the KWIC module function documentation > at <http://demo.exist-db.org/**exist/functions/kwic/<http://demo.exist-db.org/exist/functions/kwic/>>, > actually) > > > Please notice that this XML example is purely illustrative and my actual >> database contains many different types of elements so I cannot really do >> any element-specific (i.e. by a specific element-name) filtering. Also >> notice that I am actually interested in the Film element, not Star (and >> indeed may not even know by which sub-element Film was found). >> >> > Hard to tell without knowing about your index configuration and maybe a > short example, but in general, I think the approach in above query should > work: first, find the matching nodes ($nodes), next find all matching text > fragments ($matches), determine the context cutoff point $ancestor, and run > kwic:get-summary(). > > Hope this helps, > > Ron > > -- > Ron Van den Branden > Wetenschappelijk attaché / Senior Researcher > Reviews Editor LLC. The Journal of Digital Scholarship in the Humanities > > Centrum voor Teksteditie en Bronnenstudie - CTB (KANTL) > Centre for Scholarly Editing and Document Studies > Koninklijke Academie voor Nederlandse Taal- en Letterkunde > Royal Academy of Dutch Language and Literature > Koningstraat 18 / b-9000 Gent / Belgium > tel: +32 9 265 93 51 / fax: +32 9 265 93 49 > E-mail : ron...@ka... > http://www.kantl.be/ctb > > |