Local Keyword Queries

3 views
Skip to first unread message

Tony Payne

unread,
Jan 28, 2010, 11:19:44 PM1/28/10
to Sunspot
If I've followed the recent discussions correctly, 1.0rc2 should now
have the ability to do a local keyword search. I've tried this and
have not been able to make it work. Here are the queries I'm running:

Straight keyword-based query finds 1456 results:

INFO: [] webapp=/solr path=/select params={fl=*
+score&start=0&q=strip&qf=menu_item_type_name_text+restaurant_name_text
+name_text&wt=ruby&fq=type:MenuItemLocation&fq=menu_item_type_id_i:
1&rows=10&defType=dismax} hits=1456 status=0 QTime=29

Spatial query finds 0 results:

Jan 28, 2010 8:14:45 PM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={spatial={!radius%3D10.0+sort
%3Dtrue}
42.0591155,-80.1540226&start=0&q=*:*&wt=ruby&fq=type:MenuItemLocation&fq=menu_item_type_id_i:
1&rows=10} hits=0 status=0 QTime=219

The MenuItemLocation configuration:

searchable :auto_index => false do
text :name, :restaurant_name, :menu_item_type_name

integer :calories, :fat, :sat_fat, :cal_from_fat, :protein, :carbohydrate, :fiber, :cholesterol, :sodium, :sugars, :trans_fat, :menu_item_type_id
coordinates { [latitude, longitude] }
end

The search:

MenuItemLocation.search do
near(Geokit::Geocoders::MultiGeocoder.geocode(params
[:l]), :distance => params[:r].to_f || 10, :sort => true)
keywords params[:q]
with(:menu_item_type_id, MenuItemType.find_by_name('Entree').try
(:id))
paginate :page => 1, :per_page => 10
end

I figure there's a good chance I've got it misconfigured. I'm new to
sunspot (but not solr) and I've come up with my configurations mostly
from reading the source. Am I doing something wrong or is local solr
still not working with sunspot?

Sunspot looks like a fantastic upgrade from the acts_as_solr with tons
of hacks I've been surviving on for the last few years. Thanks!

Tony

Mat Brown

unread,
Jan 29, 2010, 8:14:22 AM1/29/10
to ruby-s...@googlegroups.com
Hey Tony,

Just to make sure - you reindexed your data after upgrading to Sunspot
1.0, right?

solr-spatial-light stores lat/lng in TrieDoubleFields, which means the
initial range filters to get a bounding box are quite efficient. But
it does mean that indices created under LocalSolr need to be
reindexed.

Let me know, and we'll work on it from there.

Thanks!
Mat

> --
> You received this message because you are subscribed to the Google Groups "Sunspot" group.
> To post to this group, send email to ruby-s...@googlegroups.com.
> To unsubscribe from this group, send email to ruby-sunspot...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ruby-sunspot?hl=en.
>
>

Mat Brown

unread,
Jan 29, 2010, 4:30:50 PM1/29/10
to Sunspot
That's great news that it's working, but if your :coordinates method
was returning an object that responds to :lat and :lng, that should've
worked too... what kind of object was it? Normal ruby class? Struct?
OpenStruct?

Thanks!
Mat

On Fri, Jan 29, 2010 at 16:28, Tony Payne <payne...@gmail.com> wrote:
> Mat,
>
> Looks like I got it working. Here's the change I made:
>
> -    coordinates :location
> +    coordinates { [location.lat, location.lng] }
>
> Thanks for your help!
>
>
> On Jan 29, 2010, at 1:01 PM, Mat Brown wrote:
>
>> Hi Tony,
>>
>> Not sure if it is the root cause of the issue, but there are a couple
>> of things I noticed about the adapter:
>>
>> - Sunspot adapters are comprised of two classes - a DataAccessor and
>> an InstanceAdapter. The #id method would go in the InstanceAdapter and
>> the other two in the DataAccessor. Here's an example:
>> http://github.com/outoftime/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/adapters.rb
>> - Did you register your adapters with Sunspot? Check out lines #4 and
>> #5 here: http://github.com/outoftime/sunspot/blob/master/sunspot_rails/rails/init.rb
>> - you need the equivalent in your app, probably in an initializer.
>> Note that in your case the second argument would be MenuItemLocation
>> instead of ActiveRecord::Base
>>
>> Let me know if that helps!
>>
>> Mat
>>
>> On Fri, Jan 29, 2010 at 15:35, Tony Payne <payne...@gmail.com> wrote:
>>> Also, here's the adapter I'm using for the MenuItemLocation object.
>>>
>>>
>>>
>>>
>>>
>>> Thanks!
>>> Tony
>>>
>>> On Jan 29, 2010, at 11:01 AM, Mat Brown wrote:
>>>
>>>> Tony, can you send me a small subset of your data that I can use to
>>>> try to reproduce?
>>>>
>>>> On Fri, Jan 29, 2010 at 13:59, Tony Payne <payne...@gmail.com> wrote:
>>>>> No, the behavior is the same.
>>>>>
>>>>> Tony
>>>>>
>>>>> On Jan 29, 2010, at 10:50 AM, Mat Brown wrote:
>>>>>
>>>>>> And is it working now?
>>>>>>
>>>>>> On Fri, Jan 29, 2010 at 13:49, Tony Payne <payne...@gmail.com> wrote:
>>>>>>>
>>>>>>> This is my configuration


