致命:在' /home/XXXX/searchengine/config/development.sphinx.conf&#39中找不到索引;

时间:2017-12-04 08:23:30

标签: ruby ruby-on-rails-5 thinking-sphinx

当我想要时,sphinx告诉我这个错误(rake ts:start) 我使用rails 5.1.4和ruby 2.4.1

Sphinx 2.2.9-id64-release (rel22-r5006)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/home/snoura/searchengine/config/development.sphinx.conf'...
FATAL: no indexes found in '/home/snoura/searchengine/config/development.sphinx.conf'

The Sphinx start command failed:
Command: searchd --pidfile --config "/home/snoura/searchengine/config/development.sphinx.conf"
Status:  1
Output:  See above

There may be more information about the failure in /home/snoura/searchengine/log/development.searchd.log.

这就是我的模型Post.rb

中的内容
define_index do
indexes content
indexes :name, sortable: true
end

1 个答案:

答案 0 :(得分:0)

这里有两点需要注意。

首先:您使用非常旧语法来定义索引(Taryn对您的问题的评论是正确的)。模型中的define_index是Thinking Sphinx v1 / v2的方法。思考Sphinx v3(支持Rails 3.2到5.x的版本)期望索引定义存在于app/indices目录中。因此,您要在那里添加一个文件(可能是post_index.rb),其中包含以下内容:

ThinkingSphinx::Index.define :post, :with => :active_record do
  indexes content
  indexes name, sortable: true
end

文档中提供了完整的索引定义语法: https://freelancing-gods.com/thinking-sphinx/indexing.html

要注意的第二件事是您需要在启动守护程序之前处理索引。这意味着运行rake ts:index