Class: SearchPage

Inherits:
Page
  • Object
show all
Defined in:
app/models/search_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#queryObject

Returns the value of attribute query.



3
4
5
# File 'app/models/search_page.rb', line 3

def query
  @query
end

#query_resultObject

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 ####

Returns:

  • (Boolean)


90
91
92
# File 'app/models/search_page.rb', line 90

def cache?
  false
end

#helperObject



121
122
123
# File 'app/models/search_page.rb', line 121

def helper
  @helper ||= ActionView::Base.new
end

#renderObject



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