@@ -20,7 +20,7 @@ declare variable $dq:CHARS_KWIC := 80;
2020 Templating function: process the query.
2121:)
2222declare
23- %public %templates:default("field" , "all" ) %templates:default("view" , "kwic " )
23+ %public %templates:default("field" , "all" ) %templates:default("view" , "summary " )
2424function dq:query ($node as node ()*, $model as map (*), $q as xs:string?, $field as xs:string, $view as xs:string) {
2525 if ($q) then
2626 let $hits := dq:do-query (collection ($config:data-root), $q, $field)
@@ -41,21 +41,45 @@ function dq:query($node as node()*, $model as map(*), $q as xs:string?, $field a
4141 Display the hits: this function iterates through all hits and calls
4242 kwic:summarize to print out a summary of each match.
4343:)
44- declare %private function dq:print ($hit as element (), $search-params as xs:string, $mode as xs:string)
44+ declare %private function dq:print ($hit as element (), $search-params as xs:string, $view as xs:string)
4545as element ()* {
4646 let $nodeId := util:node-id ($hit)
47- let $uri := util:document-name (root ($hit)) || "?" ||
47+ let $uri := util:document-name (root ($hit)) || "?" ||
4848 $search-params || "& id=D" || $nodeId || "#D" || $nodeId
4949 let $config :=
50- <config xmlns = "" width = "{if ($mode eq 'summary' ) then $dq:CHARS_SUMMARY else $dq:CHARS_KWIC} "
51- table = "{if ($mode eq 'summary' ) then 'no' else 'yes' } "
50+ <config xmlns = "" width = "{if ($view eq 'summary' ) then $dq:CHARS_SUMMARY else $dq:CHARS_KWIC} "
51+ table = "{if ($view eq 'summary' ) then 'no' else 'yes' } "
5252 link = "{$uri} " />
5353 let $matches := kwic:get-matches ($hit)
54- for $ancestor in ($matches/ancestor::para | $matches/ancestor::title | $matches/ancestor::td |
55- $matches/ancestor::note[not (para)])
56- for $match in $ancestor//exist:match
5754 return
58- kwic:get-summary ($ancestor, $match, $config)
55+ if ($view eq "kwic" ) then
56+ for $ancestor in ($matches/ancestor::para | $matches/ancestor::title | $matches/ancestor::td | $matches/ancestor::note[not (para)])
57+ for $match in $ancestor//exist:match
58+ return
59+ kwic:get-summary ($ancestor, $match, $config)
60+ else
61+ let $ancestors := ($matches/ancestor::para | $matches/ancestor::title | $matches/ancestor::td | $matches/ancestor::note[not (para)])
62+ return
63+ for $ancestor in $ancestors
64+ return
65+ dq:match-to-copy ($ancestor)
66+ };
67+
68+ declare function dq:match-to-copy ($element as element ())
69+ as element ()
70+ {
71+ element { node-name ($element) } {
72+ $element/@*,
73+ for $child in $element/node ()
74+ return
75+ if ($child instance of element ()) then
76+ if ($child instance of element (exist:match)) then
77+ <mark>{ $child/string () }</mark>
78+ else
79+ dq:match-to-copy ($child)
80+ else
81+ $child
82+ }
5983};
6084
6185(:~
@@ -79,20 +103,20 @@ declare %private function dq:print-headings($section as element()*, $search-para
79103(:~
80104 Display the query results.
81105:)
82- declare %private function dq:print-results ($hits as element ()*, $search-params as xs:string, $mode as xs:string) {
106+ declare %private function dq:print-results ($hits as element ()*, $search-params as xs:string, $view as xs:string) {
83107 <div id = "f-results" >
84108 <p class = "heading" >Found {count ($hits)} result{
85109 if (count ($hits) eq 1 ) then "" else "s" }.</p>
86110 {
87- if ($mode eq 'summary' ) then
111+ if ($view eq 'summary' ) then
88112 for $section in $hits
89113 let $score := ft:score ($section)
90114 order by $score descending
91115 return
92116 <div class = "section" >
93117 <span class = "score" >Score: {round-half-to-even ($score, 2 )}</span>
94118 <div class = "headings" >{ dq:print-headings ($section, $search-params) }</div>
95- { dq:print ($section, $search-params, $mode ) }
119+ { dq:print ($section, $search-params, $view ) }
96120 </div>
97121 else
98122 <table class = "kwic" >
@@ -105,7 +129,7 @@ declare %private function dq:print-results($hits as element()*, $search-params a
105129 {dq:print-headings ($section, $search-params)}
106130 </td>
107131 </tr>,
108- dq:print ($section, $search-params, $mode )
132+ dq:print ($section, $search-params, $view )
109133 )
110134 }
111135 </table>
0 commit comments