[英]postgresql full text search rails title and description
I am trying to search a model with title and description, but having the following error. 我正在尝试搜索具有标题和描述的模型,但是出现以下错误。 I want to be able to search title and description and the type of job. 我希望能够搜索标题和描述以及工作类型。 Any help will be really appreciated. 任何帮助将不胜感激。
PG::DatatypeMismatch: ERROR: argument of OR must be type boolean, not type character varying LINE 1: ...T "refinery_jobs".* FROM "refinery_jobs" WHERE (title OR d... ^ : SELECT "refinery_jobs".* FROM "refinery_jobs" WHERE (title OR description LIKE '%consultant%' AND job_type LIKE '%Contract%') LIMIT 10 PG :: DatatypeMismatch:错误:OR的参数必须为布尔型,而不是字符类型不同LINE 1:... T“ refinery_jobs”。* FROM“ refinery_jobs”其中(标题OR d ... ^:选择“ refinery_jobs”。 *从“ refinery_jobs”位置(标题或说明,如'%consultant%'和job_type如'%Contract%')LIMIT 10
Here is my query 这是我的查询
results << model.limit(RESULTS_LIMIT).where("title OR description LIKE ? AND job_type LIKE ?","%#{query}%","%#{job_type}%")
your error says that postgresql expects both side of an OR
to evaluate to a truthy value. 您的错误是说postgresql期望OR
的两端都求值为真实值。 in your sql, this error pertains to the left side of OR
which is simply title
. 在您的sql中,此错误与OR
的左侧有关,后者仅是title
。 just change your query to 只需将查询更改为
where(
"(title LIKE :query OR description LIKE :query) AND job_type LIKE :job_type",
query: "%#{query}%",
job_type: "%#{job_type}%"
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.