Would this require full-text search or is it possible to do with a method?
I have a table of Chinese sentences and I want to find all the records that include a string.
For example:
irb(main):007:0> Hint.all
Hint Load (0.7ms) SELECT "hints".* FROM "hints"
[
[0] #<Hint:0x007fb99c9d1900> {
:id => 107,
:sentence => "你叫什么名字?",
:user => nil,
:learned => nil,
:created_at => Sat, 05 Jan 2013 21:04:06 UTC +00:00,
:updated_at => Sat, 05 Jan 2013 21:04:06 UTC +00:00
},
[1] #<Hint:0x007fb99f2acc30> {
:id => 108,
:sentence => "当时有约翰做他们的助手。",
:user => nil,
:learned => nil,
:created_at => Sat, 05 Jan 2013 21:04:23 UTC +00:00,
:updated_at => Sat, 05 Jan 2013 21:04:23 UTC +00:00
},
[2] #<Hint:0x007fb99f2ac618> {
:id => 109,
:sentence => "马可和家人可能过着舒适的生活,因为他们在城里有自己的房子,家里有仆人。",
:user => nil,
:learned => nil,
:created_at => Sat, 05 Jan 2013 21:19:43 UTC +00:00,
:updated_at => Sat, 05 Jan 2013 21:19:43 UTC +00:00
}
]
I want to search for "名字" and it return a list of records that have that string in the sentence
table. In this case it would find a match in [0].
(if full-text search is required, can you recommend something that will work with Chinese and heroku, as close to free as possible?)
您可以做这样的事情吗,还是我缺少有关Unicode符号的东西?
Hint.where("sentence LIKE '%名字%'")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.