Commit b2c5363d authored by Douwe Maan's avatar Douwe Maan

Rename to_fuzzy_arel to fuzzy_arel_match

parent aedd2cfa
...@@ -122,7 +122,7 @@ module Issuable ...@@ -122,7 +122,7 @@ module Issuable
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
def search(query) def search(query)
title = to_fuzzy_arel(:title, query) title = fuzzy_arel_match(:title, query)
where(title) where(title)
end end
...@@ -135,8 +135,8 @@ module Issuable ...@@ -135,8 +135,8 @@ module Issuable
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
def full_search(query) def full_search(query)
title = to_fuzzy_arel(:title, query) title = fuzzy_arel_match(:title, query)
description = to_fuzzy_arel(:description, query) description = fuzzy_arel_match(:description, query)
where(title&.or(description)) where(title&.or(description))
end end
......
...@@ -19,7 +19,7 @@ module Gitlab ...@@ -19,7 +19,7 @@ module Gitlab
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end end
def to_fuzzy_arel(column, query) def fuzzy_arel_match(column, query)
words = select_fuzzy_words(query) words = select_fuzzy_words(query)
matches = words.map { |word| arel_table[column].matches(to_pattern(word)) } matches = words.map { |word| arel_table[column].matches(to_pattern(word)) }
......
...@@ -137,14 +137,14 @@ describe Gitlab::SQL::Pattern do ...@@ -137,14 +137,14 @@ describe Gitlab::SQL::Pattern do
end end
end end
describe '.to_fuzzy_arel' do describe '.fuzzy_arel_match' do
subject(:to_fuzzy_arel) { Issue.to_fuzzy_arel(:title, query) } subject(:fuzzy_arel_match) { Issue.fuzzy_arel_match(:title, query) }
context 'with a word equal to 3 chars' do context 'with a word equal to 3 chars' do
let(:query) { 'foo' } let(:query) { 'foo' }
it 'returns a single ILIKE condition' do it 'returns a single ILIKE condition' do
expect(to_fuzzy_arel.to_sql).to match(/title.*I?LIKE '\%foo\%'/) expect(fuzzy_arel_match.to_sql).to match(/title.*I?LIKE '\%foo\%'/)
end end
end end
...@@ -152,7 +152,7 @@ describe Gitlab::SQL::Pattern do ...@@ -152,7 +152,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'fo' } let(:query) { 'fo' }
it 'returns nil' do it 'returns nil' do
expect(to_fuzzy_arel).to be_nil expect(fuzzy_arel_match).to be_nil
end end
end end
...@@ -160,7 +160,7 @@ describe Gitlab::SQL::Pattern do ...@@ -160,7 +160,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'foo baz' } let(:query) { 'foo baz' }
it 'returns a joining LIKE condition using a AND' do it 'returns a joining LIKE condition using a AND' do
expect(to_fuzzy_arel.to_sql).to match(/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%'/) expect(fuzzy_arel_match.to_sql).to match(/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%'/)
end end
end end
...@@ -168,7 +168,7 @@ describe Gitlab::SQL::Pattern do ...@@ -168,7 +168,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'foo "really bar" baz' } let(:query) { 'foo "really bar" baz' }
it 'returns a joining LIKE condition using a AND' do it 'returns a joining LIKE condition using a AND' do
expect(to_fuzzy_arel.to_sql).to match(/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%' AND .*title.*I?LIKE '\%really bar\%'/) expect(fuzzy_arel_match.to_sql).to match(/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%' AND .*title.*I?LIKE '\%really bar\%'/)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment