Merge pull request #2580 from basecamp/fix-hyphenated-search
Fix hyphenated search
This commit is contained in:
@@ -5,7 +5,7 @@ module Search::Stemmer
|
||||
|
||||
def stem(value)
|
||||
if value.present?
|
||||
value.gsub(/[^\w\s]/, "").split(/\s+/).map { |word| STEMMER.stem(word.downcase) }.join(" ")
|
||||
value.gsub(/[^\w\s]/, " ").split(/\s+/).map { |word| STEMMER.stem(word.downcase) }.join(" ")
|
||||
else
|
||||
value
|
||||
end
|
||||
|
||||
@@ -12,4 +12,16 @@ class Search::StemmerTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal "test run jump walk", result
|
||||
end
|
||||
|
||||
test "stem hyphenated words" do
|
||||
result = Search::Stemmer.stem("BC3-IOS-1D8B")
|
||||
|
||||
assert_equal "bc3 io 1d8b", result
|
||||
end
|
||||
|
||||
test "stem words separated by repeated punctuation" do
|
||||
result = Search::Stemmer.stem("foo---bar")
|
||||
|
||||
assert_equal "foo bar", result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,4 +35,11 @@ class SearchTest < ActiveSupport::TestCase
|
||||
results = Search::Record.for(user_without_access.account_id).search("anything", user: user_without_access)
|
||||
assert_empty results
|
||||
end
|
||||
|
||||
test "search for hyphenated strings" do
|
||||
card = @board.cards.create!(title: "BC3-IOS-1D8B", creator: @user, status: "published")
|
||||
|
||||
results = Search::Record.for(@user.account_id).search("BC3-IOS-1D8B", user: @user)
|
||||
assert results.find { |it| it.card_id == card.id }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user