forked from abaevdict/abaev-basex
fixed search to work correctly
This commit is contained in:
parent
7b35bf2e83
commit
ad87bf327e
2 changed files with 34 additions and 30 deletions
|
@ -282,25 +282,21 @@ declare function abv-m:mark-element($doc as document-node(), $path as xs:string)
|
|||
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)}}
|
||||
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}]
|
||||
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))})
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue