Make sure escaping works consistently everywhere (including with ?)
Remove duplication
This commit is contained in:
@@ -60,7 +60,7 @@ defmodule MusicLibrary.Records do
|
|||||||
|
|
||||||
defp fts_escape(term) do
|
defp fts_escape(term) do
|
||||||
# For FTS5, if the term contains special characters, we need to wrap it in double quotes
|
# For FTS5, if the term contains special characters, we need to wrap it in double quotes
|
||||||
if String.contains?(term, ["'", " ", "\"", "(", ")", "^", "-", ":"]) do
|
if String.contains?(term, ["'", " ", "\"", "(", ")", "^", "-", ":", "?"]) do
|
||||||
# Escape internal double quotes and wrap in double quotes
|
# Escape internal double quotes and wrap in double quotes
|
||||||
escaped = String.replace(term, "\"", "\"\"")
|
escaped = String.replace(term, "\"", "\"\"")
|
||||||
"\"#{escaped}\"*"
|
"\"#{escaped}\"*"
|
||||||
@@ -70,20 +70,9 @@ defmodule MusicLibrary.Records do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defp fts_query_escape(query) do
|
defp fts_query_escape(query) do
|
||||||
# For general queries, split terms and combine with AND
|
query
|
||||||
# First undo SearchParser's quote doubling
|
|
||||||
clean_query = String.replace(query, "''", "'")
|
|
||||||
|
|
||||||
clean_query
|
|
||||||
|> String.split(~r/\s+/, trim: true)
|
|> String.split(~r/\s+/, trim: true)
|
||||||
|> Enum.map_join(" AND ", fn term ->
|
|> Enum.map_join(" AND ", &fts_escape/1)
|
||||||
if String.contains?(term, ["'", " ", "\"", "(", ")", "^", "-", ":"]) do
|
|
||||||
escaped = String.replace(term, "\"", "\"\"")
|
|
||||||
"\"#{escaped}\""
|
|
||||||
else
|
|
||||||
term
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_search(initial_search, query, order \\ :alphabetical) do
|
defp build_search(initial_search, query, order \\ :alphabetical) do
|
||||||
|
|||||||
Reference in New Issue
Block a user