fixes to model searches

This commit is contained in:
albert
2013-02-19 12:27:17 -05:00
parent e678427ee7
commit e0fdda3103
21 changed files with 68 additions and 68 deletions

View File

@@ -8,11 +8,11 @@ module Moderator
end
def execute
if params[:user_id]
if params[:user_id].present?
search_by_user_id(params[:user_id].split(/,/))
elsif params[:user_name]
elsif params[:user_name].present?
search_by_user_name(params[:user_name].split(/,/))
elsif params[:ip_addr]
elsif params[:ip_addr].present?
search_by_ip_addr(params[:ip_addr].split(/,/))
else
[]

View File

@@ -230,7 +230,7 @@ class Artist < ActiveRecord::Base
q = active
return q if params.blank?
case params[:name]
case params[:name].present?
when /^http/
q = q.url_matches(params[:name])
@@ -250,7 +250,7 @@ class Artist < ActiveRecord::Base
q = q.any_name_matches(params[:name])
end
if params[:id]
if params[:id].present?
q = q.where("id = ?", params[:id])
end

View File

@@ -42,19 +42,19 @@ class Comment < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:body_matches]
if params[:body_matches].present?
q = q.body_matches(params[:body_matches])
end
if params[:post_tags_match]
if params[:post_tags_match].present?
q = q.post_tags_match(params[:post_tags_match])
end
if params[:creator_name]
if params[:creator_name].present?
q = q.for_user_name(params[:creator_name])
end
if params[:creator_id]
if params[:creator_id].present?
q = q.for_creator(params[:creator_id].to_i)
end

View File

@@ -117,27 +117,27 @@ class Dmail < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:message_matches]
if params[:message_matches].present?
q = q.search_message(params[:message_matches])
end
if params[:owner_id]
if params[:owner_id].present?
q = q.for(params[:owner_id].to_i)
end
if params[:to_name]
if params[:to_name].present?
q = q.to_name_matches(params[:to_name])
end
if params[:to_id]
if params[:to_id].present?
q = q.where("to_id = ?", params[:to_id].to_i)
end
if params[:from_name]
if params[:from_name].present?
q = q.from_name_matches(params[:from_name])
end
if params[:from_id]
if params[:from_id].present?
q = q.where("from_id = ?", params[:from_id].to_i)
end

View File

@@ -25,30 +25,30 @@ class ForumPost < ActiveRecord::Base
end
def active
where("is_deleted = false")
where("forum_posts.is_deleted = false")
end
def search(params)
q = scoped
return q if params.blank?
if params[:creator_id]
if params[:creator_id].present?
q = q.where("creator_id = ?", params[:creator_id].to_i)
end
if params[:topic_id]
if params[:topic_id].present?
q = q.where("topic_id = ?", params[:topic_id].to_i)
end
if params[:topic_title_matches]
if params[:topic_title_matches].present?
q = q.joins(:topic).where("forum_topics.text_index @@ plainto_tsquery(?)", params[:topic_title_matches])
end
if params[:body_matches]
if params[:body_matches].present?
q = q.body_matches(params[:body_matches])
end
if params[:creator_name]
if params[:creator_name].present?
q = q.creator_name(params[:creator_name])
end

View File

@@ -25,11 +25,11 @@ class ForumTopic < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:title_matches]
if params[:title_matches].present?
q = q.title_matches(params[:title_matches])
end
if params[:title]
if params[:title].present?
q = q.where("title = ?", params[:title])
end

View File

@@ -34,19 +34,19 @@ class Note < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:body_matches]
if params[:body_matches].present?
q = q.body_matches(params[:body_matches])
end
if params[:post_tags_match]
if params[:post_tags_match].present?
q = q.post_tags_match(params[:post_tags_match])
end
if params[:creator_name]
if params[:creator_name].present?
q = q.creator_name(params[:creator_name])
end
if params[:creator_id]
if params[:creator_id].present?
q = q.where("creator_id = ?", params[:creator_id].to_i)
end

View File

@@ -15,15 +15,15 @@ class PoolVersion < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:updater_id]
if params[:updater_id].present?
q = q.for_user(params[:updater_id].to_i)
end
if params[:updater_name]
if params[:updater_name].present?
q = q.where("updater_id = (select _.id from users _ where lower(_.name) = ?)", params[:updater_name].downcase)
end
if params[:pool_id]
if params[:pool_id].present?
q = q.where("pool_id = ?", params[:pool_id].to_i)
end

View File

@@ -925,15 +925,15 @@ class Post < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:before_id]
if params[:before_id].present?
q = q.before_id(params[:before_id].to_i)
end
if params[:after_id]
if params[:after_id].present?
q = q.after_id(params[:after_id].to_i)
end
if params[:tag_match]
if params[:tag_match].present?
q = q.tag_match(params[:tag_match])
end

View File