>>>>>>>
>>>>>>>  searchable :auto_index => false do
>>>>>>>    text :name, :restaurant_name, :menu_item_type_name
>>>>>>>    integer :calories, :fat, :sat_fat, :cal_from_fat, :protein, :carbohydrate, :fiber, :cholesterol, :sodium, :sugars, :trans_fat

>>>>>>>    integer :menu_item_type_id
>>>>>>>    coordinates :location
>>>>>>>  end
>>>>>>>
>>>>>>> The location method returns an object that responds to methods lat and lng. The data has been reindexed
>>>>>>>
>>>>>>> Tony
>>>>>>>
>>>>>>> On Jan 29, 2010, at 10:34 AM, Mat Brown wrote:
>>>>>>>
>>>>>>>> Hey Tony,
>>>>>>>>
>>>>>>>> Missed this before, but I don't see your model configured for indexing
>>>>>>>> lat/lng. You'll want something like this:
>>>>>>>>
>>>>>>>>    searchable do
>>>>>>>>      coordinates { [self.lat, self.lng] }
>>>>>>>>      # etc.
>>>>>>>>    end
>>>>>>>>
>>>>>>>> With that configuration in place, you'll need to reindex your data,
>>>>>>>> then try your search and let me know how it goes.
>>>>>>>>
>>>>>>>> I suppose Sunspot should probably fail fast if geo search is attempted
>>>>>>>> on a model that doesn't have geo indexing configured...
>>>>>>>>
>>>>>>>> Mat
>>>>>>>>
>>>>>>>> On Fri, Jan 29, 2010 at 12:30, Tony Payne <payne...@gmail.com> wrote:
>>>>>>>>> Mat, this is a new installation 1.0rc2 is the first release of Sunspot
>>>>>>>>> I've used.
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Tony


>>>>>>>>>
>>>>>>>>> On Jan 29, 5:14 am, Mat Brown <m...@patch.com> wrote:
>>>>>>>>>> Hey Tony,
>>>>>>>>>>
>>>>>>>>>> Just to make sure - you reindexed your data after upgrading to Sunspot
>>>>>>>>>> 1.0, right?
>>>>>>>>>>
>>>>>>>>>> solr-spatial-light stores lat/lng in TrieDoubleFields, which means the
>>>>>>>>>> initial range filters to get a bounding box are quite efficient. But
>>>>>>>>>> it does mean that indices created under LocalSolr need to be
>>>>>>>>>> reindexed.
>>>>>>>>>>
>>>>>>>>>> Let me know, and we'll work on it from there.
>>>>>>>>>>
>>>>>>>>>> Thanks!
>>>>>>>>>> Mat
>>>>>>>>>>

Tony Payne

unread,
Feb 1, 2010, 12:49:08 PM2/1/10
to Sunspot
It was an active record model class

On Jan 29, 1:30 pm, Mat Brown <m...@patch.com> wrote:
> That's great news that it's working, but if your :coordinates method
> was returning an object that responds to :lat and :lng, that should've
> worked too... what kind of object was it? Normal ruby class? Struct?
> OpenStruct?
>
> Thanks!
> Mat
>

