Skip to content

Enable partial word searches in pg_search #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
7 changes: 5 additions & 2 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ class Post < ActiveRecord::Base
include PgSearch

pg_search_scope :search_by_query,
:against => [:title, :description, :tags],
:ignoring => :accents
against: [:title, :description, :tags],
ignoring: :accents,
using: {
tsearch: { prefix: true }
}

attr_reader :member_id

Expand Down
10 changes: 8 additions & 2 deletions spec/controllers/offers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@
end

describe "GET #index (search)" do
it "populates an array of offers" do
login(another_member.user)
before { login(another_member.user) }

it "populates an array of offers" do
get "index", q: offer.title.split(/\s/).first

expect(assigns(:offers).size).to eq 1
expect(assigns(:offers)[0]).to eq offer
expect(assigns(:offers).to_a).to eq([offer])
end

it "allows to search by partial word" do
get :index, q: offer.title.split(/\s/).first[0..-2]

expect(assigns(:offers)).to include offer
end
end

describe 'GET #show' do
Expand Down