I ve used 瑞安·比特与Ajax 系列进行搜索,以撰写一些基本搜索功能。
What it basically does is take a string from a form, and performs a like query via a model method. What I m trying to do is conditionally search to different columns(due_date and name) in the database with a single string that I parse with the Date class. That way a user can search for items by a date, or the item name witht he same form. My method looks like:
def self.search(search)
if search
search_date = Date.parse(search) rescue nil
end
if search_date
where( due_date = ? , search_date)
elsif search
where( UPPER(name) LIKE ? , "%#{search.upcase}%")
else
scoped
end
end
如同用户类型在某一日期时一样,该日期的班级能够进行整顿,在数据库中查看任何预定日期的物体。 问题在于,如果它是一个日期,它能够 par平,搜查就会缓慢。
我想知道,是否有办法加快这项工作。 日期等级是否如此缓慢? 我是否应该有两种不同的方法? 或者,我是否完全改写我的搜寻?