public function testMultipleCoordinates()
 {
     $doc = array('coordinates' => array(array('coord' => array('lat' => 0.7077777777777799, 'lon' => -50.089444444444), 'region' => null, 'dim' => 10000, 'name' => "", 'primary' => true, 'type' => "river", 'globe' => "earth", 'country' => "BR"), array('coord' => array('lat' => -15.518055555556, 'lon' => -71.765277777778), 'region' => null, 'dim' => 10000, 'name' => "", 'primary' => false, 'type' => "river", 'globe' => "earth", 'country' => "BR")));
     $builder = new SuggestBuilder(SuggestScoringMethodFactory::getScoringMethod('incomingLinks', 1));
     $coord = $builder->findPrimaryCoordinates($doc);
     $expected = array('lat' => 0.7077777777777799, 'lon' => -50.089444444444);
     $this->assertSame($expected, $coord);
     $doc['coordinates'][1]['primary'] = true;
     $coord = $builder->findPrimaryCoordinates($doc);
     $expected = array('lat' => 0.7077777777777799, 'lon' => -50.089444444444);
     $this->assertSame($expected, $coord, "With two primaries coord we choose the first one");
     $doc['coordinates'][0]['primary'] = false;
     $coord = $builder->findPrimaryCoordinates($doc);
     $expected = array('lat' => -15.518055555556, 'lon' => -71.765277777778);
     $this->assertSame($expected, $coord, "Choose primary coord even if it's not the first one.");
     $doc['coordinates'][1]['primary'] = false;
     $coord = $builder->findPrimaryCoordinates($doc);
     $expected = array('lat' => 0.7077777777777799, 'lon' => -50.089444444444);
     $this->assertSame($expected, $coord, "Choose first coord if there's no primary.");
     $doc['coordinates'][0]['primary'] = true;
     $doc['coordinates'][0]['globe'] = 'Magrathea';
     $coord = $builder->findPrimaryCoordinates($doc);
     $expected = array('lat' => -15.518055555556, 'lon' => -71.765277777778);
     $this->assertSame($expected, $coord, "Choose first coord on earth.");
     $doc['coordinates'][1]['globe'] = 'Magrathea';
     $coord = $builder->findPrimaryCoordinates($doc);
     $this->assertNull($coord, "No coord if none is on earth.");
 }
 private function indexData()
 {
     $query = new Query();
     $query->setFields(array('_id', '_type', '_source'));
     // Exclude content fields to save bandwidth
     $query->setSource(array('exclude' => array('text', 'source_text', 'opening_text', 'auxiliary_text')));
     $query->setQuery(new Elastica\Query\Filtered(new Elastica\Query\MatchAll(), new Elastica\Filter\BoolAnd(array(new Elastica\Filter\Type(Connection::PAGE_TYPE_NAME), new Elastica\Filter\Term(array("namespace" => NS_MAIN))))));
     $scrollOptions = array('search_type' => 'scan', 'scroll' => "15m", 'size' => $this->indexChunkSize);
     // TODO: only content index for now ( we'll have to check how it works with commons )
     $sourceIndex = $this->getConnection()->getIndex($this->indexBaseName, Connection::CONTENT_INDEX_TYPE);
     $result = $sourceIndex->search($query, $scrollOptions);
     $totalDocsInIndex = $result->getResponse()->getData();
     $totalDocsInIndex = $totalDocsInIndex['hits']['total'];
     $totalDocsToDump = $totalDocsInIndex;
     $scoreMethodName = $this->getOption('scoringMethod', 'quality');
     $this->scoreMethod = SuggestScoringMethodFactory::getScoringMethod($scoreMethodName, $totalDocsInIndex);
     $builder = new SuggestBuilder($this->scoreMethod, $this->withGeo);
     $docsDumped = 0;
     $this->output("Indexing {$totalDocsToDump} documents ({$totalDocsInIndex} in the index)\n");
     $self = $this;
     $destinationType = $this->getIndex()->getType(Connection::TITLE_SUGGEST_TYPE_NAME);
     $retryAttempts = $this->indexRetryAttempts;
     Util::iterateOverScroll($sourceIndex, $result->getResponse()->getScrollId(), '15m', function ($results) use($self, &$docsDumped, $totalDocsToDump, $builder, $destinationType, $retryAttempts) {
         $suggestDocs = array();
         foreach ($results as $result) {
             $docsDumped++;
             $suggests = $builder->build($result->getId(), $result->getSource());
             foreach ($suggests as $suggest) {
                 $suggestDocs[] = new \Elastica\Document(null, $suggest);
             }
         }
         $self->outputProgress($docsDumped, $totalDocsToDump);
         Util::withRetry($retryAttempts, function () use($destinationType, $suggestDocs) {
             $destinationType->addDocuments($suggestDocs);
         });
     }, 0, $retryAttempts);
     $this->output("Indexing done.\n");
 }