views:

84

answers:

1

I have implemented the full text search using Sphinx and Thinking Sphinx. I want to add column wise search. Some thing like:-(taking an example of Stack Overflow)

Suppose you want to see actvities related to you, just type:

  user:me

Then it will return a result with all the questions and answers related to piemesons.

If you type

 votes:15

then it will return a result with all the questions tagged with having more than 15 votes.

And if you type

  user:me votes:15

then it will return all the questions and answers belonging to you with more than 15 votes.

How can I implement this thing?

Right now my search results are based upon full text search. How can these kinds of features be included?

Any options avaliable in Sphinx or Solr or any other search engines?

+1  A: 

:with option in thinking sphinx.

First of all, you have to define those attributes in your index definition (check out attributes section here).

has views_count, :as => :views, :type => :integer
has user.id, :as => :user, :type => :integer

Then you could search for posts like this:

Post.search '', :with => {:views => 12..maxint, :user => User.first.id}

(I am not sure if there is any more elegant possibility of giving open ranges, but 12..max_int should be enough)

Two important things:

  1. if you want to count related objects (e.g. responses), you should use counter cache
  2. if your "user" is polymorphic association, I recommend "CRC32(CONCAT(user_type, user_id))" instead of user.id
skalee