Search code examples
ruby-on-railsrubysphinxthinking-sphinx

Thinking sphinx search doesnt return any result


i'm trying to implement simple search function with thinking sphinx, basing on this. i managed to set sphinx up, but when i try it in a console, 0 results are found every time. i'm wondering what is wrong here...

indices/news_post_index.rb:

ThinkingSphinx::Index.define :news_post, :with => :active_record do
  indexes title
  indexes content
end

and the rails console output:

2.0.0p0 :013 > NewsPost.create!(title: "awesome post", content: "this post is awesome and you know it", published_at: "2001-01-01")
   (0.3ms)  BEGIN
  NewsPost Exists (60.7ms)  SELECT 1 AS one FROM `news_posts` WHERE `news_posts`.`slug` = 'awesome-post' LIMIT 1
  SQL (48.3ms)  INSERT INTO `news_posts` (`content`, `created_at`, `published_at`, `slug`, `title`, `updated_at`) VALUES ('this post is awesome and you know it', '2013-09-10 08:18:35', '2001-01-01', 'awesome-post', 'awesome post', '2013-09-10 08:18:35')
   (40.1ms)  COMMIT
 => #<NewsPost id: 2, published_at: "2001-01-01", content: "this post is awesome and you know it", title: "awesome post", created_at: "2013-09-10 08:18:35", updated_at: "2013-09-10 08:18:35", slug: "awesome-post"> 
2.0.0p0 :014 > NewsPost.search "awesome post"
  Sphinx Query (0.9ms)  SELECT * FROM `news_post_core` WHERE MATCH('awesome post @sphinx_internal_class_name (NewsPost)') AND `sphinx_deleted` = 0 LIMIT 0, 20
  Sphinx  Found 0 results
 => [] 

From what i understand title is indexed, and so I should be able to search for it. but no matter what my key is, results are always empty array, no results at all...


Solution

  • Run rake ts:index after every update, then search.