I sent the second query from the else statement.
The first query is:
@search = Search.new
if location = Location.find_by_zip_code(params[:search])
latitude = location.latitude * Math::PI / 180
longitude = location.longitude * Math::PI / 180
locations = Location.search(
:geo => [latitude, longitude],
:with => {:geodist => 0.0..100_000.0},
:order => 'geodist ASC',
:per_page => 5_000
)
@users = User.where(zip_code: locations.map(&:zip_code))
haha I totally forgot to combine the with conditions!
On Friday, November 28, 2014 6:32:01 PM UTC-5, Pat Allan wrote:
>
> Oh, but also - you’re specifying :with twice - you need to combine those
> two hashes into one!
>
> On 29 Nov 2014, at 10:29 am, Pat Allan <[email protected]
> <javascript:>> wrote:
>
> I don’t think that’s the same query as the SphinxQL you’ve shared -
> because that had ‘user_id <> 1’ in it.
>
> On 29 Nov 2014, at 10:27 am, alexa <[email protected] <javascript:>>
> wrote:
>
> @users = User.search(params[:query],
> :conditions => { :gender => params[:gender]},
> :with => {:age => 18..55},
> :geo => [current_user.latitude * Math::PI / 180.0,
> current_user.longitude * Math::PI / 180.0],
> :with => {:geodist => 0.0..100_000.0},
> :order => 'geodist ASC')
>
> On Friday, November 28, 2014 6:23:51 PM UTC-5, Pat Allan wrote:
>>
>> Can you share the search call in your controller?
>>
>> On 29 Nov 2014, at 8:17 am, alexa <[email protected]> wrote:
>>
>> Ok I am doing it as such but it is ignoring the age search. For example I
>> am doing 18-22 search for Males, and it's returning all Males regardless of
>> their age.
>>
>> Params being passed are gender=Male&start_age=18&end_age=23
>>
>> In the view form is setup as:
>>
>> select_tag :start_age, options_for_select((18..65)
>>
>> select_tag :end_age, options_for_select((20..65)
>>
>> The issue seems to be in the sphinx query:
>>
>> *Sphinx Query (0.9ms)* SELECT GEODIST(0.5904448859496816,
>> -1.464156709498043, latitude, longitude) AS geodist, * FROM `user_core`
>> WHERE MATCH('@gender Male') AND `geodist` BETWEEN 0.0 AND 100000.0 AND
>> `sphinx_deleted` = 0 AND `user_id` <> 1 ORDER BY `geodist` ASC LIMIT 0, 20
>>
>> Is it required to pass the age param in the conditions method? As I'm
>> doing that for gender :gender => params[:gender]
>>
>> On Thursday, November 27, 2014 6:09:35 PM UTC-5, Pat Allan wrote:
>>>
>>> If age is a column on the users table (and it sounds like it is) then
>>> you can just refer to it directly in the `has` call:
>>>
>>> has age
>>>
>>> Then, you’ll need to run `rake ts:rebuild` to have the Sphinx
>>> configuration and indices updated, and after that:
>>>
>>> User.search params[:query], :with => {:age => 18..55}
>>>
>>> If you’re using your user_age_range method, make sure it’s returning a
>>> range of integers:
>>>
>>> params[:start_age].to_i..params[:end_age].to_i
>>>
>>> Cheers
>>>
>>> —
>>> Pat
>>>
>>> On 28 Nov 2014, at 5:10 am, alexa <[email protected]> wrote:
>>>
>>> I can successfully perform a age search using ThinkingSphinx if I do
>>> this in the controller:
>>>
>>> @users = User.where(age: user_age_range)
>>>
>>> private
>>> def user_age_range
>>> params[:start_age]..params[:end_age]
>>> end
>>>
>>> That requires no changes to the index. However it ignores all my
>>> previous rules with geo search distance, since I am overwriting my original
>>> @users = User.search(params[:query] by having two @users statements.
>>>
>>> I'm not sure how to adjust it using `age: user_age_range` with the
>>> @users = User.search(params[:query] .
>>>
>>> So I figured the best option would be to do a with condition, :with => {
>>> :age => 18..55 } and add age as a 'has' attribute so Sphinx can do that max
>>> computation. But setting up the 'has' attribute has been confusing for me
>>> lol. What should the age 'has' attribute look like if I am tying to do the
>>> with condition?
>>>
>>> --
>>> 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 thinkin...@googlegroups.
>>> <http://googlegroups.com/>com <http://googlegroups.com/>.
>>> 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.
>>
>>
>>
> --
> 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] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> 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] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> 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.