Ticket #20037: 20037.patch

File 20037.patch, 2.5 KB (added by GerdP, 5 years ago)

possible solution

  • src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java

     
    1515
    1616import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1717import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     18import org.openstreetmap.josm.data.osm.search.SearchCompiler.ExactKeyValue.Mode;
    1819import org.openstreetmap.josm.data.osm.search.SearchCompiler.Match;
    1920import org.openstreetmap.josm.data.osm.search.SearchParseError;
    2021
     
    7374                    throw new IllegalStateException(mode);
    7475                }
    7576            }
    76            
     77
    7778            final Match match = SearchCompiler.compile(search);
    7879            return constructQuery(match, "[bbox:{{bbox}}];", "");
    7980        } catch (SearchParseError | UnsupportedOperationException e) {
     
    129130            // [~"key"~"value", i] -- filter objects tagged with a key and a case-insensitive value matching regular expressions
    130131            final String key = ((SearchCompiler.ExactKeyValue) match).getKey();
    131132            final String value = ((SearchCompiler.ExactKeyValue) match).getValue();
    132             final SearchCompiler.ExactKeyValue.Mode mode = ((SearchCompiler.ExactKeyValue) match).getMode();
     133            final Mode mode = ((SearchCompiler.ExactKeyValue) match).getMode();
    133134            switch (mode) {
    134135                case ANY_VALUE:
    135136                    return "[" + (negated ? "!" : "") + quote(key) + "]";
     
    136137                case EXACT:
    137138                    return "[" + quote(key) + (negated ? "!=" : "=") + quote(value) + "]";
    138139                case EXACT_REGEXP:
     140                case ANY_KEY: // *=value
    139141                    final Matcher matcher = Pattern.compile("/(?<regex>.*)/(?<flags>i)?").matcher(value);
    140142                    final String valueQuery = matcher.matches()
    141143                            ? quote(matcher.group("regex")) + Optional.ofNullable(matcher.group("flags")).map(f -> "," + f).orElse("")
    142144                            : quote(value);
     145                    if (mode == Mode.ANY_KEY)
     146                        return "[~\"^.*$\"" + (negated ? "!~" : "~") + valueQuery + "]";
    143147                    return "[" + quote(key) + (negated ? "!~" : "~") + valueQuery + "]";
    144148                case MISSING_KEY:
    145149                    // special case for empty values, see https://github.com/drolbr/Overpass-API/issues/53