Rebuilding the index and restarting server fixed the error. Thanks.
I moved the code from distance controller to the proper controller.
The search is returning the exact zip codes only. So on the form when I
enter "30052" it will return only users with that zip code. So should I be
adding more code to the search form?
>
> <%= form_tag searches_path, method: :get do %>
> <p>
> <%= text_field_tag :search, params[:search] %>
> <%= button_tag "Search", name: nil %>
> </p>
> <% end %>
Unless I need to add to my search view? Something like:
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.location.zipcode %></td>
<td><%= user.location.city %></td>
<td><%= user.distance %></td>
</tr>
<% end %>
On Friday, November 22, 2013 6:30:17 PM UTC-5, Pat Allan wrote:
>
> You seem to be searching on User, yet it’s Location that has the latitude
> and longitude values - so the search call in your DistanceController will
> not work.
>
> But I can see no reason why your User.search call in
> SearchesController#index wouldn’t work, given it’s just passing a parameter
> through. Have you run ts:rebuild since adding the index for the User model?
>
> —
> Pat
>
> On 23 Nov 2013, at 6:40 am, C Wilson <[email protected] <javascript:>>
> wrote:
>
> I did the has and belongs to since what I was using before didn't seem to
> work. I now changed it back to `belongs_to :location`. Wiith your code and
> small change it now works when indexing
>
> indexing index 'location_core'...
> collected 42522 docs, 0.4 MB
> sorted 0.1 Mhits, 100.0% done
> total 42522 docs, 362463 bytes
> total 0.696 sec, 520685 bytes/sec, 61083.68 docs/sec
> indexing index 'user_core'...
> collected 3 docs, 0.0 MB
> sorted 0.0 Mhits, 100.0% done
> total 3 docs, 233 bytes
> total 0.029 sec, 7976 bytes/sec, 102.70 docs/sec
> total 6 reads, 0.001 sec, 230.3 kb/call avg, 0.1 msec/call avg
> total 19 writes, 0.003 sec, 164.8 kb/call avg, 0.1 msec/call avg
>
> However when previously TS results worked, now since I have the geo
> searching integrated the search page no longer works. I get
> a ThinkingSphinx::NoIndicesError. It's pointing to the show.html page.
>
> https://gist.github.com/pwz2k/7605599
>
> With your assistance. This is how all my code looks now:
>
>
>> ThinkingSphinx::Index.define :location, :with => :active_record do
>> indexes city
>>
>> has "RADIANS(locations.latitude)", :as => :latitude, :type => :float
>> has "RADIANS(locations.longitude)", :as => :longitude, :type => :float
>> end
>> ThinkingSphinx::Index.define :user, :with => :active_record do
>> indexes name, :as => :user, :sortable => true
>> indexes religion, zip_code, about_me, career, sexuality, children,
>> user_smoke, user_drink, gender, ethnicity, education
>> has created_at, updated_at
>> has id, :as => :locations_ids
>> end
>
>
>
> user.rb:
>
>> belongs_to :location
>> attr_accessible :name
>
>
> location.rb:
>
>> class Location < ActiveRecord::Base
>> attr_accessible :city, :latitude, :longitude, :zipcode
>> end
>
>
> Distance controller:
>
>> class DistanceController < ApplicationController
>> def search
>> @latitude = params[:latitude].to_f * Math::PI / 180
>> @longitude = params[:longitude].to_f * Math::PI / 180
>> @users = User.search :geo => [@latitude, @longitude], :with =>
>> {:geodist => 0.0..200_000.0}, :order => "geodist ASC"
>> end
>> end
>
>
> Searches controller:
>
>> def new
>> @search = Search.new
>> end
>> def create
>> @search = Search.new(params[:search])
>> if @search.save
>> redirect_to @search
>> else
>> render 'new'
>> end
>> end
>> def show
>> @search = Search.find(params[:id])
>> @users = @search.users
>> end
>>
>> def index
>> @users = User.search(params[:search])
>> end
>> end
>
>
> /views/searches/show.html.rb:
>
> <h1>Search Results</h1>
>> <%= render @users.to_a %>
>>
>
>
> --
> 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/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.