Strip hashtag prefixes
Users may actually type in a literal hashtag into the search, so this will ensure it still returns results.
This commit is contained in:
parent
97e668f4aa
commit
19f32f7b09
2 changed files with 22 additions and 0 deletions
|
|
@ -141,6 +141,8 @@ defmodule Pleroma.Hashtag do
|
||||||
|> String.trim()
|
|> String.trim()
|
||||||
|> String.split(~r/\s+/)
|
|> String.split(~r/\s+/)
|
||||||
|> Enum.filter(&(&1 != ""))
|
|> Enum.filter(&(&1 != ""))
|
||||||
|
|> Enum.map(&String.trim_leading(&1, "#"))
|
||||||
|
|> Enum.filter(&(&1 != ""))
|
||||||
|
|
||||||
if Enum.empty?(search_terms) do
|
if Enum.empty?(search_terms) do
|
||||||
[]
|
[]
|
||||||
|
|
|
||||||
|
|
@ -122,5 +122,25 @@ defmodule Pleroma.HashtagTest do
|
||||||
assert "racecar" in results
|
assert "racecar" in results
|
||||||
assert "nascar" in results
|
assert "nascar" in results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "handles hashtag symbols in search query" do
|
||||||
|
{:ok, _} = Hashtag.get_or_create_by_name("computer")
|
||||||
|
{:ok, _} = Hashtag.get_or_create_by_name("laptop")
|
||||||
|
{:ok, _} = Hashtag.get_or_create_by_name("phone")
|
||||||
|
|
||||||
|
results_with_hash = Hashtag.search("#computer #laptop")
|
||||||
|
results_without_hash = Hashtag.search("computer laptop")
|
||||||
|
|
||||||
|
assert results_with_hash == results_without_hash
|
||||||
|
|
||||||
|
results_mixed = Hashtag.search("#computer laptop #phone")
|
||||||
|
assert "computer" in results_mixed
|
||||||
|
assert "laptop" in results_mixed
|
||||||
|
assert "phone" in results_mixed
|
||||||
|
|
||||||
|
results_only_hash = Hashtag.search("#computer")
|
||||||
|
results_no_hash = Hashtag.search("computer")
|
||||||
|
assert results_only_hash == results_no_hash
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue