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
#
# Returns an ActiveRecord::Relation.
def search(query)
title = to_fuzzy_arel(:title, query)
title = fuzzy_arel_match(:title, query)
where(title)
end
......@@ -135,8 +135,8 @@ module Issuable
#
# Returns an ActiveRecord::Relation.
def full_search(query)
title = to_fuzzy_arel(:title, query)
description = to_fuzzy_arel(:description, query)
title = fuzzy_arel_match(:title, query)
description = fuzzy_arel_match(:description, query)
where(title&.or(description))
end
......
......@@ -19,7 +19,7 @@ module Gitlab
query.length >= MIN_CHARS_FOR_PARTIAL_MATCHING
end
def to_fuzzy_arel(column, query)
def fuzzy_arel_match(column, query)
words = select_fuzzy_words(query)
matches = words.map { |word| arel_table[column].matches(to_pattern(word)) }
......
......@@ -137,14 +137,14 @@ describe Gitlab::SQL::Pattern do
end
end
describe '.to_fuzzy_arel' do
subject(:to_fuzzy_arel) { Issue.to_fuzzy_arel(:title, query) }
describe '.fuzzy_arel_match' do
subject(:fuzzy_arel_match) { Issue.fuzzy_arel_match(:title, query) }
context 'with a word equal to 3 chars' do
let(:query) { 'foo' }
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
......@@ -152,7 +152,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'fo' }
it 'returns nil' do
expect(to_fuzzy_arel).to be_nil
expect(fuzzy_arel_match).to be_nil
end
end
......@@ -160,7 +160,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'foo baz' }
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
......@@ -168,7 +168,7 @@ describe Gitlab::SQL::Pattern do
let(:query) { 'foo "really bar" baz' }
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
......
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