[ "${PATH_INFO%\[search\]}" = "$PATH_INFO" ] && return 1
. "$_EXEC/cgilite/storage.sh"
+. "$_EXEC/db23.sh"
I="$_DATA/index"
words="$( GET q | awk '
{ for (n = 1; n <= NF; n++) printf "%s ", tolower($n); }
')"
+searchteaser() {
+ local file="$1" words db3_data
+ local w l nc nl hits mhits cont mcont
+ shift 1; words="$*"
+
+ for w in ${words}; do
+ grep -hiwnF "$w" "$file"
+ done \
+ | sort -t: -k1 -n \
+ | { nc=-1 hits=0 mhits=0
+ while read -r l; do
+ nl="$nc" nc="${l%%:*}"
+ if [ $nc -eq $nl ]; then
+ hits=$((hits + 1))
+ elif [ $nc -eq $((nl + 1 )) ]; then
+ hits=$((hits + 1))
+ cont="${cont}${BR}${l#*:}"
+ elif [ $hits -gt $mhits ]; then
+ mhits="$hits" mcont="$cont"
+ hits=1 cont="${l#*:}"
+ else
+ hits=1 cont="${l#*:}"
+ fi
+ done
+
+ [ $hits -gt $mhits ] \
+ && STRING "$cont" \
+ || STRING "$mcont"
+ }
+}
+
for w in ${words}; do
[ ! -f "$I/$w" ] && continue
[ "${page%/:*/}" = "${page%/:${LANGUAGE}/}" ] || continue
fi
acl_read "$page" || continue
- printf '%s\n' "$page"
+ printf '%s %s\n' "$doc" "$(searchteaser "$(mdfile "$page")" $words)"
done \
| theme_search "${words% }"
theme_search(){
local words="$*"
- # STDIN: read result pages line by line
+ # STDIN: [STRING page][TAB][STRING teaser]
theme_page - "$(_ Search results): ${words}" <<-EOF
<article>
<input type="search" name="q" value="$(HTML $words)"><button class="search" type="submit">$(_ Search)</button>
</form>
<ol class="searchresults">
- $( while read p; do
- printf '<li><a href="%s">%s</a></li>' "$(URL "$p")" "$(HTML "$p")"
+ $(while read -r p t; do
+ path="$(UNSTRING "$p")" pfrag="${path%/}" title=''
+ while [ "$pfrag" ]; do
+ title="$(page_title "$pfrag")/$title"
+ pfrag="${pfrag%/*}"
+ done
+ printf '<li><a href="%s">%s</a><p>%s</p></li>' \
+ "$(URL "$path")" "$(HTML "/$title")" "$(UNSTRING "$t" |HTML)"
done)
</ol>
</article>