Id: More flexible format in 'Search Features' when searching by element id

Created on 22 May 2020  Â·  9Comments  Â·  Source: openstreetmap/iD

Currently, User can search for a specific feature with a 'Search Features' query like n1234. When I copy an element from JOSM (or other places) I get a string like node 1234. But when I search in iD for this string, I get nothing. When I search for 1234 it offers node 1234 as an option.

I suggest supporting search queries of the form node 1234.

After looking at the code...
https://github.com/openstreetmap/iD/blob/63aa47f02f06534eb3311ec869659cfdffc74f42/modules/ui/feature_list.js#L125
it could use the regex
/^(node|way|relation|[nwr]) ?([0-9]+)$/i
and in four places immediately blow, replace idMatch[1] with idMatch[1][0]

But this would only support English. A step further would be to get the user's current language, and support the localized word for each element type.

good first issue usability

All 9 comments

It would be great if we could allow more than one translated word for the regex, e.g. „Punkt“ and „Knoten“ for the german translation of node or maybe even „Weg“ and „Fläche“ for way.

But this would only support English. A step further would be to get the user's current language, and support the localized word for each element type.

I think this would be pretty straightforward. Ideally, iD would expose a translatable string for “node id” in Transifex. With the current locale’s translation in hand, iD could convert that into a regex dynamically.

It would be great if we could allow more than one translated word for the regex, e.g. „Punkt“ and „Knoten“ for the german translation of node or maybe even „Weg“ and „Fläche“ for way.

Or iD could expose two translatable lists of prefixes and suffixes (similar to the presets’ synonym lists), which would allow for variation. Hopefully no language needs both a prefix and suffix at the same time, though.

Would it be possible to update the regex to exclude spaces before or after element ids? As that would solve #7467.

Ignore whitespace before, after or between:
/^\s*(node|way|relation|[nwr])\s*([0-9]+)\s*$/i

Consider merging this issue with with https://github.com/openstreetmap/iD/issues/7282. Also, I had indicated I might make a pull request. I'm abandoning that for now.

These are examples of positive matches:
n158867610
n 158867610
n/158867610
node158867610
node 158867610
node/158867610
https://www.openstreetmap.org/node/158867610
https://www.openstreetmap.org/node/158867610/history
https://www.openstreetmap.org/node/158867610/history#map=19/43.66140/-70.25415
And the same for ways and relations. By requiring tokens before the type and after the id I have minimized false positives.
This also resolves https://github.com/openstreetmap/iD/issues/7282

To record some unintended consequences of this change:
image
This seems like a common use-case, and I regret breaking it. Any thoughts on if it is worth addressing?

I think we could just have locationMatch take priority over idMatch in https://github.com/openstreetmap/iD/blob/0789b861b47fb59b3810efe258c2c256a234f2fa/modules/ui/feature_list.js#L125-L149

So check location first, don't bother checking id if location is matched. Thoughts?

So check location first, don't bother checking id if location is matched. Thoughts?

@SilentSpike Sounds fine, I'd welcome a PR for that.

Was this page helpful?
0 / 5 - 0 ratings