Index: trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 9930)
+++ trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java	(revision 9940)
@@ -773,7 +773,3 @@
         return Collections.<ActionParameter<?>>singletonList(new SearchSettingsActionParameter(SEARCH_EXPRESSION));
     }
-
-    public static String escapeStringForSearch(String s) {
-        return s.replace("\\", "\\\\").replace("\"", "\\\"");
-    }
 }
Index: trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 9930)
+++ trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java	(revision 9940)
@@ -1745,3 +1745,23 @@
         return searchFlags;
     }
+
+    static String escapeStringForSearch(String s) {
+        return s.replace("\\", "\\\\").replace("\"", "\\\"");
+    }
+
+    /**
+     * Builds a search string for the given tag. If value is empty, the existence of the key is checked.
+     *
+     * @param key   the tag key
+     * @param value the tag value
+     * @return a search string for the given tag
+     */
+    public static String buildSearchStringForTag(String key, String value) {
+        final String forKey = '"' + escapeStringForSearch(key) + '"' + '=';
+        if (value == null || value.isEmpty()) {
+            return forKey + "*";
+        } else {
+            return forKey + '"' + escapeStringForSearch(value) + '"';
+        }
+    }
 }
