Return results for packages only with screenshots.
Currently the packages controller is not working well. The JOIN is not the best way apparently as the 'description' column exists for both the "packages" and the "screenshots" table. So another way to query for the data needs to be found.
This commit is contained in:
parent
f9e920aea5
commit
88dfb33721
3 changed files with 14 additions and 4 deletions
|
|
@ -1,13 +1,19 @@
|
|||
class PackagesController < ApplicationController
|
||||
def index
|
||||
@packages = Package
|
||||
|
||||
if params[:with_screenshots]=='yes'
|
||||
@packages = @packages.joins(:screenshots).where('screenshots.approved = ?', true)
|
||||
end
|
||||
|
||||
if params[:search]
|
||||
query = '%'+params[:search]+'%'
|
||||
# TODO: Index on lower(…) is missing. Does not scale.
|
||||
# TODO: Consider using a serious search engine like Xapian or ElasticSearch.
|
||||
@packages = Package.where("lower(description) like lower(?) or lower(name) like lower(?)", query, query).order('name').first(20)
|
||||
else
|
||||
@packages = Package.order('name').first(20)
|
||||
@packages = @packages.where("lower(description) like lower(?) or lower(name) like lower(?)", query, query)
|
||||
end
|
||||
|
||||
@packages = @packages.order('name').limit(20)
|
||||
end
|
||||
|
||||
def with_screenshots
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<%# Show search results %>
|
||||
|
||||
<% if @packages %>
|
||||
<% if @packages.count>0 %>
|
||||
<h1>Class=<%= @packages.class %></h1>
|
||||
<ul>
|
||||
<% @packages.each do |package| %>
|
||||
<li>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
<%= form_tag(url_for, method: "get") do %>
|
||||
<%= text_field_tag :search, '', autofocus: true, placeholder: 'What are you looking for...' %>
|
||||
|
|
||||
With screenshots? <%= check_box_tag 'with_screenshots', 'yes', true %>
|
||||
|
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue