Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Added feature to search over rpms also #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def show
if params[:query].blank?
redirect_to controller: 'home', action: 'index'
else
@srpms = Srpm.query(params[:query]).by_branch_name(params[:branch]).page(params[:page]).includes(:branch)
@srpms = Srpm.includes(:branch).b(params[:branch]).q(params[:query]).page(params[:page]).reorder("srpms.name").distinct

# @srpms = Srpm.none
# @srpms = Srpm.search(
Expand Down
4 changes: 4 additions & 0 deletions app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Package < ApplicationRecord

after_destroy :remove_filename_from_cache

pg_search_scope :query,
against: %i[name summary description filename sourcepackage],
using: { tsearch: { prefix: true } }

multisearchable against: [:name, :summary, :description, :filename,
:sourcepackage]

Expand Down
4 changes: 4 additions & 0 deletions app/models/srpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class Srpm < ApplicationRecord

scope :by_branch_name, ->(name) { joins(:branch).where(branches: { name: name }) }

scope :q, ->(text) { joins(:packages).merge(Package.query(text)).or(self.query(text)) }

singleton_class.send(:alias_method, :b, :by_branch_name)

validates :groupname, presence: true

validates :md5, presence: true
Expand Down
1 change: 1 addition & 0 deletions config/initializers/require.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "#{Rails.root}/lib/extensions"
11 changes: 11 additions & 0 deletions lib/extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "active_record"
require "active_record/relation"
require "active_record/relation/query_methods.rb"

module ActiveRecord::QueryMethods
def structurally_incompatible_values_for_or(other)
(ActiveRecord::Relation::SINGLE_VALUE_METHODS - [:distinct]).reject { |m| send("#{m}_value") == other.send("#{m}_value") } +
(ActiveRecord::Relation::MULTI_VALUE_METHODS - [:eager_load, :left_outer_joins, :joins, :references, :order, :extending]).reject { |m| send("#{m}_values") == other.send("#{m}_values") } +
(ActiveRecord::Relation::CLAUSE_METHODS - [:having, :where]).reject { |m| send("#{m}_clause") == other.send("#{m}_clause") }
end
end