I’d imagine it’d be something like this:

  # add any common options here
  sphinx_options = {}
  
  if params[:zip_code].present?
    # presuming ZipCode is a model?
    zip_code = ZipCode.find_by :code => params[:zip_code]
    sphinx_options[:geo] = [
      zip_code.latitude  * Math::PI / 180.0,
      zip_code.longitude * Math::PI / 180.0
    ]
  elsif user_signed_in?
    sphinx_options[:geo] = [
      current_user.latitude  * Math::PI / 180.0,
      current_user.longitude * Math::PI / 180.0
    ]
  end

  Model.search sphinx_options

Cheers

— 
Pat

> On 1 Dec 2014, at 9:00 am, [email protected] wrote:
> 
> It is setup in the controller to detect the current user lat/lon and use it 
> when performing a geo search without the user having to enter their zip code.
> 
>             :geo => [current_user.latitude * Math::PI / 180.0, 
> current_user.longitude * Math::PI / 180.0]
> 
> 
> This works great for registered members as they don't have to enter their zip 
> code to perform a search. But it's not a good idea for non-registered members 
> (wouldn't have a lat/lon value store in db) and if registered members wanted 
> to search a different area.
> 
> How can I add a condition that when visitors perform a search and manually 
> enter in a zip code on the form:
> 
>                     = text_field_tag :zip_code, nil, placeholder: "enter zip 
> here", class: 'text_input'
> 
> That it will use that zip's lat/lon instead of the "current_user's 
> information"?
> 
> For example current setup is like the following. User A has zip code of 
> 90001. Sphinx will automatically detect their lat/lon value 33.97, -1118.24 
> and insert that into the search results. User A is happy because they never 
> had to enter their zip code.
> 
> User A (or guest) would like to search from a different area. They enter in a 
> zip code 10001, but Sphinx ignores and continues using 90001 (since that's 
> the current users information).
> 
> I want to overwrite the current_user information IF the User entered a zip 
> code into the form.
> 
> -- 
> 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/d/optout.

-- 
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/d/optout.

Reply via email to