我正在使用ThinkingSphinx进行通过Book模型的简单搜索。我book_indexes.rb看起来是这样的:获取不基于整个索引值的搜索结果
ThinkingSphinx::Index.define :book, with: :active_record do
indexes title
indexes author
indexes publishing_date
indexes isbn
end
和控制器动作看起来像这样
def index
@books = Book.search(params[:search])
end
到目前为止一切正常,因为它应该是,当我键入“圣经”,它返回本书名为“圣经” 。但是有可能获得不是基于整个标题的搜索结果吗?用更简单的话来说,当我搜索“围脖”或“b”时,我希望得到“圣经”。
编辑
我thinking_sphinx.yml现在是:
development:
enable_star: true
min_infix_len: 1
min_prefix_len: 1
和控制器动作:
@books = Book.search("*#{params[:search]}*")
,但它仍然工程一样的,只是没有任何查询,只需加载后页面,@books是零
你已经运行'rake ts:index'或'rake ts:rebuild'? – claptimes
nope,会在一分钟内尝试 – Leo
是的,这就是我需要做的,我也删除了来自think_sphinx.yml的min_infix_len:1,因为它引发了一个错误,说前缀和infifes不能同时启用。 thx – Leo