Skip to content

Commit

Permalink
implement pg search
Browse files Browse the repository at this point in the history
  • Loading branch information
Vakmeth committed Aug 30, 2024
1 parent 2680ab6 commit 35a8868
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 20 deletions.
10 changes: 0 additions & 10 deletions app/indices/group_index.rb

This file was deleted.

10 changes: 0 additions & 10 deletions app/indices/person_index.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/models/pbs/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ module Pbs::Group
self.used_attributes += [:website, :bank_account, :pbs_shortname]
self.superior_attributes = [:pbs_shortname]

Group::SEARCHABLE_ATTRS << :pbs_shortname << :description << :website << :bank_account
include PgSearchable

validates :description, length: {allow_nil: true, maximum: 2**16 - 1}
validates :hostname, uniqueness: true, allow_blank: true
has_many :crises
Expand Down
3 changes: 3 additions & 0 deletions app/models/pbs/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ module Pbs::Person
:prefers_digital_correspondence << :kantonalverband_id
Person::ADDRESS_ATTRS << "prefers_digital_correspondence"

Person::SEARCHABLE_ATTRS << :title << :pbs_number
include PgSearchable

alias_method_chain :full_name, :title

i18n_boolean_setter :prefers_digital_correspondence
Expand Down
41 changes: 41 additions & 0 deletions spec/domain/search_strategy/group_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2024, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.
#
require "spec_helper"

describe SearchStrategies::GroupSearch do
before do
groups(:bund).update!(pbs_shortname: "shortname", description: "description", website: "lemurenshop",
bank_account: "account")
end

describe "#search_fulltext" do
let(:user) { people(:root) }

it "finds accessible groups by shortname" do
result = search_class(groups(:bund).pbs_shortname).search_fulltext
expect(result).to include(groups(:bund))
end

it "finds accessible groups by description" do
result = search_class(groups(:bund).description).search_fulltext
expect(result).to include(groups(:bund))
end

it "finds accessible groups by website" do
result = search_class(groups(:bund).website).search_fulltext
expect(result).to include(groups(:bund))
end

it "finds accessible groups by bank account" do
result = search_class(groups(:bund).bank_account).search_fulltext
expect(result).to include(groups(:bund))
end
end

def search_class(term = nil, page = nil)
described_class.new(user, term, page)
end
end
30 changes: 30 additions & 0 deletions spec/domain/search_strategy/person_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024, Pfadibewegung Schweiz. This file is part of
# hitobito_pbs and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito_pbs.

require "spec_helper"

describe SearchStrategies::PersonSearch do
before do
people(:al_schekka).update!(pbs_number: 4566, title: "Sky")
end

describe "#search_fulltext" do
let(:user) { people(:bulei) }

it "finds accessible person by title" do
result = search_class(people(:al_schekka).title).search_fulltext
expect(result).to include(people(:al_schekka))
end

it "finds accessible person by pbs number" do
result = search_class(people(:al_schekka).pbs_number.to_s).search_fulltext
expect(result).to include(people(:al_schekka))
end
end

def search_class(term = nil, page = nil)
described_class.new(user, term, page)
end
end

0 comments on commit 35a8868

Please sign in to comment.