manticoresoftware / manticoresearch-php

Official PHP client for Manticore Search
MIT License
167 stars 32 forks source link

Search: Geo sort docs wrong #123

Closed Kayrim closed 1 year ago

Kayrim commented 1 year ago

The docs show this example for geo sorting a search

search->sort([    
               '_geo_distance' =>[    
                   'location_anchor'=>    
                       [    
                           'lat'=>52.396,    
                           'lon'=> -1.774    
                       ],    
                   'location_source' => [    
                       'latitude_deg',    
                       'longitude_deg'    
                   ]    
               ]    
           ]);`    

However this will run into an error in the search class

//if 1st arg is array means we have a sorting expression  
        if (is_array($field)) {  
            //if 2nd arg is true we full set the sort with the expr, otherwise just add it  
            //we let passing uppercased directions here as well  
            foreach ($field as $k => $v) {  
                $field[$k] = strtolower($v);  
            }  
            if (isset($direction) && $direction === true) {  
                $this->params['sort'] = $field;  
            } else {  
                $this->params['sort'] [] = $field;  
            }  
            return $this;  
        }  

$v = the array of location_anchor or location_source
so strtolower throws an error here.
Uncaught TypeError: strtolower(): Argument #1 ($string) must be of type string, array given

githubmanticore commented 1 year ago

➤ Nick Sergeev commented:

Fixed in https://github.com/manticoresoftware/manticoresearch-php/commit/732e6dc202bfb359351241dfda7803ba779fda3c