Find the list of fields indexed?

209 views
Skip to first unread message

Martin Streicher

unread,
Jun 8, 2011, 10:14:09 AM6/8/11
to Sunspot

I can ask if a model is searchable using searchable?

Can I also find the list of fields indexed within a class's searchable
block?

For example, if I have

searchable do
string(:name)
boolean(:published)
end

can I get a list that returns [:name, :published]?

Matthew A. Brown

unread,
Jun 8, 2011, 10:17:13 AM6/8/11
to ruby-s...@googlegroups.com
Martin,

Nothing that straightforward, but you can call
Sunspot::Setup.for(MyModel) and that will bring you back an object you
can introspect.

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

Martin Streicher

unread,
Jun 8, 2011, 10:28:04 AM6/8/11
to ruby-s...@googlegroups.com

Based on a previous question that Mat answered (located at http://groups.google.com/group/ruby-sunspot/browse_thread/thread/815cd71bfb81be59/da65179527232d60?lnk=gst&q=find+list+of+fields+indexed#da65179527232d60), I found the trick:

Sunspot::Setup.for(Klass).fields.map(&:name)

returns the symbols/field names used in the searchable block to create the index for Klass.

Mat advises this is not part of the public API.

Matthew A. Brown

unread,
Jun 8, 2011, 10:30:11 AM6/8/11
to ruby-s...@googlegroups.com
One of my goals for Sunspot 2.0 is to have much richer introspection
ability, including a public API for introspecting a model's search
setup.

Martin Streicher

unread,
Jun 8, 2011, 12:08:05 PM6/8/11
to ruby-s...@googlegroups.com

I wrote up a little something...

http://blog.locomotivellc.com/post/6321969631/sunspot-introspection

All, please let me know if you see errors.

Martin

terrenc...@gmail.com

unread,
May 24, 2013, 1:21:46 AM5/24/13
to ruby-s...@googlegroups.com
Hello, 
I was wondering if any of these introspection features are in sunspot 2.0 or if the method described in this thread are still the main way to 
access a models search setup and get fields that are being indexed in solr. 
Thanks, 
Terrence
Reply all
Reply to author
Forward
0 new messages