forked from abaevdict/abaev-basex
134 lines
No EOL
4.5 KiB
Text
134 lines
No EOL
4.5 KiB
Text
module namespace search = 'http://ossetic-studies.org/ns/abaevdict-site/search';
|
|
|
|
declare namespace tei = "http://www.tei-c.org/ns/1.0";
|
|
|
|
import module namespace abv-m = 'http://ossetic-studies.org/ns/abaevdict-mod' at '../../abv-mod.xqm';
|
|
|
|
declare variable $search:types :=
|
|
(
|
|
{
|
|
'query': ".//text() contains text {'$'}",
|
|
'ru': 'Везде',
|
|
'en': 'All'
|
|
},
|
|
{
|
|
'query': ".//tei:form/tei:orth//text() contains text {'$'}",
|
|
'ru': 'Формы',
|
|
'en': 'Forms'
|
|
},
|
|
{
|
|
'query': ".//tei:cit[@type='translationEquivalent']//text() contains text {'$'}",
|
|
'ru': 'Значения',
|
|
'en': 'Meanings'
|
|
},
|
|
{
|
|
'query': ".//tei:cit[@type='example']/tei:quote//text() contains text {'$'}",
|
|
'ru': 'Примеры',
|
|
'en': 'Examples'
|
|
},
|
|
{
|
|
'query': ".//tei:cit[@type='translation']//text() contains text {'$'}",
|
|
'ru': 'Переводы',
|
|
'en': 'Translations'
|
|
},
|
|
{
|
|
'query': ".//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)/text() contains text {'$'}",
|
|
'ru': 'Цит. формы',
|
|
'en': 'Mentioned'
|
|
},
|
|
{
|
|
'query': ".//tei:gloss//text() contains text {'$'}",
|
|
'ru': 'Глоссы',
|
|
'en': 'Glosses'
|
|
},
|
|
{
|
|
'query': "./tei:etym[1]//text() contains text {'$'}",
|
|
'ru': 'Этимологии',
|
|
'en': 'Etymology'
|
|
},
|
|
{
|
|
'query': "$",
|
|
'ru': 'XQuery',
|
|
'en': 'XQuery'
|
|
}
|
|
);
|
|
|
|
(: GET SEARCH RESULTS :)
|
|
|
|
declare function search:content($lang as xs:string,
|
|
$pattern as xs:string? := (),
|
|
$text as xs:string? := ()) {
|
|
<form role="search" id="abv-search"
|
|
hx-post=""
|
|
hx-select="main"
|
|
hx-target="main"
|
|
hx-swap="outerHTML"
|
|
hx-push-url="true">
|
|
<select name="pattern" required="1">
|
|
{
|
|
for $opt in $search:types
|
|
return
|
|
<option value="{$opt('query')}">
|
|
{
|
|
if ($pattern = $opt('query')) then
|
|
attribute selected {'1'},
|
|
if ($lang = 'ru') then $opt('ru')
|
|
else $opt('en')
|
|
}
|
|
</option>
|
|
}
|
|
</select>
|
|
<input name="text" required="1"
|
|
placeholder="{if ($lang = 'ru') then 'Искать' else 'Search'}"
|
|
value="{$text}"
|
|
aria-label="Search">
|
|
{if (exists(session:get('searchQuery'))) then
|
|
attribute disabled {"1"} }
|
|
</input>
|
|
<input type="submit" value="Submit"/>
|
|
</form>,
|
|
<table hx-boost="true" id="abv-search-results">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">{if ($lang = 'ru') then 'Лексема' else 'Lemma'}</th>
|
|
<th scope="col">{if ($lang = 'ru') then 'Перевод' else 'Translation'}</th>
|
|
<th scope="col">{if ($lang = 'ru') then 'Контекст' else 'Context'}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{if (exists($pattern) and exists($text)) then
|
|
let $entries := abv-m:collection($lang,'xml')/tei:entry
|
|
let $query := replace($pattern, "\$", $text)
|
|
let $hits :=
|
|
ft:mark(xquery:eval(`declare namespace tei = "http://www.tei-c.org/ns/1.0";
|
|
declare namespace abv = "http://ossetic-studies.org/ns/abaevdict";
|
|
.[{$query}]`, {'': $entries}))
|
|
for $hit in $hits
|
|
order by abv-m:sortKey($hit/tei:form[1]/tei:orth[1]/text())
|
|
return
|
|
<tr>
|
|
<td>
|
|
<a href="/{$lang}/dictionary?query={$query}#{$hit/@xml:id}">
|
|
{$hit/tei:form[1]/tei:orth[1]}
|
|
</a>
|
|
</td>
|
|
<td>
|
|
{
|
|
string-join(
|
|
data($hit/tei:sense
|
|
/(tei:sense|tei:sense/tei:sense|.)/tei:cit/tei:quote),
|
|
', '
|
|
)
|
|
}
|
|
</td>
|
|
<td>
|
|
{
|
|
if (count($hit//*[tei:mark]) > 0) then
|
|
util:strip-namespaces(($hit//*[tei:mark])[1])/child::node()
|
|
}
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
}; |