Search feature repaired
This commit is contained in:
parent
f940e96014
commit
f3a8b7c3a5
8 changed files with 60 additions and 29 deletions
|
|
@ -6,6 +6,13 @@ class PackagesController < ApplicationController
|
|||
@packages = @packages.text_search(params[:query])
|
||||
end
|
||||
|
||||
if params[:search]
|
||||
logger.debug "Searching for #{params[:search]}"
|
||||
#search_phrase = params[:search].split.join('&')
|
||||
#@packages = @packages.general_search([:name,:description], search_phrase, :language=>'english', :rank=>true)
|
||||
@packages = @packages.general_search(params[:search])
|
||||
end
|
||||
|
||||
# Limit the packages to those that have approved screenshots.
|
||||
# Also eager-load the screenshots.
|
||||
if params[:show]=='onlywith'
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
class Package < ActiveRecord::Base
|
||||
# PostgreSQL-based full-text search:
|
||||
# https://github.com/Casecommons/pg_search
|
||||
include PgSearch
|
||||
# TODO: Make search weighted on users' rating
|
||||
pg_search_scope :general_search, :against => [:name, :description, :long_description]
|
||||
|
||||
has_many :screenshots, :inverse_of=>:package
|
||||
|
||||
default_scope {
|
||||
order('name ASC')
|
||||
}
|
||||
|
||||
|
||||
# Return a query of all packages that have screenshots
|
||||
def self.with_screenshots
|
||||
# Query for all packages who's ID appears in a screenshot's "package_id" field
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
.item
|
||||
// Switch to grid view
|
||||
//a href=url(:package, :index)
|
||||
= link_to packages_grid_path
|
||||
= link_to packages_grid_path, search: params[:search]
|
||||
img src="/images/sidebar/grid0.svg" width=40 height=40
|
||||
.item.space
|
||||
img src="/images/sidebar/list1.svg" width=40 height=40
|
||||
|
|
@ -15,35 +15,35 @@
|
|||
.item.space
|
||||
// Switch to list view
|
||||
//a href=url(:package, :index, view: 'list')
|
||||
= link_to packages_list_path
|
||||
= link_to packages_list_path, search: params[:search]
|
||||
img src="/images/sidebar/list0.svg" width=40 height=40
|
||||
|
||||
// Cycling between with/without/any packages filter
|
||||
.caption Screenshots
|
||||
- if params['show'] == 'with'
|
||||
.item
|
||||
a href=url_for(show: 'without')
|
||||
a href=url_for(show: 'without', search: params[:search])
|
||||
img src="/images/sidebar/show-without0.svg" width=40 height=40
|
||||
.item
|
||||
img src="/images/sidebar/show-with1.svg" width=40 height=40
|
||||
.item.space
|
||||
a href=url_for(show: 'any')
|
||||
a href=url_for(show: 'any', search: params[:search])
|
||||
img src="/images/sidebar/show-any0.svg" width=40 height=40
|
||||
- elsif params['show'] == 'without'
|
||||
.item
|
||||
img src="/images/sidebar/show-without1.svg" width=40 height=40
|
||||
.item
|
||||
a href=url_for(show: 'with')
|
||||
a href=url_for(show: 'with', search: params[:search])
|
||||
img src="/images/sidebar/show-with0.svg" width=40 height=40
|
||||
.item.space
|
||||
a href=url_for(show: 'any')
|
||||
a href=url_for(show: 'any', search: params[:search])
|
||||
img src="/images/sidebar/show-any0.svg" width=40 height=40
|
||||
- else # any
|
||||
.item
|
||||
a href=url_for(show: 'without')
|
||||
a href=url_for(show: 'without', search: params[:search])
|
||||
img src="/images/sidebar/show-without0.svg" width=40 height=40
|
||||
.item
|
||||
a href=url_for(show: 'with')
|
||||
a href=url_for(show: 'with', search: params[:search])
|
||||
img src="/images/sidebar/show-with0.svg" width=40 height=40
|
||||
.item.space
|
||||
img src="/images/sidebar/show-any1.svg" width=40 height=40
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
' Sorry. I couldn't find any software package like that.
|
||||
' Would you like to view
|
||||
'
|
||||
a href=url(:package, :index) all packages
|
||||
a href=url_for(show: params[:show]) all packages
|
||||
'
|
||||
' instead?
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
' Sorry. I couldn't find any software package like that.
|
||||
' Would you like to view
|
||||
'
|
||||
a href=url(:package, :index) all packages
|
||||
a href=url_for(show: params[:show]) all packages
|
||||
'
|
||||
' instead?
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue