Question regarding use of keywords

21 views
Skip to first unread message

Tom Cocca

unread,
Oct 11, 2010, 3:16:42 PM10/11/10
to ruby-sunspot
Hi Mat,

I am going through some very old code that is using sunpot 0.10.6 and I found the following:


def search(params)
  Post.search do |query|
    query.fulltext self.key_words do |ft|
      ft.fields :title, :body
    end
  end
end

Do you happen to remember what query.fulltext "some keywords" do { ... } did as opposed to query.keywords "some keywords", :fields => :one, :two  ?

I can't remember if it did something different or if the dsl has changed in a recent version or if it was just an alias to the same thing ...

Also, on another note regarding fulltext searching:

There is no possible way to do say different keywords matches on different sets of fields is there?

Say, I wanted to search my text :title, :body  fields for "John Doe" AND my text :comments fields for "Jane Smith"
like so:

fulltext 'John Doe', :fields => :title, :body
fulltext 'Jane Smith', :fields => :comments

There is no way to do this combination correct, right now I think I would have to do:

fulltext "John Doe Jane Smith", :fields => :title, :body, :comments

but of course this will match :title and body on 'Jane' or 'Smith' and comments on 'John' or 'Doe' which is not entirely the disired behavior.

Thanks,
~ Tom

Mat Brown

unread,
Oct 11, 2010, 3:23:40 PM10/11/10
to ruby-s...@googlegroups.com
Hi Tom,

To answer your first question: they're two ways of doing the same
thing. The DSL exposes more functionality, but some of the basic stuff
can be passed as options instead.

Recent versions of Sunspot (1.1+ for sure, maybe 1.0 as well) allow
you to use #fulltext more than once, with different options (e.g.
different fields). So yep, you can do that.

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

Tom Cocca

unread,
Oct 11, 2010, 3:27:10 PM10/11/10
to ruby-s...@googlegroups.com
Thanks Mat,

I thought it was just an alias so thats good, nothing like looking at code after a year and not remembering anything about it.

As to the second point of calling fulltext more than once, I'll give it a shot, the wiki made it sound like I couldn't do it:

http://github.com/outoftime/sunspot/wiki/Fulltext-search

specifically this line:  "Note that the keywords method should not be called multiple times in one search – successive calls will overwrite the previously specified keywords."

Thanks though, I'll give it a shot today.

~ Tom

Mat Brown

unread,
Oct 11, 2010, 3:29:31 PM10/11/10
to ruby-s...@googlegroups.com
Ack, I believe the wiki is out of date in that respect -- thanks for
the heads up.

Tom Cocca

unread,
Oct 11, 2010, 4:05:57 PM10/11/10
to ruby-s...@googlegroups.com
Thanks Mat,

I'm assuming query.keywords can be used multiple times just like query.fulltext as it is just an alias correct?

~ Tom

Mat Brown

unread,
Oct 11, 2010, 4:06:43 PM10/11/10
to ruby-s...@googlegroups.com
Yep!

Tom Cocca

unread,
Oct 11, 2010, 4:11:34 PM10/11/10
to ruby-s...@googlegroups.com
Awesome, with this ability to fulltext on different field sets, life just gets better and better.

I am thinking about making a frontend with sorting/filtering/searching etc... to replace activescaffold and sunspot/solr is a perfect fit to take the feature set the next level.

Last question, is that any way to get the list of indexed "methods" for a Model?

~ Tom

Mat Brown

unread,
Oct 11, 2010, 4:15:32 PM10/11/10
to ruby-s...@googlegroups.com
Check out the Sunspot::Setup class -- it's not technically part of the
public API, but it definitely lets you introspect on all that sort of
thing.
Reply all
Reply to author
Forward
0 new messages