Sunspot::UnrecognizedFieldError: No field configured for Model with name 'attribute'

1,409 views
Skip to first unread message

viatropos

unread,
Feb 3, 2011, 6:54:00 PM2/3/11
to Sunspot
I have a simple searchable ActiveRecord model with a field "title":

class Model < ActiveRecord::Base
searchable do
text :title
end
end

When I run this:

Sunspot.search(Model) { with(:title, "test") }

..I get this error:

Sunspot::UnrecognizedFieldError: No field configured for Model
with name 'title'

The class `Model` has subclasses for STI in Rails, but I doubt that's
the issue. What am I missing here?

Thanks!

Matthew A. Brown

unread,
Feb 3, 2011, 7:48:56 PM2/3/11
to ruby-s...@googlegroups.com
Howdy,

You can't filter on text fields. If you want to do a keyword search on
:title, you want:

keywords('test')

Which will (by default) search all defined text fields. If you want to
match titles exactly, the :title field should be a string field,
rather than a text field.

More info here:
https://github.com/outoftime/sunspot/wiki/Setting-up-classes-for-search-and-indexing

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.
>
>

viatropos

unread,
Feb 3, 2011, 8:01:46 PM2/3/11
to Sunspot
Thanks! Works perfectly.

On Feb 3, 6:48 pm, "Matthew A. Brown" <mat.a.br...@gmail.com> wrote:
> Howdy,
>
> You can't filter on text fields. If you want to do a keyword search on
> :title, you want:
>
>     keywords('test')
>
> Which will (by default) search all defined text fields. If you want to
> match titles exactly, the :title field should be a string field,
> rather than a text field.
>
> More info here:https://github.com/outoftime/sunspot/wiki/Setting-up-classes-for-sear...
Reply all
Reply to author
Forward
0 new messages