Sounds like just removing the filter on geodist should do the trick - you're 
ordering by geodist, so the closest matches will certainly be at the top.

On 4 Feb 2014, at 8:36 am, C Wilson <[email protected]> wrote:

> This should be my last question lol. I have been trying out scenarios over 
> the weekend but could't get something to work so I reverted back to what did 
> work.
> 
> The code pulls the nearest users within 400km. Is it possible to return for 
> example maximum 400 users even if they're outside the 400km distance?
> 
> Example:
> 
> I have 100 users in the database. 20 from New York and 80 from California.
>  
> A user does a search in 10453 (Bronx, NY) and it returns 20 users that are 
> from New York in order from their distance. At the bottom of the list will be 
> the rest of the users from the database (80 from California). 
> 
> The reason for wanting to do this is because to do a search and pull only 20 
> users will be depressing for a new app. It would look much better to list 100 
> users, even if 80 of them are from a different state than what the user 
> search.
> 
> I wasn't sure if this was possible.
> 
>   def index
>     if location = Location.find_by_zipcode(params[:search])
>         latitude  = location.latitude * Math::PI / 180 
>         longitude = location.longitude * Math::PI / 180 
>         locations = Location.search( 
>           :geo   => [latitude, longitude], 
>           :with  => {:geodist => 0.0..600_000.0}, 
>           :order => 'geodist ASC',
>           :per_page => 5_000
>         ) 
>         @users = User.where(zip_code: locations.map(&:zipcode))
>          
>       
>           else
>             @users = User.search(params[:search])
>         end      
>       end
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to