def search(self, resources_request=None):
<EOL>name_pattern, version_range = self._parse_request(resources_request)<EOL>family_names = set(<EOL>x.name for x in iter_package_families(paths=self.package_paths)<EOL>if fnmatch.fnmatch(x.name, name_pattern)<EOL>)<EOL>family_names = sorted(family_names)<EOL>if self.resource_type:<EOL><INDENT>resource_type = self.resource_type<EOL><DEDENT>elif version_range or len(family_names) == <NUM_LIT:1>:<EOL><INDENT>resource_type = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>resource_type = "<STR_LIT>"<EOL><DEDENT>if not family_names:<EOL><INDENT>return resource_type, []<EOL><DEDENT>if resource_type == "<STR_LIT>":<EOL><INDENT>results = [ResourceSearchResult(x, "<STR_LIT>") for x in family_names]<EOL>return "<STR_LIT>", results<EOL><DEDENT>results = []<EOL>for name in family_names:<EOL><INDENT>it = iter_packages(name, version_range, paths=self.package_paths)<EOL>packages = sorted(it, key=lambda x: x.version)<EOL>if self.latest and packages:<EOL><INDENT>packages = [packages[-<NUM_LIT:1>]]<EOL><DEDENT>for package in packages:<EOL><INDENT>try:<EOL><INDENT>if package.timestamp:<EOL><INDENT>if self.after_time and package.timestamp < self.after_time:<EOL><INDENT>continue<EOL><DEDENT>if self.before_time and package.timestamp >= self.before_time:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if self.validate:<EOL><INDENT>package.validate_data()<EOL><DEDENT><DEDENT>except ResourceContentError as e:<EOL><INDENT>if resource_type == "<STR_LIT>":<EOL><INDENT>result = ResourceSearchResult(package, "<STR_LIT>", str(e))<EOL>results.append(result)<EOL><DEDENT>continue<EOL><DEDENT>if resource_type == "<STR_LIT>":<EOL><INDENT>result = ResourceSearchResult(package, "<STR_LIT>")<EOL>results.append(result)<EOL>continue<EOL><DEDENT>try:<EOL><INDENT>for variant in package.iter_variants():<EOL><INDENT>if self.validate:<EOL><INDENT>try:<EOL><INDENT>variant.validate_data()<EOL><DEDENT>except ResourceContentError as e:<EOL><INDENT>result = ResourceSearchResult(<EOL>variant, "<STR_LIT>", str(e))<EOL>results.append(result)<EOL>continue<EOL><DEDENT><DEDENT>result = ResourceSearchResult(variant, "<STR_LIT>")<EOL>results.append(result)<EOL><DEDENT><DEDENT>except ResourceContentError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT><DEDENT>return resource_type, results<EOL>
Search for resources.

        Args:
            resources_request (str): Resource to search, glob-style patterns
                are supported. If None, returns all matching resource types.

        Returns:
            2-tuple:
            - str: resource type (family, package, variant);
            - List of `ResourceSearchResult`: Matching resources. Will be in
              alphabetical order if families, and version ascending for
              packages or variants.