Skip to content

Commit

Permalink
Fix to site-search for better DB comptibility (Oracle in particular h…
Browse files Browse the repository at this point in the history
…ad a problem)
  • Loading branch information
tslocke committed Jun 20, 2008
1 parent 8f111ea commit d31a71c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions hobo/lib/hobo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,24 @@ def find_by_search(query, search_targets=nil)
# FIXME: This should interrogate the model-router directly, there's no need to enumerate models
# By default, search all models, but filter out...
Hobo.models.select do |m|
ModelRouter.linkable?(m, :show) && # ...non-linkables
m.search_columns.any? # and models with no search-columns
ModelRouter.linkable?(m, :show) && # ...non-linkables
m.search_columns.any? # and models with no search-columns
end
end

query_words = ActiveRecord::Base.connection.quote_string(query).split

search_targets.build_hash do |search_target|
conditions = query_words.map do |word|
"(" + search_target.search_columns.map { |column| %(#{column} like "%#{word}%") }.join(" or ") + ")"
end.join(" and ")
conditions = []
parameters = []
query_words.each do |word|
column_queries = search_target.search_columns.map { |column| "#{column} like ?" }
conditions << "(" + column_queries.join(" or ") + ")"
parameters.concat(["%#{word}%"] * column_queries.length)
end
conditions = conditions.join(" and ")

results = search_target.find(:all, :conditions => conditions)
results = search_target.find(:all, :conditions => [conditions, *parameters])
[search_target.name, results] unless results.empty?
end
end
Expand Down

0 comments on commit d31a71c

Please sign in to comment.