TeX-Live / texdoc

Find and view documentation in TeX Live
https://tug.org/texdoc/
GNU General Public License v3.0
47 stars 7 forks source link

Fuzzy search should always be attempted #99

Open gucci-on-fleek opened 1 year ago

gucci-on-fleek commented 1 year ago

If you search for the string texbytopi, you would expect that texdoc would open the documentation for the package texbytopic, but instead it tells you that there are no good matches:

$ texdoc -Ml texbytopi
texdoc warning: No good result found, showing all results.
texbytopi   -8.5    /usr/local/texlive/2022/texmf-dist/doc/plain/texbytopic/TeXbyTopic.pdf      The book itself
texbytopi   -9.8    /usr/local/texlive/2022/texmf-dist/doc/plain/texbytopic/README      Readme

But if you mistype any letter, then texdoc counter-intuitively gives a better score and automatically opens the document:

$ texdoc -Ml texbytopz
texbytopz   7.0 /usr/local/texlive/2022/texmf-dist/doc/plain/texbytopic/TeXbyTopic.pdf      The book itself
texbytopz   1.8 /usr/local/texlive/2022/texmf-dist/doc/plain/texbytopic/README      Readme

This is unexpected. @wtsnjp suggests the cause of this in https://github.com/TeX-Live/texdoc/issues/98#issuecomment-1445345710:

The fuzzy search I introduced in Texdoc v3.0 is incomplete. The fuzzy search is only executed when Texdoc fails to find anything in the standard search; in the second case, the fuzzy search is not working because something was found even though only negative matches were found. This is why the results are worse than in the third case (texdoc -lM zezbytopiz).

The fuzzy search should be triggered even when only bad results are found. More to the point, you could always use fuzzy search in any case and, as you say, give an appropriate penalty based on edit distance. However, the latter would require more drastic changes than the former.

wtsnjp commented 1 year ago

I am willing to implement this proposal. This should also resolve #88.