improved search highlight and fix search

This commit is contained in:
Oleg Belyaev 2025-03-24 16:23:32 +03:00
parent 3855cf6bf0
commit 10b0f39199
3 changed files with 10 additions and 7 deletions

View file

@ -269,11 +269,13 @@ declare function abv-m:entry-form-by-id($id as xs:string) {
doc(`abaevdict_index/lookup.xml`)/tei:table[1]/tei:entry[@xml:id=$id]/text()
};
declare function abv-m:mark-element($doc as document-node(), $path as xs:string) {
declare function abv-m:mark-element($doc as document-node(),
$path as xs:string,
$query as xs:string) {
let $doc-tr := $doc transform with {
for $n in xquery:eval($path, {'': .})
return replace node $n
with <abv:mark>{$n}</abv:mark>
with ft:mark($n[. contains text {$query}])
}
return $doc-tr
};

View file

@ -221,7 +221,6 @@ declare %rest:path("{$lang}/search/prev")
let $n as xs:integer := session:get('searchN')-1
let $r1 := session:set('searchN', $n)
let $sd := session:get('searchData')
let $node := db:get-id(`abaevdict_{$lang}`,$sd[$n])
return page:by-id($lang, $sd($n)('entry'), string-join($sd($n)('nodes'),'|'))
};
@ -232,7 +231,6 @@ declare %rest:path("{$lang}/search/position")
function page:search-position($lang, $p as xs:integer) {
let $r1 := session:set('searchN', $p)
let $sd := session:get('searchData')
let $node := db:get-id(`abaevdict_{$lang}`,$sd[$p])
return page:by-id($lang, $sd($p)('entry'), string-join($sd($p)('nodes'),'|'))
};
@ -519,7 +517,9 @@ declare %rest:path("{$lang}/dict")
{for $doc at $i in $page:sorted
where $i > ($p - 1) * $page:items and $i <= $p * $page:items
let $html := if ($xpath != '' and $entry = $doc/@xml:id)
then abv-m:mark-element(doc(`abaevdict_{$lang}/xml/{$doc/@xml:id}.xml`),$xpath) => abv-m:make-html($lang)
then abv-m:mark-element(
doc(`abaevdict_{$lang}/xml/{$doc/@xml:id}.xml`),
$xpath, session:get('searchQuery')) => abv-m:make-html($lang)
else doc(`abaevdict_{$lang}/html/{$doc/@xml:id}.html`)
return (
(: Block with icons to the left of entry (floating) :)

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:stylesheet xpath-default-namespace=""
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:abv="http://ossetic-studies.org/ns/abaevdict"
@ -24,7 +25,7 @@
</xsl:choose>
</xsl:function>
<xsl:template match="abv:mark">
<xsl:template match="tei:mark">
<mark>
<xsl:apply-templates/>
</mark>