我正在尝试基于此思想狮身人面像实现简单的搜索功能。我设法设置了狮身人面像,但是当我在控制台中尝试时,每次都会找到0个结果。我想知道这里出了什么问题...
indexs / 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
=> []
根据我的理解,标题已编入索引,因此我应该能够对其进行搜索。但是不管我的关键是什么,结果总是空数组,根本没有结果...
rake ts:index
每次更新后运行,然后搜索。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句