简体   繁体   English

Ruby on Rails:用Ruby代码替换SQL查询的“ LIKE”部分

[英]Ruby on Rails: Replacing the “LIKE” part of the SQL query with Ruby code

In my application I have a "LIKE" SQL query that is something like... 在我的应用程序中,我有一个类似的“ LIKE” SQL查询。

Item.where("name LIKE ?", "%"+params[:q]+"%").all

But I want to hit the db only 1x (at application start-up), since the number of Items is huge, and load this generic part... 但是我想只在数据库启动时(应用程序启动时)命中1倍的db,因为Items的数量很大,然后加载这个通用部分...

Item.all

...into memory (a global variable), so I can later reuse its content throughout the app, in different cases, and refined with some case-specific Ruby code (see the "LIKE" part). ...存入内存(一个全局变量),以便以后可以在不同情况下在整个应用程序中重用其内容,并使用一些特定于案例的Ruby代码进行完善(请参阅“ LIKE”部分)。

What's the speediest way to do such "filtering" with Ruby? 用Ruby进行这种“过滤”的最快方法是什么?

您可以为此使用低级缓存吗?

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

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