diff --git a/bin/dasht b/bin/dasht
index 6d987cb..427f17b 100755
--- a/bin/dasht
+++ b/bin/dasht
@@ -13,7 +13,7 @@
# ### Examples
#
# `dasht`
-# First 100 topics from each installed docset.
+# Topics (A-Z) from each installed docset.
#
# `dasht` 'c - x'
# Search for "c - x" in all installed docsets.
diff --git a/bin/dasht-query-exec b/bin/dasht-query-exec
index 6db063f..92be180 100755
--- a/bin/dasht-query-exec
+++ b/bin/dasht-query-exec
@@ -16,6 +16,9 @@
# located inside a [Dash] docset at `/Contents/Resources/docSet.dsidx`, while
# passing the optional *OPTIONS\_FOR\_SQLITE3* arguments down to sqlite3(1).
#
+# If *PATTERN* is empty or solely consists of unescaped wildcard characters,
+# topics having distinct leading characters are returned from the *DATABASE*.
+#
# ### Searching
#
# SQL LIKE wildcard characters in *PATTERN* can be escaped with a backslash.
@@ -74,18 +77,17 @@ pattern=$(echo "$pattern" | sed "s/'/&&/g")
# You should have received a copy of the GNU General Public License
# along with Zeal. If not, see .
#
+searchIndex_topic=name
searchIndex_query="
- SELECT name,
- type,
+ SELECT name AS name,
+ type AS type,
path AS url
FROM searchIndex
- WHERE name LIKE '$pattern' ESCAPE '\\'
- ORDER BY name COLLATE NOCASE
- LIMIT 100;
"
+ztoken_topic=ztokenname
ztoken_query="
- SELECT ztokenname AS name,
- ztypename AS type,
+ SELECT ztokenname AS name,
+ ztypename AS type,
zpath || ifnull('#' || nullif(zanchor, ''), '') AS url
FROM ztoken
JOIN ztokenmetainformation
@@ -94,9 +96,6 @@ ztoken_query="
ON zfilepath.z_pk = ztokenmetainformation.zfile
JOIN ztokentype
ON ztokentype.z_pk = ztoken.ztokentype
- WHERE ztokenname LIKE '$pattern' ESCAPE '\\'
- ORDER BY ztokenname COLLATE NOCASE
- LIMIT 100;
"
# _ __ ____ ____ _ _
# ___ _ __ __| | ___ / _| / ___| _ \| | ___ ___ __| | ___
@@ -106,9 +105,31 @@ ztoken_query="
#
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-if sqlite3 "$database" .tables | grep -F -q searchIndex
-then query=$searchIndex_query
-else query=$ztoken_query
+if sqlite3 "$database" .tables | grep -F -q searchIndex; then
+ topic=$searchIndex_topic
+ query=$searchIndex_query
+else
+ topic=$ztoken_topic
+ query=$ztoken_query
+fi
+
+if echo "$pattern" | tr -d '%_' | grep -q . ; then
+ # something particular was searched; fetch first 100 matching topics
+ where="WHERE $topic LIKE '$pattern' ESCAPE '\\'"
+ group=
+ limit='LIMIT 100'
+else
+ # nothing particular was searched; group topics by leading character
+ query=$(echo "$query" | awk '
+ # min() gets FIRST topic from each group; else we get the LAST one
+ $1 == "SELECT" && $3 == "AS" { $2 = "min(" $2 " COLLATE NOCASE)" }
+ { print }
+ ')
+ where=
+ group="GROUP BY substr($topic,1,1)"
+ limit=
fi
+order="ORDER BY $topic COLLATE NOCASE"
+query="$query $where $group $order $limit ;"
exec sqlite3 "$@" "$database" "$query"
diff --git a/bin/dasht-query-html b/bin/dasht-query-html
index e533f8c..5d391ab 100755
--- a/bin/dasht-query-html
+++ b/bin/dasht-query-html
@@ -13,7 +13,7 @@
# ### Examples
#
# `dasht-query-html`
-# First 100 topics from each installed docset.
+# Topics (A-Z) from each installed docset.
#
# `dasht-query-html` 'c - x'
# Search for "c - x" in all installed docsets.
@@ -103,6 +103,7 @@ dasht-query-line "$@" | awk -v pattern="$1" '
sub("[[:space:]]+$", "", pattern) # strip trailing whitespace
gsub("[[:space:]]+", ".*", pattern) # treat whitespace as wildcards
pattern = ignorecase(pattern) # emulate IGNORECASE=1 for POSIX
+ if (pattern == "") pattern = "^." # grouped by leading character
}
NR == 1 { print "
" }
$2 == "=" { result[$1] = substr($0, index($0, $2) + length($2) + 1) }
diff --git a/bin/dasht-query-line b/bin/dasht-query-line
index 5b5a44a..c6175d2 100755
--- a/bin/dasht-query-line
+++ b/bin/dasht-query-line
@@ -13,7 +13,7 @@
# ### Examples
#
# `dasht-query-line`
-# First 100 topics from each installed docset.
+# Topics (A-Z) from each installed docset.
#
# `dasht-query-line` 'c - x'
# Search for "c - x" in all installed docsets.
diff --git a/bin/dasht-server-http b/bin/dasht-server-http
index a3e7991..902c4be 100755
--- a/bin/dasht-server-http
+++ b/bin/dasht-server-http
@@ -13,10 +13,10 @@
# ### Examples
#
# printf 'GET / HTTP/1.1\r\n' | `dasht-server-http`
-# Shows first 100 topics from all installed [Dash] docsets.
+# Shows topics (A-Z) from each installed [Dash] docset.
#
# printf 'GET /?docsets=*DOCSETS* HTTP/1.1\r\n' | `dasht-server-http`
-# Shows first 100 topics from installed [Dash] docsets matching *DOCSETS*.
+# Shows topics (A-Z) from installed [Dash] docsets matching *DOCSETS*.
#
# printf 'GET /?query=*PATTERN* HTTP/1.1\r\n' | `dasht-server-http`
# Searches for *PATTERN* in all installed [Dash] docsets.
diff --git a/man/man1/dasht-query-exec.1 b/man/man1/dasht-query-exec.1
index eb1f125..5f14b93 100644
--- a/man/man1/dasht-query-exec.1
+++ b/man/man1/dasht-query-exec.1
@@ -11,6 +11,9 @@ Searches for \fIPATTERN\fP in \fIDATABASE\fP, which is an SQLite3 database file
located inside a Dash \[la]https://kapeli.com/dash\[ra] docset at \fB\fC/Contents/Resources/docSet.dsidx\fR, while
passing the optional \fIOPTIONS_FOR_SQLITE3\fP arguments down to
.BR sqlite3 (1).
+.PP
+If \fIPATTERN\fP is empty or solely consists of unescaped wildcard characters,
+topics having distinct leading characters are returned from the \fIDATABASE\fP\&.
.SS Searching
.PP
SQL LIKE wildcard characters in \fIPATTERN\fP can be escaped with a backslash.
diff --git a/man/man1/dasht-query-html.1 b/man/man1/dasht-query-html.1
index b65f8e2..c48fc85 100644
--- a/man/man1/dasht-query-html.1
+++ b/man/man1/dasht-query-html.1
@@ -8,7 +8,7 @@ dasht\-query\-html \- searches Dash \[la]https://kapeli.com/dash\[ra] docsets an
.SS Examples
.TP
\fB\fCdasht\-query\-html\fR
-First 100 topics from each installed docset.
+Topics (A\-Z) from each installed docset.
.TP
\fB\fCdasht\-query\-html\fR 'c \- x'
Search for "c \- x" in all installed docsets.
diff --git a/man/man1/dasht-query-line.1 b/man/man1/dasht-query-line.1
index c9c6ef6..3aa60b7 100644
--- a/man/man1/dasht-query-line.1
+++ b/man/man1/dasht-query-line.1
@@ -8,7 +8,7 @@ dasht\-query\-line \- searches Dash \[la]https://kapeli.com/dash\[ra] docsets an
.SS Examples
.TP
\fB\fCdasht\-query\-line\fR
-First 100 topics from each installed docset.
+Topics (A\-Z) from each installed docset.
.TP
\fB\fCdasht\-query\-line\fR 'c \- x'
Search for "c \- x" in all installed docsets.
diff --git a/man/man1/dasht-server-http.1 b/man/man1/dasht-server-http.1
index 8998ed3..f9107bf 100644
--- a/man/man1/dasht-server-http.1
+++ b/man/man1/dasht-server-http.1
@@ -9,10 +9,10 @@ dasht\-server\-http \- simple search engine that powers
.SS Examples
.TP
printf 'GET / HTTP/1.1\[rs]r\[rs]n' | \fB\fCdasht\-server\-http\fR
-Shows first 100 topics from all installed Dash \[la]https://kapeli.com/dash\[ra] docsets.
+Shows topics (A\-Z) from each installed Dash \[la]https://kapeli.com/dash\[ra] docset.
.TP
printf 'GET /?docsets=\fIDOCSETS\fP HTTP/1.1\[rs]r\[rs]n' | \fB\fCdasht\-server\-http\fR
-Shows first 100 topics from installed Dash \[la]https://kapeli.com/dash\[ra] docsets matching \fIDOCSETS\fP\&.
+Shows topics (A\-Z) from installed Dash \[la]https://kapeli.com/dash\[ra] docsets matching \fIDOCSETS\fP\&.
.TP
printf 'GET /?query=\fIPATTERN\fP HTTP/1.1\[rs]r\[rs]n' | \fB\fCdasht\-server\-http\fR
Searches for \fIPATTERN\fP in all installed Dash \[la]https://kapeli.com/dash\[ra] docsets.
diff --git a/man/man1/dasht.1 b/man/man1/dasht.1
index fc5b229..e60b861 100644
--- a/man/man1/dasht.1
+++ b/man/man1/dasht.1
@@ -8,7 +8,7 @@ dasht \- API documentation in your terminal
.SS Examples
.TP
\fB\fCdasht\fR
-First 100 topics from each installed docset.
+Topics (A\-Z) from each installed docset.
.TP
\fB\fCdasht\fR 'c \- x'
Search for "c \- x" in all installed docsets.