使用 Rails 3.2。我有下表:
name address
=======================================
Hilton Hotel New York, USA
Hilton Hotel Paris, France
Mandarin Hotel Chicago, USA
Le Meridien Hotel New York, USA
和以下查询:
term = "%#{params[:term]}%"
shops = Shop.limit(10).where("name LIKE ? OR address like ?", term, term)
我的预期结果是这样的:
Search - "Hilton"
Result - "Hilton Hotel, New York, USA"; "Hilton Hotel, Paris, France"
Search - "Hilton USA"
Result - "Hilton Hotel, New York, USA"
Search - "New York"
Result - "Hilton Hotel, New York, USA"; "Le Meridien Hotel, New York, USA"
我应该如何重写我的查询?
谢谢。