How to implement a search, for example, stack overflow

I implemented a full-text search using Sphinx and Sphinx Thinking . I want to add a column search. Some things, for example :-( example example)

Suppose you want to see actions related to you, just enter:

user:me 

He will then return the result with all the questions and answers related to the piemesons.

If you type

  votes:15 

he will return the result with all questions marked by the presence of more than 15 votes.

And if you type

  user:me votes:15 

then he will return all questions and answers that belong to you, with more than 15 votes.

How can I implement this thing?

My search results are now based on full-text search. How can I enable these features?

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

+6
ruby-on-rails search
source share
1 answer

:with in the thinking of the sphinx.

First of all, you must define these attributes in the index definition ( see the attribute section here ).

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

Then you can search for messages like this:

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

(I'm not sure if there is a more elegant ability to give open ranges, but 12..max_int should be enough)

Two important things:

  • If you want to count related objects (e.g. answers), you should use a cache counter
  • If your "user" is a polymorphic association, I recommend "CRC32(CONCAT(user_type, user_id))" instead of user.id
+2
source share

All Articles