Incorrect Browser Search Results?

Environment Info

Anki 2.1.50 (c96ef8cd) Python 3.9.7 Qt 6.2.3 PyQt 6.2.3
Platform: Mac 12.0.1
Flags: frz=True ao=False sv=3
Add-ons, last update check: 2022-04-15 20:17:52


===Add-ons (active)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
BetterSearch ['1052724801', 2022-01-25T17:25, 'None', '']
Field AutoComplete ['511710206', 2022-04-15T07:02, 'None', mod]
Markdown Support - With Batch n Preview Updated ['1259478414', 2022-02-04T05:39, 'None', '']
Quick Field Navigation ['734297936', 2019-12-29T21:24, 'None', '']
True Retention ['613684242', 2017-11-19T15:43, 'None', '']
link Cards Notes and Preview them in extra window ['1423933177', 2021-12-07T10:51, 'None', '']

===IDs of active AnkiWeb add-ons===
1052724801 1259478414 1423933177 511710206 613684242 734297936

===Add-ons (inactive)===
(add-on provided name [Add-on folder, installed at, version, is config changed])
Add Hyperlink ['318752047', 2022-02-08T18:21, 'None', '']
Advanced Browser ['874215009', 2022-01-30T18:07, 'None', '']
AnkiWebView Inspector ['31746032', 2022-04-08T15:44, 'None', '']
Batch Editing ['291119185', 2019-06-02T14:47, 'None', '']
Cloze Overlapper for Anki 21 ['109531687', 2021-01-11T22:12, 'None', '']
Customize Keyboard Shortcuts ['24411424', 2021-12-05T15:39, 'None', '']
Fastbar- with nightmode support ['46611790', 2022-04-14T23:04, 'None', '']
Field History ['1247884413', 2019-01-08T13:34, 'None', '']
Image Occlusion Enhanced for Anki 21 ['1374772155', 2022-04-09T03:15, 'None', '']
Markdown and KaTeX Support ['1087328706', 2022-02-10T11:44, 'None', '']
Mini Format Pack ['295889520', 2018-07-24T13:45, 'None', '']
More Overview Stats 21 ['738807903', 2021-07-30T15:13, 'None', '']
Searching PDF Reading  Note-Taking in Add Dialog ['1781298089', 2021-09-17T06:24, 'None', mod]
Symbols As You Type ['2040501954', 2021-03-21T22:17, 'None', '']
Syntax Highlighting for Code ['1463041493', 2018-10-06T21:31, 'None', '']
Ze Add Note Id ['886709118', 2021-03-02T15:06, 'None', '']
Ze Frozen Fields ['94610912', 2021-02-11T19:06, 'None', '']
extended editor for field for tables searchreplace ['805891399', 2022-03-13T06:51, 'None', '']

Problem

Browser returns unexpected search results. Specifically, the query: w:tin returns a card that has string glutin-is and glutinis, but doesn’t contain exact string tin. As per the manual, w:dog will search for dog but will NOT search for doggy or underdog, so this should be analogous.

I also tried re:\btin\b but it shows the same results (pretty sure that’s to be expected)

Example

This card shows with search query w:tin

(Note fields):


Expected result

Show cards with string tin as distinct word, and exclude cards that don’t search for distinct word tin

Actual result:

Shows cards without tin as a distinct word, but instead shows cards with tin anywhere within a string (like glutin and glutin-is)

Slight clarification

I still get cards that have only tin string only as well, but also incorrectly get cards that can have tin anywhere within, ex.

(note fields)

Try it with Better Search disabled (or preferably with all add-ons disabled).

Make sure there’s no space before tin.

Check the formatting of the sort field, sometimes there’s some cruft in there.

I did start up Anki without add-ons by holding Shift, but for some reason the copy debug still says it’s activated (I think I’ve read this before).

There are no spaces before tin (in the search bar)

I tried checking the format of the sorting field, but for some reason clicking on different note types makes the HTML editor not open/freeze, and there’s like some memory leak that makes fields of some notes “leak” onto the fields of other notes, so the fields and formatting are wrong (could be a reason why the search doesn’t work? Or maybe it’s just purely visual glitch)

Solution

After updating to 2.1.51RC1 the HTML editor works/doesn’t leak when navigating, so I was able to check the HTML editor of the sort field.

I realized that the sort field wasn’t necessarily the problem, since Anki will search all fields. So I checked the HTML editor of the different fields of cards.

Long story short:
w:tin must be equivalent to the RegEx expression: /\btin\b/
this means that Anki is looking for tin , as long as it isn’t before or after any of these characters:

  1. lowercase a-z
  2. uppercase A-Z
  3. any digit 0-9
  4. an underscore _

After looking at HTML editor, the card’s underlying HTML has:

gl<b>u</b>tin-is

i.e. it is valid (and this was the case with all similar cases)

The real problem is that the manual is slightly misleading for this syntax, since it will include “glutin-s”, even though it suggests it wouldn’t. Maybe put an asterisk on that part, and explain that it reads HTML, so formatting can possibly negate this? @dae (sorry to ping)

gl<b>u</b>tin-is

Good catch!

The manual does mention something tangentially related to this…

Anki is only able to search within formatting in the sort field you’ve configured. For example, if you add " example" to one of your fields, this will not be matched when searching for “example” unless that field is the sort field. If a word is not formatted, or the formatting does not change in the middle of the word, then Anki will be able to find it in any field.

…but that doesn’t make it clear that the reverse is also true. I’ve suggested a change to warn users about this. Of course ideally it would be possible to ignore formatting when searching.

Are you sure you’re using the release version of 2.1.50, and not one of the betas? This issue was occurring with 2.1.50 RC3.

2 Likes

Ahh I guess based on the build number c96ef8cd I was using RC3, didn’t even realize haha! Thanks for the info, and getting the word out