Full-Text search, how to mark whole phrases
Friday, 19 April 2013 · 3 messages
BM
Bartosz Marciniak19 Apr 2013 11:25 #
Hi,
I have placed small document in database with enabled full-text index: <text>
Text with hello world phrase.
</text>
The following expression:
ft:mark(db:open('simple')//*[text() contains text 'hello world'])
produces:
<text>Text with <mark>hello</mark> <mark>world</mark> phrase.</text>
Is it possible to enclose result in one element
<mark>hello world</mark> ?
Regards
Bartosz MarciniakCG
Christian Grün19 Apr 2013 15:36 #
Hi Bartosz,
Quoted text · Bartosz Marciniak · 2 lines
> Is it possible to enclose result in one element > <mark>hello world</mark> ?
unfortunately this is not possible, because at the stage of marking the terms, we don’t have any information if the matched terms were the result of a single or phrase search. If all of your adjacent query terms will be the result of phrase queries, you could rewrite your result with some additional XQuery code (using e.g. a transform expression [1]).
Hope this helps,
Christian
[1] http://docs.basex.org/wiki/XQuery_Update#transform
LQ
Quoted text · Bartosz Marciniak · 3 lines
On Fri, 2013-04-19 at 11:25 +0200, Bartosz Marciniak wrote: > Is it possible to enclose result in one element > <mark>hello world</mark> ?
In general this is not possible using XQuery and XPath Full Text 1.0, and it's the single most-requested feature for a future version.
Many vendors provide an extension to do "match highlighting" including BaseX:
http://docs.basex.org/wiki/Full-Text_Module
Liam
--
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
Written for BaseX 7.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery