implemented full-text search
This commit is contained in:
parent
947fe623da
commit
9b42996cef
6 changed files with 203 additions and 15 deletions
|
@ -267,4 +267,40 @@ declare function abv-m:langname-by-id($id as xs:string, $lang as xs:string) {
|
|||
|
||||
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) {
|
||||
let $doc-tr := $doc transform with {
|
||||
for $n in xquery:eval($path, {'': .})
|
||||
return replace node $n
|
||||
with <abv:mark>{$n}</abv:mark>
|
||||
}
|
||||
return $doc-tr
|
||||
};
|
||||
|
||||
(: Function to search, used in API and elsewhere :)
|
||||
declare function abv-m:search($db-lang as xs:string,
|
||||
$type as xs:string,
|
||||
$query as xs:string) {
|
||||
let $pexpr := string-join(
|
||||
('declare namespace tei = "http://www.tei-c.org/ns/1.0";',
|
||||
switch($type)
|
||||
case "full" return "//text()"
|
||||
case "form" return "/tei:entry[1]/tei:form/tei:orth"
|
||||
case "sense" return "/tei:entry[1]/tei:sense"
|
||||
case "example" return "/tei:entry[1]//tei:cit[@type='example']/tei:quote"
|
||||
case "translation" return "/tei:entry[1]//tei:cit[@type='translation']"
|
||||
case "mentioned" return "/tei:entry[1]//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)"
|
||||
case "gloss" return "tei:entry[1]//tei:gloss"
|
||||
case "etym" return "tei:entry[1]/tei:etym[1]//text()"
|
||||
default return "//text()")
|
||||
)
|
||||
return array{for $doc in collection(`abaevdict_{$db-lang}/xml`)
|
||||
let $hits := for $node in xquery:eval($pexpr, {'': $doc})
|
||||
where $node contains text {$query}
|
||||
return path($node)
|
||||
where count($hits) > 0
|
||||
order by abv-m:sortKey($doc/tei:entry[1]/tei:form[1]/tei:orth[1])
|
||||
return {'entry_id': string($doc/tei:entry[1]/@xml:id),
|
||||
'path': array:build($hits)}}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue