public function testSearchWithPackageType()
 {
     $repo = new ArrayRepository();
     $repo->addPackage($this->getPackage('foo', '1', 'Composer\\Package\\CompletePackage'));
     $repo->addPackage($this->getPackage('bar', '1', 'Composer\\Package\\CompletePackage'));
     $package = $this->getPackage('foobar', '1', 'Composer\\Package\\CompletePackage');
     $package->setType('composer-plugin');
     $repo->addPackage($package);
     $this->assertSame(array(array('name' => 'foo', 'description' => null)), $repo->search('foo', RepositoryInterface::SEARCH_FULLTEXT, 'library'));
     $this->assertEmpty($repo->search('bar', RepositoryInterface::SEARCH_FULLTEXT, 'package'));
     $this->assertSame(array(array('name' => 'foobar', 'description' => null)), $repo->search('foo', 0, 'composer-plugin'));
 }
 /**
  * {@inheritDoc}
  */
 public function search($query, $mode = 0)
 {
     $this->loadRootServerFile();
     if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) {
         $url = str_replace('%query%', $query, $this->searchUrl);
         $hostname = parse_url($url, PHP_URL_HOST) ?: $url;
         $json = $this->rfs->getContents($hostname, $url, false);
         $results = JsonFile::parseJson($json, $url);
         return $results['results'];
     }
     if ($this->hasProviders()) {
         $results = array();
         $regex = '{(?:' . implode('|', preg_split('{\\s+}', $query)) . ')}i';
         foreach ($this->getProviderNames() as $name) {
             if (preg_match($regex, $name)) {
                 $results[] = array('name' => $name);
             }
         }
         return $results;
     }
     return parent::search($query, $mode);
 }