[英]How to search integer fields using searchkick?
How to make searchkick search integer fields? 如何使searchkick搜索整数字段?
Let's say i have a Book model with three properties namely name:string, author:string and pages:integer. 假设我有一个Book模型,具有三个属性,即name:string,author:string和pages:integer。
I want to search according to pages field. 我想根据页面字段进行搜索。 Right now if i use a query like below it works for string fields ie name and author but it doesnt work for pages field which is of integer type.
现在,如果我使用类似下面的查询,它适用于字符串字段,即名称和作者,但不适用于整数类型的页面字段。
Book.search(q,
misspellings: { below: 5 },
fields: [:name, :author, :pages],
order: { name: 'asc' },
page: params[:page],
per_page: 20)
I go to console and just searched Book.search(120, fields: [:pages]) and it returns empty result even though there are records with pages 120. Why is searchkick not searching for integer fields? 我进入控制台并仅搜索Book.search(120,fields:[:pages]),即使有记录包含第120页,它也返回空结果。为什么searchkick不搜索整数字段? I appreciate any help to this dilemma i am facing.
感谢您为我所面临的这一困境所提供的帮助。 Thanks!
谢谢!
I fixed it with this 我用这个修好了
In Book model 书中模型
def search_data
{
name: name,
author: author,
pages: pages.to_s
}
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.