Ticket #20037: 20037.2.patch
File 20037.2.patch, 2.5 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/tools/SearchCompilerQueryWizard.java
46 46 * @return an Overpass QL query 47 47 * @throws UncheckedParseException when the parsing fails 48 48 */ 49 public String constructQuery(final String search) {49 public static String constructQuery(final String search) { 50 50 try { 51 51 Matcher matcher = Pattern.compile("\\s+GLOBAL\\s*$", Pattern.CASE_INSENSITIVE).matcher(search); 52 52 if (matcher.find()) { … … 73 73 throw new IllegalStateException(mode); 74 74 } 75 75 } 76 76 77 77 final Match match = SearchCompiler.compile(search); 78 78 return constructQuery(match, "[bbox:{{bbox}}];", ""); 79 79 } catch (SearchParseError | UnsupportedOperationException e) { … … 81 81 } 82 82 } 83 83 84 private String constructQuery(final Match match, final String bounds, final String queryLineSuffix) {84 private static String constructQuery(final Match match, final String bounds, final String queryLineSuffix) { 85 85 final List<Match> normalized = normalizeToDNF(match); 86 86 final List<String> queryLines = new ArrayList<>(); 87 87 queryLines.add("[out:xml][timeout:90]" + bounds); … … 135 135 return "[" + (negated ? "!" : "") + quote(key) + "]"; 136 136 case EXACT: 137 137 return "[" + quote(key) + (negated ? "!=" : "=") + quote(value) + "]"; 138 case ANY_KEY: // *=value 139 // fall through 138 140 case EXACT_REGEXP: 139 141 final Matcher matcher = Pattern.compile("/(?<regex>.*)/(?<flags>i)?").matcher(value); 140 142 final String valueQuery = matcher.matches() 141 143 ? quote(matcher.group("regex")) + Optional.ofNullable(matcher.group("flags")).map(f -> "," + f).orElse("") 142 144 : quote(value); 145 if (mode == SearchCompiler.ExactKeyValue.Mode.ANY_KEY) 146 return "[~\"^.*$\"" + (negated ? "!~" : "~") + valueQuery + "]"; 143 147 return "[" + quote(key) + (negated ? "!~" : "~") + valueQuery + "]"; 144 148 case MISSING_KEY: 145 149 // special case for empty values, see https://github.com/drolbr/Overpass-API/issues/53