Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#19070 closed enhancement (fixed)

SearchCompiler: regexp comparison using <tilde>

Reported by: simon04 Owned by: simon04
Priority: normal Milestone: 20.05
Component: Core Version:
Keywords: search regex Cc:

Description

This increases (mental) interoperability with MapCSS and Overpass QL. Also required for #18164

Example: highway~primary|secondary

Attachments (1)

2020-04-11-174017_1119x513_scrot.png (28.8 KB ) - added by simon04 5 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 by simon04, 5 years ago

Resolution: fixed
Status: assignedclosed

In 16260/josm:

fix #19070 - SearchCompiler: regexp comparison using <tilde>

comment:2 by simon04, 5 years ago

Updated search dialog:


comment:3 by GerdP, 5 years ago

What about the "regular expression" checkbox in the lower left corner?

comment:4 by GerdP, 5 years ago

See also #15943

comment:5 by simon04, 5 years ago

The regular expression mode not only affects key=value queries, but is used for other types as well, see org.openstreetmap.josm.data.osm.search.SearchCompiler#parseFactor()

Since search expressions are also used for user-defined filters, dropping this radio button element sounds like pain to me.

in reply to:  5 ; comment:6 by GerdP, 5 years ago

Replying to simon04:

The regular expression mode not only affects key=value queries, but is used for other types as well, see org.openstreetmap.josm.data.osm.search.SearchCompiler#parseFactor()

I just wondered what happens when you enable the button AND use e.g. highway~trunk.*

Since search expressions are also used for user-defined filters, dropping this radio button element sounds like pain to me.

+1

BTW: The regex search works a bit strange, no matter which version I use.
highway~trunk finds highway=trunk, but not highway=trunk_link
With highway~trunk.* finds both

When I just search for trunk with "standard Search syntax" enabled I also find both, but also other stuff like highway:historic=trunk or name=Strunk

The search for pattern highway~^trunk.* doesn't seem to work. I have to use quotes: highway~"^trunk.*"

in reply to:  6 comment:7 by simon04, 5 years ago

Replying to GerdP:

I just wondered what happens when you enable the button AND use e.g. highway~trunk.*

The radio button is not taken into account when using highway~trunk

highway~trunk finds highway=trunk, but not highway=trunk_link
With highway~trunk.* finds both

The patch is performed using matches() (in contrast to find()) – thus the whole string has to be matched against the given regexp. For details see org.openstreetmap.josm.data.osm.search.SearchCompiler.ExactKeyValue#match

comment:8 by GerdP, 5 years ago

I didn't try to understand the details of the code in SearchCompiler, else I would already have tried to fix #15943.
Looking at your changes in r16260 we probably just have to remove one line?

  • src/org/openstreetmap/josm/gui/dialogs/SearchDialog.java

     
    291291                .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''")),
    292292                GBC.eol());
    293293        hintPanel.add(new SearchKeywordRow(hcbSearchString)
    294                 .addKeyword("<i>key</i>", null, tr("matches if ''key'' exists"))
    295294                .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''"))
    296295                .addKeyword("<i>key</i>~<i>regexp</i>", null, tr("value of ''key'' matching the regular expression ''regexp''"))
    297296                .addKeyword("<i>key</i>=*", null, tr("''key'' with any value"))

in reply to:  8 comment:9 by simon04, 5 years ago

Replying to GerdP:

I didn't try to understand the details of the code in SearchCompiler, else I would already have tried to fix #15943.

Let's continue the discussion in #15943 (since it's not related to this ticket).

comment:10 by Klumbumbus, 5 years ago

Milestone: 20.0420.05

Milestone renamed

in reply to:  6 comment:11 by gaben, 5 years ago

Replying to GerdP:

The search for pattern highway~^trunk.* doesn't seem to work. I have to use quotes: highway~"^trunk.*"

I searched for peaks with elevation in name. The name:"\\.*\\d+ *m" query works but name~"\\.*\\d+ *m" not. According to the help in the search window tilde should work (key~regexp). Is this intended?

JOSM 16392, regex mode enabled.

comment:12 by skyper, 5 years ago

Resolution: fixed
Status: closedreopened

comment:13 by simon04, 5 years ago

Resolution: fixed
Status: reopenedclosed
  • You should compare foo=bar to foo~barfoo:bar is different as it searches for substrings
  • For matching an arbitrary string you'd use .* (without escaping)

Thus, name~"\\.*\\d+ *m" not matching name=Peak 3000 m is correct (since \\.* matches an arbitrary number of dots).

Note: name:"\\.*\\d+ *m" matches since it searches for substrings – the substring 3000 m matches

comment:14 by gaben, 5 years ago

@simon04: Ah got it. That escaping confused me. Thanks for the explanation!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.