Skip to content

Commit

Permalink
Fix for Multiword Tags (#894)
Browse files Browse the repository at this point in the history
* add the ability to search for multiword tag by using #tag tag#

* remove debug statement

* fix whitespace issue defined by rubocop

* add a test for multiword comment
  • Loading branch information
johnbumgardner authored Mar 21, 2021
1 parent 4e72e0c commit f2a1656
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/controllers/entities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,15 @@ def parse_query_and_tags(search_string)

query = []
tags = []
search_string.strip.split(/\s+/).each do |token|
if token.starts_with?("#")
tags << token[1..-1]
else
query << token
if search_string.start_with?("#") && search_string.end_with?("#")
tags << search_string[1..-2]
else
search_string.strip.split(/\s+/).each do |token|
if token.starts_with?("#")
tags << token[1..-1]
else
query << token
end
end
end
[query.join(" "), tags.join(", ")]
Expand Down
5 changes: 5 additions & 0 deletions spec/controllers/entities_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
expect(controller.send(:parse_query_and_tags, str)).to eq(['', 'test'])
end

it 'should parse #multiword tags' do
str = "#multiword tag#"
expect(controller.send(:parse_query_and_tags, str)).to eq(['', 'multiword tag'])
end

it "should parse no tags" do
str = "test query"
expect(controller.send(:parse_query_and_tags, str)).to eq(['test query', ''])
Expand Down

0 comments on commit f2a1656

Please sign in to comment.