Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default preferred_place based on locale strings with localities #89

Open
pleary opened this issue Aug 29, 2017 · 6 comments
Open

Set default preferred_place based on locale strings with localities #89

pleary opened this issue Aug 29, 2017 · 6 comments
Assignees

Comments

@pleary
Copy link
Member

pleary commented Aug 29, 2017

The local param can include a locality code in addition to the language code (e.g. en-NZ or es-MX). We could lookup the iNaturalist place equivalents to the location portion of the code and use that as a default preferred_place, (e.g. en-NZ sets a default preferred_place_id of 6803, New Zealand's iNat place_id).

I suggest the order of precedence of preferred_place from least to most important:

  • Authenticated user's preferred_place
  • Locality extracted from locale
  • HTTP param preferred_place_id
@kueda
Copy link
Member

kueda commented Jul 17, 2020

So I guess the idea here would be to modify InaturalistAPI.lookupPreferredPlaceMiddleware to do something like look up places in the database by their admin_level and code attributes.

@kueda kueda added the ready label Jul 17, 2020
@viatrix
Copy link
Contributor

viatrix commented Jul 28, 2020

I started investigating this issue and I have a few concerns:

  1. code field is absent in elasticsearch indexes for places;
  2. in test db code field is filled only for US states and is empty for countries.


Is code field used for countries on non-test environments?
Which approach is better for searching by code: by adding it to elasticsearch indexes or by selecting from the db?

@kueda
Copy link
Member

kueda commented Jul 31, 2020


Is code field used for countries on non-test environments?

Generally yes, especially for countries. You can see this using the old Rails-based JSON endpoints, e.g. https://www.inaturalist.org/places/russia.json, where the code field is set to RU.

Which approach is better for searching by code: by adding it to elasticsearch indexes or by selecting from the db?

IMO, since this is a pretty quick lookup and we're not planning on using it for search, I would fetch it out of the database. If that becomes a performance problem, we could add it to elasticsearch later. @pleary do you have an opinion on this?

@viatrix
Copy link
Contributor

viatrix commented Aug 3, 2020

I’ve noticed that ancestry field in places table looks inconsistent: in Node.js test seeds for postgres (fixtures.js) it includes id of the current item:

{
  "id": 222,
  "name": "California",
  "ancestry": "111/222"
},

In test db and in rails code it doesn’t contain id of the current record, only the id of the parent record; id of the current record is pushed to ancestor_place_ids during processing:

 id  |    name    | ancestry 
-----+------------+----------
 297 | California | 17

Should I consider that ancestry field contains only parent ids, without current id?

@kueda
Copy link
Member

kueda commented Aug 4, 2020

Weird, that's probably a problem with the fixture, so yes, assume the ancestry field only contains ancestor IDs, not the ID of the record itself.

viatrix added a commit to viatrix/iNaturalistAPI that referenced this issue Aug 9, 2020
viatrix added a commit to viatrix/iNaturalistAPI that referenced this issue Aug 10, 2020
viatrix added a commit to viatrix/iNaturalistAPI that referenced this issue Aug 11, 2020
pleary added a commit that referenced this issue Nov 24, 2020
Set preferredPlace based on locality from locale. Implements #89
@kueda
Copy link
Member

kueda commented Dec 7, 2020

One unexpected consequence of this that we need to figure out is that due to the fact that we are prioritizing names in a place over names matching a locale without a place, people requesting names in en-HK are getting Chinese names in Hong Kong when an English name exists but lacks a place association. For example, when you request https://api.inaturalist.org/v1/taxa/627207?locale=en-HK, the preferred_common_name is "大頭茶." I'm going to temporarily disable this until we figure that out. IMO, the right solution is to change the way we prioritize the names, but I think that's going to have some other unexpected and maybe more-widespread consequences, which we should probably just deal with... when we have the bandwidth. Alternatively, we could give lower weight to the places we extract from the locale code.

Some backstory regarding our current name priority is at https://groups.google.com/u/1/g/inaturalist/c/P8iNMY0WYNM/discussion

@kueda kueda self-assigned this Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants