Multiple word searching with Ruby, and MySQL

前端 未结 4 1547
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 11:06

I\'m trying to accomplish a multiple word searching in a quotes database using Ruby, ActiveRecord, and MySQL. The way I did is shown bellow, and it is working, but I would l

4条回答
  •  耶瑟儿~
    2021-01-15 11:35

    MySQL fulltext search not working, so best way to do this:

    class Quote
      def self.search_by_quote(query)
        words = query.to_s.strip.split
        words.map! { |word| "quote LIKE '%#{word}%'" }
        sql = words.join(" AND ")
        self.where(sql)
      end
    end
    

提交回复
热议问题