Class: SearchPage
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
-
#query_result ⇒ Object
Returns the value of attribute query_result.
Instance Method Summary collapse
-
#cache? ⇒ Boolean
“Behavior” methods ####.
- #helper ⇒ Object
- #render ⇒ Object
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
3 4 5 |
# File 'app/models/search_page.rb', line 3 def query @query end |
#query_result ⇒ Object
Returns the value of attribute query_result.
3 4 5 |
# File 'app/models/search_page.rb', line 3 def query_result @query_result end |
Instance Method Details
#cache? ⇒ Boolean
“Behavior” methods ####
90 91 92 |
# File 'app/models/search_page.rb', line 90 def cache? false end |
#helper ⇒ Object
121 122 123 |
# File 'app/models/search_page.rb', line 121 def helper @helper ||= ActionView::Base.new end |
#render ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/models/search_page.rb', line 94 def render @query_result = [] @query = "" q = @request.parameters[:q] exclude_pages = (@request.parameters[:exclude_pages] || '').split(',') case Page.connection.adapter_name.downcase when 'postgresql' sql_content_check = "((lower(page_parts.content) ILIKE ?) OR (lower(title) ILIKE ?))" else sql_content_check = "((LOWER(page_parts.content) LIKE ?) OR (LOWER(title) LIKE ?))" end unless (@query = q.to_s.strip).blank? tokens = query.split.collect { |c| "%#{c.downcase}%"} pages = Page.find(:all, :order => 'published_at DESC', :include => [ :parts ], :conditions => [(["#{sql_content_check}"] * tokens.size).join(" AND "), *tokens.collect { |token| [token] * 2 }.flatten]) @query_result = pages.delete_if { |p| !p.published? || exclude_pages.include?(p.url)} end lazy_initialize_parser_and_context if layout parse_object(layout) else render_part(:body) end end |