0

我正在尝试在基础上用思维狮身人面像实现简单的搜索功能。我设法设置了 sphinx,但是当我在控制台中尝试时,每次都找到 0 个结果。我想知道这里有什么问题...

指数/news_post_index.rb:

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

和 rails 控制台输出:

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
 => [] 

据我了解,标题已编入索引,因此我应该能够搜索它。但无论我的关键是什么,结果总是空数组,根本没有结果......

4

1 回答 1

1

每次更新后运行rake ts:index,然后搜索。

于 2013-09-10T08:47:03.680 回答