JOSM/Search function
From OpenStreetMap
This page describes JOSM search function as determine by me (User:kleptog) reading the source and extrapolating as I write the page. As such it may not 100% match reality but feel free to notify me of any errors you find.
JOSM search is a fairly advanced system which which first takes your string, compiles it into a tree structure and runs that over the data. At the base level there are matching tokens, which can then be combined to form complex searches.
There is provision for case-sensetive matches, that is activated from the search dialog directly.
Contents |
Tokens
This is a list of the base tokens in so far as I can see from the source:
| Token | Meaning |
|---|---|
| selected | Matches only objects which are currently selected |
| modified | Matches only objects which have been modified. This is essentially anything that would be uploaded if you hit the upload button, thus it includes newly created objects. |
| incomplete | Matches any objects which are incomplete (e.g. referenced by a relation but not returned by the server) |
| key:value | A more specific matching form, of which a few special versions exist. Both the key and the value may be double quoted strings (you have to use them if the key contains a colon). |
| type:node
type:segment type:way | Matches a specific type of object |
| user:name | Matches objects that were last edited by user name (exact match). Note that this reflects the information JOSM gets from the server, even if you modifed the object locally in JOSM. |
| nodes:number | Matches ways that contain exactly number nodes. |
| id:value | Matches the object with the server id value. (Objects that have not been uploaded to the server yet have the id 0.) |
| key:value | Matches objects with the key key and the value value. The key is an exact match but the value is a substring match. |
| value | Matches the given value as a substring match on either the key or the value. If value has a colon in it you must use double-quotes to protect it. |
Modifiers
There is currently one modifer, the minus sign (-) which is used to invert selections. It can be placed in one of two places, which makes not difference. Note that the actual effect in JOSM may not be what you'd expect (see the examples below).
| Example | Description |
|---|---|
| -selection | Anything that is not selected |
| -id:value
id:-value | Everything except objects with the given ID |
| -key:value
key:-value | Everything except objects with the given key (exact match) and the given value (substring match). Note that it will select any objects that don't have the key at all (see proposal). |
Proposal: make the placement make a difference, so that '-highway:unclassified' be like the current meaning, anything that doesn't match that tag, whereas 'highway:-unclassified' match anything with a highway tag that doesn't match the value. It would simplify some examples and be more intuitive also. - Kleptog
Combiners
There are two ways to combine token, via AND or OR. There is no explicit AND symbol. There are also no parenthesis. This is where the biggest deficiency is in the JOSM search function: there are also no precedence rules. This may make some complex searches completely impossible. (This is such a big deficiency that I may actually send a patch for it - Kleptog). It's also quite unintuitive.
| Combiner | Description |
|---|---|
| token token | Matches if both tokens match |
| token | token
token OR token | Matches if either token matches |
Examples
In case the above is [wikipedia:Gobbledygook] to you, here are some worked example, including some tricks:
| highway unclassified | Returns any objects that have both the words 'highway' and 'unclassified' as a substring in either the key of the value fields |
| highway:unclass | Returns any object where the key 'highway' has a value with the substring 'unclass'. |
| -highway:unclassified | This appears to match everything. You may be wondering way, since most roads aren't unclassified. The reason is that this matches everything that does not contain the 'unclassified' substring in the 'highway' tag (e.g. everything that doesn't have a 'highway' tag). |
| -highway:unclassified type:way | This is better, now all the highways are unselected, but the waterway still are. For that you need: |
| -highway:unclassified type:way highway: | Now you get just those ways which have a 'highway' tag. |
| selected -type:node | Removes all nodes from the current selection. |
| selected | type:node | Adds all nodes to the current selection |
| selected | type:node place:London | Here the counterintuitive choice of precedence rears its ugly head. You'd be tempted to interpret it as selected | (type:node place:London) whereas it is actually interpreted as (selected | type:node) place:London. What you need to do is... |
| selected | (type:node place:London) | This does what you expect, though you can acheive the same result by selecting "add to selection" in the search dialog box. |
| foo bar | baz zap | Beware: Juxtaposition has a lower precedence than OR. This will be interpreted as foo (bar | baz) zap. |
| (foo bar) OR (baz zap) | You can use parens to override default precedence. This will select the objects that match foo and bar or baz and zap. |
Good luck searching!

