简体   繁体   English

在rails 4.0上的ruby中搜索逻辑

[英]Search logic in ruby on rails 4.0

Well when we are implementing simple search its something like (searching for a song): 那么当我们实现简单的搜索时,它就像(搜索一首歌):

Model: 模型:

def self.search(query5)
         where("name LIKE ? ","%#{query5.downcase}%")
     end

but when the query is something like James TW when you love someone and the name of the song is when you love some James TW it doesnt return anything. 但是,如果你喜欢某人,那么查询就像詹姆斯的TW一样,而当你爱一些詹姆斯的时候,这首歌的名字就不会有任何回报。 So what do I do about that hat the correct logic for that? 那么我该怎么办这个帽子的正确逻辑呢?

It's not currently being maintained, but I've used the Ransack gem to great success. 它目前尚未维护,但我使用Ransack宝石取得了巨大成功。 It removes much of this complexity. 它消除了这种复杂性。

SQL LIKE expression will not work in your case. SQL LIKE表达式在您的情况下不起作用。 You should think of using a full text search engine . 您应该考虑使用全文搜索引擎

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM