dronefly-garden / dronefly

Red Discord Bot V3 cogs for naturalists.
Other
16 stars 3 forks source link

search taxon: show matched term when not scientific/preferred name #122

Open synrg opened 4 years ago

synrg commented 4 years ago

When a taxon search matches neither the scientific name nor the preferred name, ,search taxon should show the name that was actually matched in the search results, and also in the taxon display itself once the entry is selected. Compare:

image

and:

image

Cope's won't show for a ,t hyla versicolor query (because it correctly matches the Complex first), but without displaying the name, it is not apparent to people looking at the search results and/or pressing letter C to select it, why that even matched what the user typed.

The issue with the matched name not showing in the search results is that although format_taxon_name() (called in search.py get_taxon()) does pass with_term=True, that will only include the term if it is part of the taxon record, and for some reason with this particular query, it is not. Looking at the API call results:

https://api.inaturalist.org/v1/search?q=hyla%20versicolor&sources=taxa

It's returning this for the 3rd match:

    "matched_term": "Hyla chrysoscelis",

I don't think we can do any better! It might be worth asking an iNat dev why it returns this and not "Hyla versicolor", as expected.

But the issue with the matched name not showing in the selected entry is that it is displayed by calling the taxon() command itself on the taxon_id of the result, which does a whole separate search by id# instead of using search terms, so there's no way to get the terms communicated down to the taxon command. If the matched_term were correctly returned, what we should be doing instead to display a selected entry is taking the taxon record that was returned by the search and using that to populate the taxon embed with with_term=True, instead of looking it up again by taxon_id.