Skip to content

Commit 801a59e

Browse files
committed
output whole paragraphs in summary hit-list; make summary default view
1 parent 602bf8e commit 801a59e

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

modules/search.xql

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare variable $dq:CHARS_KWIC := 80;
2020
Templating function: process the query.
2121
:)
2222
declare
23-
%public %templates:default("field", "all") %templates:default("view", "kwic")
23+
%public %templates:default("field", "all") %templates:default("view", "summary")
2424
function 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)
4545
as 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>

search.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
<label for="field" class="control-label col-sm-2">in</label>
1313
<div class="col-sm-10">
1414
<select name="field" class="form-control templates:form-control">
15-
<option value="all" selected="selected">All</option>
15+
<option value="all" selected="selected">All Contents</option>
1616
<option value="title">Headings Only</option>
1717
</select>
1818
</div>
1919
</div>
2020
<div class="form-group">
21-
<label for="view" class="control-label col-sm-2">View</label>
21+
<label for="view" class="control-label col-sm-2">and display as</label>
2222
<div class="col-sm-10">
2323
<select name="view" class="form-control templates:form-control">
24-
<option value="summary">Summary</option>
25-
<option value="kwic" selected="selected">Concordance</option>
24+
<option value="summary" selected="selected">Summary</option>
25+
<option value="kwic">Concordance</option>
2626
</select>
2727
</div>
2828
</div>

0 commit comments

Comments
 (0)