@@ -22,15 +22,15 @@ class PostAppeal < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:creator_id]
if params[:creator_id].present?
q = q.for_user(params[:creator_id].to_i)
end
if params[:creator_name]
if params[:creator_name].present?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].downcase)
end
if params[:post_id]
if params[:post_id].present?
q = q.where("post_id = ?", params[:post_id].to_i)
end

View File

@@ -27,15 +27,15 @@ class PostFlag < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:creator_id]
if params[:creator_id].present?
q = q.where("creator_id = ?", params[:creator_id].to_i)
end
if params[:creator_name]
if params[:creator_name].present?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].downcase)
end
if params[:post_id]
if params[:post_id].present?
q = q.where("post_id = ?", params[:post_id].to_i)
end

View File

@@ -16,15 +16,15 @@ class PostVersion < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:updater_name]
if params[:updater_name].present?
q = q.updater_name(params[:updater_name])
end
if params[:updater_id]
if params[:updater_id].present?
q = q.where("updater_id = ?", params[:updater_id].to_i)
end
if params[:post_id]
if params[:post_id].present?
q = q.where("post_id = ?", params[:post_id].to_i)
end

View File

@@ -391,7 +391,7 @@ class Tag < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:name_matches]
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
@@ -399,7 +399,7 @@ class Tag < ActiveRecord::Base
q = q.where("category = ?", params[:category])
end
case params[:sort]
case params[:sort].present?
when "count"
q = q.order("post_count")

View File

@@ -17,15 +17,15 @@ class TagAlias < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:name_matches]
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
if params[:antecedent_name]
if params[:antecedent_name].present?
q = q.where("antecedent_name = ?", params[:antecedent_name])
end
if params[:id]
if params[:id].present?
q = q.where("id = ?", params[:id].to_i)
end

View File

@@ -76,15 +76,15 @@ class TagImplication < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:id]
if params[:id].present?
q = q.where("id = ?", params[:id].to_i)
end
if params[:name_matches]
if params[:name_matches].present?
q = q.name_matches(params[:name_matches])
end
if params[:antecedent_name]
if params[:antecedent_name].present?
q = q.where("antecedent_name = ?", params[:antecedent_name])
end

View File

@@ -325,15 +325,15 @@ class Upload < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:uploader_id]
if params[:uploader_id].present?
q = q.uploaded_by(params[:uploader_id].to_i)
end
if params[:uploader_name]
if params[:uploader_name].present?
q = q.where("uploader_id = (select _.id from users _ where lower(_.name) = ?)", params[:uploader_name].downcase)
end
if params[:source]
if params[:source].present?
q = q.where("source = ?", params[:source])
end

View File

@@ -464,19 +464,19 @@ class User < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:name]
if params[:name].present?
q = q.name_matches(params[:name].downcase)
end
if params[:name_matches]
if params[:name_matches].present?
q = q.name_matches(params[:name_matches].downcase)
end
if params[:min_level]
if params[:min_level].present?
q = q.where("level >= ?", params[:min_level].to_i)
end
if params[:id]
if params[:id].present?
q = q.where("id = ?", params[:id].to_i)
end

View File

@@ -28,19 +28,19 @@ class UserFeedback < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:user_id]
if params[:user_id].present?
q = q.for_user(params[:user_id].to_i)
end
if params[:user_name]
if params[:user_name].present?
q = q.where("user_id = (select _.id from users _ where lower(_.name) = ?)", params[:user_name].downcase)
end
if params[:creator_id]
if params[:creator_id].present?
q = q.where("creator_id = ?", params[:creator_id].to_i)
end
if params[:creator_name]
if params[:creator_name].present?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].downcase)
end

View File

@@ -28,19 +28,19 @@ class WikiPage < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:title]
if params[:title].present?
q = q.where("title LIKE ? ESCAPE E'\\\\'", params[:title].downcase.tr(" ", "_").to_escaped_for_sql_like)
end
if params[:creator_id]
if params[:creator_id].present?
q = q.where("creator_id = ?", params[:creator_id])
end
if params[:body_matches]
if params[:body_matches].present?
q = q.body_matches(params[:body_matches])
end
if params[:creator_name]
if params[:creator_name].present?
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].downcase)
end

View File

@@ -11,11 +11,11 @@ class WikiPageVersion < ActiveRecord::Base
q = scoped
return q if params.blank?
if params[:updater_id]
if params[:updater_id].present?
q = q.for_user(params[:updater_id].to_i)
end
if params[:wiki_page_id]
if params[:wiki_page_id].present?
q = q.where("wiki_page_id = ?", params[:wiki_page_id].to_i)
end

View File

@@ -1,7 +1,7 @@
<div id="c-forum-topics">
<div id="a-search">
<h1>Search Forum</h1>
<%= form_tag(forum_topics_path, :method => :get, :class => "simple_form") do %>
<%= form_tag(forum_posts_path, :method => :get, :class => "simple_form") do %>
<%= search_field "topic_title_matches", :label => "Title" %>
<%= search_field "body_matches", :label => "Body" %>
<%= search_field "creator_name", :label => "Author" %>