Index: /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java	(revision 30202)
+++ /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java	(revision 30202)
@@ -0,0 +1,69 @@
+// License: GPL v2 or later. See LICENSE file for details.
+package org.openstreetmap.josm.plugins.utilsplugin2.search;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.search.SearchCompiler;
+import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;
+
+
+/**
+ * Matches all ways connected to [nodes and ways which match the expression]..
+ */
+public class ConnectedMatch extends SearchCompiler.UnaryMatch {
+    private Collection<Way> connected = null;
+    boolean all;
+
+    public ConnectedMatch(SearchCompiler.Match match, boolean all) {
+        super(match);
+        this.all = all;
+    }
+
+    /**
+     * Find (all) ways connected to ways or nodes which match the expression.
+     */
+    private void init(boolean all) {
+        Collection<Way> matchedWays = new HashSet<Way>();
+        Set<Node> matchedNodes = new HashSet<Node>();
+        // find all ways that match the expression
+        Collection<Way> allWays = Main.main.getCurrentDataSet().getWays();
+        for (Way way : allWays) {
+            if (match.match(way)) {
+                matchedWays.add(way);
+            }
+        }
+        // find all nodes that match the expression
+        Collection<Node> allNodes = Main.main.getCurrentDataSet().getNodes();
+        for (Node node : allNodes) {
+            if (match.match(node)) {
+                matchedNodes.add(node);
+            }
+        }
+        Set<Way> newWays = new HashSet<Way>();
+        if (all) {
+            NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
+            NodeWayUtils.addWaysConnectedToWaysRecursively(matchedWays, newWays);
+        } else {
+            NodeWayUtils.addWaysConnectedToNodes(matchedNodes, newWays);
+            NodeWayUtils.addWaysConnectedToWays(matchedWays, newWays);
+        }
+        connected = newWays;
+    }
+
+    @Override
+    public boolean match(OsmPrimitive osm) {
+        if (connected == null) {
+            init(all); // lazy initialization
+        }
+        if (osm instanceof Way) {
+            return connected.contains((Way) osm);
+        }
+        return false;
+    }
+    
+}
Index: /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java	(revision 30202)
+++ /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java	(revision 30202)
@@ -0,0 +1,58 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.openstreetmap.josm.plugins.utilsplugin2.search;
+
+import java.util.Collection;
+import java.util.HashSet;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.search.SearchCompiler;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Relation;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;
+
+/**
+ * Matches all objects contained within the match expression.
+ */
+public class InsideMatch extends SearchCompiler.UnaryMatch {
+    private Collection<OsmPrimitive> inside = null;
+
+    public InsideMatch(SearchCompiler.Match match) {
+        super(match);
+    }
+
+    /**
+     * Find all objects inside areas which match the expression
+     */
+    private void init() {
+        Collection<OsmPrimitive> matchedAreas = new HashSet<OsmPrimitive>();
+        // find all ways that match the expression
+        Collection<Way> ways = Main.main.getCurrentDataSet().getWays();
+        for (Way way : ways) {
+            if (match.match(way)) {
+                matchedAreas.add(way);
+            }
+        }
+        // find all relations that match the expression
+        Collection<Relation> rels = Main.main.getCurrentDataSet().getRelations();
+        for (Relation rel : rels) {
+            if (match.match(rel)) {
+                matchedAreas.add(rel);
+            }
+        }
+        inside = NodeWayUtils.selectAllInside(matchedAreas, Main.main.getCurrentDataSet(), false);
+    }
+
+    @Override
+    public boolean match(OsmPrimitive osm) {
+        if (inside == null) {
+            init(); // lazy initialization
+        }
+        return inside.contains(osm);
+    }
+    
+}
Index: /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java	(revision 30202)
+++ /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java	(revision 30202)
@@ -0,0 +1,58 @@
+// License: GPL v2 or later. See LICENSE file for details.
+package org.openstreetmap.josm.plugins.utilsplugin2.search;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.actions.search.SearchCompiler;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils;
+
+/**
+* Find (all) ways intersecting ways or nodes which match the expression.
+*/
+public class IntersectingMatch extends SearchCompiler.UnaryMatch {
+    private Collection<Way> intersecting = null;
+    boolean all;
+
+    public IntersectingMatch(SearchCompiler.Match match, boolean all) {
+        super(match);
+        this.all = all;
+        //init(all);
+    }
+
+    /**
+     * Find (all) ways intersecting ways which match the expression.
+     */
+    private void init(boolean all) {
+        Collection<Way> matchedWays = new HashSet<Way>();
+        // find all ways that match the expression
+        Collection<Way> allWays = Main.main.getCurrentDataSet().getWays();
+        for (Way way : allWays) {
+            if (match.match(way)) {
+                matchedWays.add(way);
+            }
+        }
+        Set<Way> newWays = new HashSet<Way>();
+        if (all) {
+            NodeWayUtils.addWaysIntersectingWaysRecursively(allWays, matchedWays, newWays);
+        } else {
+            NodeWayUtils.addWaysIntersectingWays(allWays, matchedWays, newWays);
+        }
+        intersecting = newWays;
+    }
+
+    @Override
+    public boolean match(OsmPrimitive osm) {
+        if (intersecting == null) {
+            init(all); // lazy initialization
+        }
+        if (osm instanceof Way) {
+            return intersecting.contains((Way) osm);
+        }
+        return false;
+    }
+    
+}
Index: /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsUnaryMatchFactory.java
===================================================================
--- /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsUnaryMatchFactory.java	(revision 30202)
+++ /applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/UtilsUnaryMatchFactory.java	(revision 30202)
@@ -0,0 +1,35 @@
+// License: GPL v2 or later. See LICENSE file for details.
+package org.openstreetmap.josm.plugins.utilsplugin2.search;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.openstreetmap.josm.actions.search.PushbackTokenizer;
+import org.openstreetmap.josm.actions.search.SearchCompiler;
+
+public class UtilsUnaryMatchFactory implements SearchCompiler.UnaryMatchFactory {
+
+    private static Collection<String> keywords = Arrays.asList("inside",
+            "intersecting", "allintersecting", "adjacent", "connected");
+
+    @Override
+    public SearchCompiler.UnaryMatch get(String keyword, SearchCompiler.Match matchOperand, PushbackTokenizer tokenizer) throws SearchCompiler.ParseError {
+        if ("inside".equals(keyword)) {
+            return new InsideMatch(matchOperand);
+        } else if ("adjacent".equals(keyword)) {
+            return new ConnectedMatch(matchOperand, false);
+        } else if ("connected".equals(keyword)) {
+            return new ConnectedMatch(matchOperand, true);
+        } else if ("intersecting".equals(keyword)) {
+            return new IntersectingMatch(matchOperand, false);
+        } else if ("allintersecting".equals(keyword)) {
+            return new IntersectingMatch(matchOperand, true);
+        }
+        return null;
+    }
+
+    @Override
+    public Collection<String> getKeywords() {
+        return keywords;
+    }
+
+}
