Question ft:mark()
Monday, 13 August 2018 · 3 messages
JB
Johannes Bauer13 Aug 2018 07:09 #
Hello,
I have a question regarding the usage of the
ft:mark() function.
Database content:<root>
<div>
<p>Some text <b>text search text</b> some more text</p>
</div>
</root>XQuery:
<result>
{
let $search := 'search'
for $match at $pos in //*[text() contains text {$search}]
let $match_parent := $match/..
return
<match>{ft:mark($match_parent//*[text() contains text {$search}])}</match>
}
</result>Current result:
<result>
<match>
<b>text <mark>search</mark> text</b>
</match>
</result>What I would like to achieve is the following output:
<result>
<match>
<p>Some text <b>text <mark>search</mark> text</b> some more
text</p>
</match>
</result>ft:mark() returns the found element node with the marked content inside.
Is it possible to get the whole paragraph content (the parent element of the found element) with the marker element inside?
Any help would be much appreciated.
Best regards
JohannesCG
Christian Grün13 Aug 2018 14:05 #
Hi Johannes,
Try this:
<result>{
let $search := 'search'
for $match in //*[text() contains text { $search }]
let $match_parent := $match/..
return <match>{
ft:mark($match_parent[.//text() contains text { $search }])
}</match>
}</result>Best,
Christian
Quoted text · Johannes Bauer · 55 lines
On Mon, Aug 13, 2018 at 7:09 AM Johannes Bauer <johannes.bauer at tanner.de> wrote: > Hello, > > I have a question regarding the usage of the ft:mark() function. > > Database content: > > <root> > <div> > <p>Some text <b>text search text</b> some more text</p> > </div> > </root> > > XQuery: > > <result> > { > let $search := 'search' > for $match at $pos in //*[text() contains text {$search}] > let $match_parent := $match/.. > return > <match>{ft:mark($match_parent//*[text() contains text {$search}])}</match> > } > </result> > > Current result: > > <result> > <match> > <b>text <mark>search</mark> text</b> > </match> > </result> > > What I would like to achieve is the following output: > > <result> > <match> > <p>Some text <b>text <mark>search</mark> text</b> some more > text</p> > </match> > </result> > > ft:mark() returns the found element node with the marked content inside. > > Is it possible to get the whole paragraph content (the parent element of > the found element) with the marker element inside? > > Any help would be much appreciated. > > Best regards > Johannes > > >
JB
Johannes Bauer13 Aug 2018 14:44 #
Hi Christian,
thank you.
That works great.
Johannes
Quoted text · Christian Grün · 77 lines
Am 13.08.2018 um 14:05 schrieb Christian Grün: > Hi Johannes, > > Try this: > > <result>{ > let $search := 'search' > for $match in //*[text() contains text { $search }] > let $match_parent := $match/.. > return <match>{ > ft:mark($match_parent[.//text() contains text { $search }]) > }</match> > }</result> > > Best, > Christian > > > > On Mon, Aug 13, 2018 at 7:09 AM Johannes Bauer > <johannes.bauer at tanner.de <mailto:johannes.bauer at tanner.de>> wrote: > > Hello, > > I have a question regarding the usage of the ft:mark() function. > > Database content: > > <root> > <div> > <p>Some text <b>text search text</b> some more text</p> > </div> > </root> > > XQuery: > > <result> > { > let $search := 'search' > for $match at $pos in //*[text() contains text {$search}] > let $match_parent := $match/.. > return > <match>{ft:mark($match_parent//*[text() contains text > {$search}])}</match> > } > </result> > > Current result: > > <result> > <match> > <b>text <mark>search</mark> text</b> > </match> > </result> > > What I would like to achieve is the following output: > > <result> > <match> > <p>Some text <b>text <mark>search</mark> text</b> some more > text</p> > </match> > </result> > > ft:mark() returns the found element node with the marked content > inside. > > Is it possible to get the whole paragraph content (the parent > element of > the found element) with the marker element inside? > > Any help would be much appreciated. > > Best regards > Johannes > >
Written for BaseX 9.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery