Skip to content

Search: Geo sort docs wrong #123

Description

@Kayrim

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions