forked from abaevdict/abaev-basex
search optimizations
This commit is contained in:
parent
10b0f39199
commit
75564a010d
4 changed files with 73 additions and 35 deletions
|
@ -217,7 +217,7 @@ declare function abv-m:insert-full-lang($abbr as node(), $lang as xs:string) {
|
|||
}
|
||||
};
|
||||
|
||||
declare function abv-m:make-html($src as document-node()+,
|
||||
declare function abv-m:make-html($src as node()+,
|
||||
$lang as xs:string)
|
||||
as node()+ {
|
||||
for $doc in $src
|
||||
|
@ -270,12 +270,11 @@ declare function abv-m:entry-form-by-id($id as xs:string) {
|
|||
};
|
||||
|
||||
declare function abv-m:mark-element($doc as document-node(),
|
||||
$path as xs:string,
|
||||
$query as xs:string) {
|
||||
$path as xs:string) {
|
||||
let $doc-tr := $doc transform with {
|
||||
for $n in xquery:eval($path, {'': .})
|
||||
return replace node $n
|
||||
with ft:mark($n[. contains text {$query}])
|
||||
with <mark>{$n}</mark>
|
||||
}
|
||||
return $doc-tr
|
||||
};
|
||||
|
@ -286,19 +285,53 @@ declare function abv-m:search($db-lang as xs:string,
|
|||
$query as xs:string) {
|
||||
let $db-name := `abaevdict_{$db-lang}`
|
||||
let $docs := collection(`{$db-name}/xml`)
|
||||
let $hits := switch($type)
|
||||
case "full" return $docs//text()[. contains text {$query}]
|
||||
case "form" return $docs/tei:entry[1]/tei:form[./tei:orth contains text {$query}]
|
||||
case "sense" return $docs/tei:entry[1]//tei:sense[./tei:cit[@type='translationEquivalent'] contains text {$query}]
|
||||
case "example" return $docs/tei:entry[1]//tei:cit[@type='example']/tei:quote[. contains text {$query}]
|
||||
case "translation" return $docs/tei:entry[1]//tei:cit[@type='translation' and . contains text {$query}]
|
||||
case "mentioned" return $docs/tei:entry[1]//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)[. contains text {$query}]
|
||||
case "gloss" return $docs/tei:entry[1]//tei:gloss[. contains text {$query}]
|
||||
case "etym" return $docs/tei:entry[1]/tei:etym[1][. contains text {$query}]
|
||||
default return $docs//text()[. contains text {$query}]
|
||||
let $test := switch($type)
|
||||
case "full" return
|
||||
fn ($node) {
|
||||
$node//text() contains text {$query}
|
||||
}
|
||||
case "form" return
|
||||
fn ($node) {
|
||||
$node//tei:form/tei:orth//text() contains text {$query}
|
||||
}
|
||||
case "sense" return
|
||||
fn ($node) {
|
||||
$node//tei:cit[@type='translationEquivalent']//text() contains text {$query}
|
||||
}
|
||||
case "example" return
|
||||
fn ($node) {
|
||||
$node//tei:cit[@type='example']/tei:quote//text() contains text {$query}
|
||||
}
|
||||
case "translation" return
|
||||
fn ($node) {
|
||||
$node//tei:cit[@type='translation']//text() contains text {$query}
|
||||
}
|
||||
case "mentioned" return
|
||||
fn ($node) {
|
||||
$node//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)/text() contains text {$query}
|
||||
}
|
||||
case "gloss" return
|
||||
fn ($node) {
|
||||
$node//tei:gloss//text() contains text {$query}
|
||||
}
|
||||
case "etym" return
|
||||
fn ($node) {
|
||||
$node/tei:etym[1]//text() contains text {$query}
|
||||
}
|
||||
default return
|
||||
fn ($node) {
|
||||
$node//text() contains text {$query}
|
||||
}
|
||||
let $hits := $docs//tei:entry[1][$test(.)]
|
||||
return array:build(for $hit in $hits
|
||||
let $entry-id := db:get($db-name,db:path($hit))/tei:entry[1]/string(@xml:id)
|
||||
group by $entry-id
|
||||
order by abv-m:sortKey(abv-m:entry-form-by-id($entry-id))
|
||||
return {'entry': $entry-id, 'nodes': array:build(for $node in $hit return path($node))})
|
||||
let $entry-id := $hit/@xml:id
|
||||
(: group by $entry-id :)
|
||||
let $mark := ft:mark($hit[$test(.)])
|
||||
order by abv-m:sortKey($hit/@xml:id)
|
||||
return {'entry': $entry-id,
|
||||
(: 'nodes': array:build(for $node in $hit return path($node)), :)
|
||||
'tei': ft:mark($hit[$test(.)]),
|
||||
'fragment': <span>{util:strip-namespaces(($mark//*[tei:mark])[1])/child::node()}</span>
|
||||
}
|
||||
)
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue