The "else" isn't needed, and the negated != is a double negative, wouldn't it be easier to just check "="?
This should work. You pick the searcher instance like you have, then you filter the targets that meet the condition, and pick the closest from them.
Searcher: pick by uid [something]
Target: var = [something]
Target: pick closest to (searcher.x, searcher.y)
--- do something
That leverages the picking system. If you want to do it a code way you can just use "for each" and "system compare" (same as a if). You can think of a uid as a pointer.