/** * Test parsing a sentence with small and long words. * * @see KeywordsParser::parse */ public function testParse() { $string = "This, is a sentence' with small_and-long words"; $keywords = KeywordsParser::parse($string); $this->assertEquals(7, count($keywords)); }
/** * @Rest\Get( * "/{country}/multi", * name="search_multi" * ) * * @Rest\QueryParam( * name="search-string", * nullable=false, * description="Search string" * ) * * @Rest\QueryParam( * name="lon", * nullable=true, * description="Longitude" * ) * * @Rest\QueryParam( * name="lat", * nullable=true, * description="Latitude" * ) * * @ApiDoc( * section="Search", * description="Search all", * statusCodes = { * 200 = "Search results" * }, * requirements={ * { * "name"="country", * "dataType"="string", * "description"="ISO Code of country" * } * }, * tags={ * "stable" = "green" * } * ) * * @param $country * @param ParamFetcherInterface $paramFetcher * * @return array * * @throws NoSearchStringProvidedException */ public function multiSearchAction($country, ParamFetcherInterface $paramFetcher) : array { $keywords = KeywordsParser::parse($paramFetcher->get('search-string')); if (empty($keywords)) { throw new NoSearchStringProvidedException(); } $request = $this->get('request_stack')->getCurrentRequest(); $client = new Client(['base_uri' => $request->getSchemeAndHttpHost()]); $params = ['country' => $country, 'search-string' => $paramFetcher->get('search-string')]; if ($paramFetcher->get('lat') && $paramFetcher->get('lon')) { $params = array_merge($params, ['lon' => $paramFetcher->get('lon'), 'lat' => $paramFetcher->get('lat')]); } $promises = ['elects' => $client->getAsync($this->generateUrl('search_elect', $params), ['decode_content' => 'gzip']), 'zones' => $client->getAsync($this->generateUrl('search_zone', $params), ['decode_content' => 'gzip'])]; /** @var Response[] $results */ $results = Promise\unwrap($promises); return ['elects' => json_decode($results['elects']->getBody()->getContents(), true), 'zones' => json_decode($results['zones']->getBody()->getContents(), true)]; }