diff --git a/app/models/package.rb b/app/models/package.rb index bdb93fb..16a7e72 100644 --- a/app/models/package.rb +++ b/app/models/package.rb @@ -4,7 +4,12 @@ class Package < ActiveRecord::Base include PgSearch # TODO: Make search weighted on users' rating pg_search_scope :general_search, - :against => [:name, :description, :long_description], + # :against => [:name, :description, :long_description], + :against => [ + [:name, 'A'], + [:description, 'B'], + [:long_description, 'C'] + ], :using => { :tsearch => {:dictionary => "english"} } @@ -14,9 +19,9 @@ class Package < ActiveRecord::Base # screenshot files from disk. has_many :screenshots, :inverse_of=>:package, :dependent => :destroy - default_scope { - order('name ASC') - } + # default_scope { + # order('name ASC') + # } # Return a query of all packages that have screenshots def self.with_screenshots diff --git a/db/migrate/20160812085722_make_fulltext_search_index_weighted.rb b/db/migrate/20160812085722_make_fulltext_search_index_weighted.rb new file mode 100644 index 0000000..0c5fc2f --- /dev/null +++ b/db/migrate/20160812085722_make_fulltext_search_index_weighted.rb @@ -0,0 +1,14 @@ +# PostregreSQL text searches are now using weights. So the index has to reflect that. +class MakeFulltextSearchIndexWeighted < ActiveRecord::Migration + def change + execute "drop index packages_fts" + + execute "create index packages_fts on packages using gin(( + setweight( to_tsvector('english', coalesce(\"packages\".\"name\"::text, '')), 'A' ) + || + setweight( to_tsvector('english', coalesce(\"packages\".\"description\"::text, '')), 'B' ) + || + setweight( to_tsvector('english', coalesce(\"packages\".\"long_description\"::text, '')), 'C' ) + ))" + end +end