From 8b22c59bece91728892190617be1612fed8bf59d Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 18 Nov 2015 20:04:19 +0100 Subject: [PATCH 1/2] removes trigram search algorithm --- app/models/proposal.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 1f3518144..ffccc8bf7 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -51,8 +51,7 @@ class Proposal < ActiveRecord::Base tags: :name }, using: { - tsearch: { dictionary: "spanish", tsvector_column: 'tsv' }, - trigram: { threshold: 0.1 }, + tsearch: { dictionary: "spanish", tsvector_column: 'tsv' } }, ranked_by: '(:tsearch + proposals.cached_votes_up)', order_within_rank: "proposals.created_at DESC" From c212aa3afdd0fd8bb47297f6a7f8c2ec23c9baa1 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 18 Nov 2015 21:04:16 +0100 Subject: [PATCH 2/2] fixes specs --- app/models/proposal.rb | 1 + spec/models/proposal_spec.rb | 23 ++++------------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/app/models/proposal.rb b/app/models/proposal.rb index ffccc8bf7..ca0cc12e2 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -53,6 +53,7 @@ class Proposal < ActiveRecord::Base using: { tsearch: { dictionary: "spanish", tsvector_column: 'tsv' } }, + ignoring: :accents, ranked_by: '(:tsearch + proposals.cached_votes_up)', order_within_rank: "proposals.created_at DESC" } diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 917d3db32..16183eb7a 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -388,15 +388,15 @@ describe Proposal do context "stemming" do it "searches word stems" do - proposal = create(:proposal, summary: 'limpiar') + proposal = create(:proposal, summary: 'biblioteca') - results = Proposal.search('limpiará') + results = Proposal.search('bibliotecas') expect(results).to eq([proposal]) - results = Proposal.search('limpiémos') + results = Proposal.search('bibliotec') expect(results).to eq([proposal]) - results = Proposal.search('limpió') + results = Proposal.search('biblioteco') expect(results).to eq([proposal]) end @@ -432,21 +432,6 @@ describe Proposal do end - context "typos" do - - it "searches with typos" do - proposal = create(:proposal, summary: 'difusión') - - results = Proposal.search('difuon') - expect(results).to eq([proposal]) - - proposal2 = create(:proposal, summary: 'desarrollo') - results = Proposal.search('desarolo') - expect(results).to eq([proposal2]) - end - - end - context "order" do it "orders by weight" do