<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def search(obj, glob, yielded=False, separator="/", afilter=None, dirs = True):
 """ Given a path glob, return a dictionary containing all keys that matched the given glob. If 'yielded' is true, then a dictionary will not be returned. Instead tuples will be yielded in the form of (path, value) for every element in the document that matched the glob. """


    def _search_view(obj, glob, separator, afilter, dirs):
        view = {}
        globlist = __safe_path__(glob, separator)
        for path in _inner_search(obj, globlist, separator, dirs=dirs):
            try:
                val = dpath.path.get(obj, path, afilter=afilter, view=True)
                merge(view, val)
            except dpath.exceptions.FilteredValue:
                pass
        return view

    def _search_yielded(obj, glob, separator, afilter, dirs):
        globlist = __safe_path__(glob, separator)
        for path in _inner_search(obj, globlist, separator, dirs=dirs):
            try:
                val = dpath.path.get(obj, path, view=False, afilter=afilter)
                yield (separator.join(map(str, dpath.path.paths_only(path))), val)
            except dpath.exceptions.FilteredValue:
                pass

    if afilter is not None:
        dirs = False
    if yielded:
        return _search_yielded(obj, glob, separator, afilter, dirs)
    return _search_view(obj, glob, separator, afilter, dirs)