> On Fri, Jan 29, 2010 at 16:28, Tony Payne <paynein...@gmail.com> wrote:
> > Mat,
>
> > Looks like I got it working. Here's the change I made:
>
> > -    coordinates :location
> > +    coordinates { [location.lat, location.lng] }
>
> > Thanks for your help!
>
> > On Jan 29, 2010, at 1:01 PM, Mat Brown wrote:
>
> >> Hi Tony,
>
> >> Not sure if it is the root cause of the issue, but there are a couple
> >> of things I noticed about the adapter:
>
> >> - Sunspot adapters are comprised of two classes - a DataAccessor and
> >> an InstanceAdapter. The #id method would go in the InstanceAdapter and
> >> the other two in the DataAccessor. Here's an example:

> >>http://github.com/outoftime/sunspot/blob/master/sunspot_rails/lib/sun...


> >> - Did you register your adapters with Sunspot? Check out lines #4 and

> >> #5 here:http://github.com/outoftime/sunspot/blob/master/sunspot_rails/rails/i...


> >> - you need the equivalent in your app, probably in an initializer.
> >> Note that in your case the second argument would be MenuItemLocation
> >> instead of ActiveRecord::Base
>
> >> Let me know if that helps!
>
> >> Mat
>

> >> On Fri, Jan 29, 2010 at 15:35, Tony Payne <paynein...@gmail.com> wrote:
> >>> Also, here's the adapter I'm using for the MenuItemLocation object.
>
> >>> Thanks!
> >>> Tony
>
> >>> On Jan 29, 2010, at 11:01 AM, Mat Brown wrote:
>
> >>>> Tony, can you send me a small subset of your data that I can use to
> >>>> try to reproduce?
>

> >>>> On Fri, Jan 29, 2010 at 13:59, Tony Payne <paynein...@gmail.com> wrote:
> >>>>> No, the behavior is the same.
>
> >>>>> Tony
>
> >>>>> On Jan 29, 2010, at 10:50 AM, Mat Brown wrote:
>
> >>>>>> And is it working now?
>

> >>>>>> On Fri, Jan 29, 2010 at 13:49, Tony Payne <paynein...@gmail.com> wrote:
>
> >>>>>>> This is my configuration
>
> >>>>>>>  searchable :auto_index => false do
> >>>>>>>    text :name, :restaurant_name, :menu_item_type_name
> >>>>>>>    integer :calories, :fat, :sat_fat, :cal_from_fat, :protein, :carbohydrate, :fiber, :cholesterol, :sodium, :sugars, :trans_fat
> >>>>>>>    integer :menu_item_type_id
> >>>>>>>    coordinates :location
> >>>>>>>  end
>
> >>>>>>> The location method returns an object that responds to methods lat and lng. The data has been reindexed
>
> >>>>>>> Tony
>
> >>>>>>> On Jan 29, 2010, at 10:34 AM, Mat Brown wrote:
>
> >>>>>>>> Hey Tony,
>
> >>>>>>>> Missed this before, but I don't see your model configured for indexing
> >>>>>>>> lat/lng. You'll want something like this:
>
> >>>>>>>>    searchable do
> >>>>>>>>      coordinates { [self.lat, self.lng] }
> >>>>>>>>      # etc.
> >>>>>>>>    end
>
> >>>>>>>> With that configuration in place, you'll need to reindex your data,
> >>>>>>>> then try your search and let me know how it goes.
>
> >>>>>>>> I suppose Sunspot should probably fail fast if geo search is attempted
> >>>>>>>> on a model that doesn't have geo indexing configured...
>
> >>>>>>>> Mat
>

Gregory Foster

unread,
Feb 2, 2010, 5:50:29 PM2/2/10
to Sunspot
Just to chime in, I'm observing the same behavior on 1.0rc2. Works
fine if I specify latitude and longitude in an array, does not work at
all if I hand off an ActiveRecord instance with public #lat and #lng
methods. Makes me wonder, how is Sunspot testing to see if the given
object responds to #lat and #lng messages?

If it's any help, in my case I've specified public #lat and #lng
methods which effectively alias the #latitude and #longitude columns/
attributes in my ActiveRecord model.

Really glad to finally get it working :)
gf

Mat Brown

unread,
Feb 2, 2010, 6:24:32 PM2/2/10
to ruby-s...@googlegroups.com
OK, good to know - I'll put a regression test in Sunspot::Rails next
week and figure out what's going on. As I recall, it's just using a
series of #respond_to? calls to figure out which methods should be
called on the coordinates object - would think that would be OK with
AR but apparently not.

Ticket here for all who are interested:

http://outoftime.lighthouseapp.com/projects/20339-sunspot/tickets/69-using-ar-model-for-coordinates-object-doesnt-work

Mat

Reply all
Reply to author
Forward
0 new messages