[PATCH] fix hyperdoc sorting in search result

1 view
Skip to first unread message

Qian Yun

unread,
Oct 2, 2023, 4:35:51 AM10/2/23
to fricas-devel
In HyperDoc, when using search functionality, for example:
click "Browse" -> type "Integer" in search bar -> click "Reference"
The result page is sorting matching count by only 1 digit:

The underlying shell command is:

$FRICAS/lib/hthits Integer $FRICAS/share/hypertex/pages/ht.db |
sort -r -n -k 1.22

Some results are:

\newsearchresultentry{9}{9.38.3. Some Number Theoretic
Functions}{ugxIntegerNTPage}
\newsearchresultentry{9}{9.21 Expression}{ExpressionXmpPage}
\newsearchresultentry{9}{2.2.5. Abbreviations}{ugTypesWritingAbbrPage}
\newsearchresultentry{8}{9.60 Octonion}{OctonionXmpPage}
\newsearchresultentry{8}{9.38 Integer}{IntegerXmpPage}
......
\newsearchresultentry{3}{6.7. Functions vs. Operations}{ugUserDecOpersPage}
\newsearchresultentry{35}{2.1.1. Domain
Constructors}{ugTypesBasicDomainConsPage}
......

This can be fixed by following patch.

- Qian


diff --git a/src/hyper/htsearch b/src/hyper/htsearch
index 8958c89b..24e67d38 100755
--- a/src/hyper/htsearch
+++ b/src/hyper/htsearch
@@ -8,5 +8,5 @@ if test -z "$1"
then
echo ""|$htbindir/presea use_case=1 -
else
-( cd $htpagedir; $htbindir/hthits "$1" $htpagedir/ht.db |sort -r -n -k
1.22 |$htbindir/presea use_case=0 expr="$1" -)
+( cd $htpagedir; $htbindir/hthits "$1" $htpagedir/ht.db |sort -r -n -t
{ -k 2 |$htbindir/presea use_case=0 expr="$1" -)
fi

Waldek Hebisch

unread,
Oct 8, 2023, 10:33:51 AM10/8/23
to fricas...@googlegroups.com
On Mon, Oct 02, 2023 at 04:35:47PM +0800, Qian Yun wrote:
> In HyperDoc, when using search functionality, for example:
> click "Browse" -> type "Integer" in search bar -> click "Reference"
> The result page is sorting matching count by only 1 digit:
>
> The underlying shell command is:
>
> $FRICAS/lib/hthits Integer $FRICAS/share/hypertex/pages/ht.db | sort -r
> -n -k 1.22

AFAICS this is "off by one" error, sort command should be

sort -r -n -k 1.23

<snip>

> This can be fixed by following patch.
>
> - Qian
>
>
> diff --git a/src/hyper/htsearch b/src/hyper/htsearch
> index 8958c89b..24e67d38 100755
> --- a/src/hyper/htsearch
> +++ b/src/hyper/htsearch
> @@ -8,5 +8,5 @@ if test -z "$1"
> then
> echo ""|$htbindir/presea use_case=1 -
> else
> -( cd $htpagedir; $htbindir/hthits "$1" $htpagedir/ht.db |sort -r -n -k 1.22
> |$htbindir/presea use_case=0 expr="$1" -)
> +( cd $htpagedir; $htbindir/hthits "$1" $htpagedir/ht.db |sort -r -n -t { -k
> 2 |$htbindir/presea use_case=0 expr="$1" -)
> fi

You propose to use 'sort -r -n -t { -k 2'. Assuming that this works as intended it shoud be independent of count of characters, which is
good. However, Posix contains the following definition of '-t':

-t char
Use char as the field separator character; char shall not be
considered to be part of a field (although it can be included
in a sort key). Each occurrence of char shall be significant

The phrase "although it can be included in a sort key" suggests that
some implementations of 'sort' include separator char as part of the
field, this would defeat the purpose. Given the spec using counts
looks safer.

--
Waldek Hebisch

Qian Yun

unread,
Oct 9, 2023, 5:52:00 AM10/9/23
to fricas...@googlegroups.com


On 10/8/23 22:33, Waldek Hebisch wrote:
> On Mon, Oct 02, 2023 at 04:35:47PM +0800, Qian Yun wrote:
>> In HyperDoc, when using search functionality, for example:
>> click "Browse" -> type "Integer" in search bar -> click "Reference"
>> The result page is sorting matching count by only 1 digit:
>>
>> The underlying shell command is:
>>
>> $FRICAS/lib/hthits Integer $FRICAS/share/hypertex/pages/ht.db | sort -r
>> -n -k 1.22
>
> AFAICS this is "off by one" error, sort command should be
>
> sort -r -n -k 1.23
>

Yes, you are right. You should commit this change.

- Qian
Reply all
Reply to author
Forward
0 new messages