refactor: MobileChannel callsign search pattern via function dispatch
build_search_pattern/1 picks between SQL-wildcard (when the query contains `*`) and prefix-match (SSID-friendly) forms via two function heads instead of an inline `if`. The transform is now isolated and obviously boolean-dispatched at the call site.
This commit is contained in:
parent
5a8f30916e
commit
0cbe93f8db
1 changed files with 11 additions and 10 deletions
|
|
@ -353,6 +353,16 @@ defmodule AprsmeWeb.MobileChannel do
|
|||
|
||||
defp ensure_float(_value), do: nil
|
||||
|
||||
# Dispatch on wildcard presence. `*` is the user-facing wildcard; SQL LIKE
|
||||
# uses `%`. Without a wildcard, match callsigns that start with the query
|
||||
# so SSID searches like "K5ABC" match "K5ABC-9".
|
||||
defp build_search_pattern(query) do
|
||||
build_search_pattern_for(String.contains?(query, "*"), query)
|
||||
end
|
||||
|
||||
defp build_search_pattern_for(true, query), do: String.replace(query, "*", "%")
|
||||
defp build_search_pattern_for(false, query), do: "#{query}%"
|
||||
|
||||
defp ensure_integer(value, _default) when is_integer(value), do: value
|
||||
|
||||
defp ensure_integer(value, default) when is_binary(value) do
|
||||
|
|
@ -471,16 +481,7 @@ defmodule AprsmeWeb.MobileChannel do
|
|||
|
||||
Logger.info("Searching for callsign: #{query}")
|
||||
|
||||
# Build search pattern - support wildcard with *
|
||||
pattern =
|
||||
if String.contains?(query, "*") do
|
||||
# Convert * to SQL % wildcard
|
||||
String.replace(query, "*", "%")
|
||||
else
|
||||
# If no wildcard, search for exact match or with SSID
|
||||
"#{query}%"
|
||||
end
|
||||
|
||||
pattern = build_search_pattern(query)
|
||||
Logger.info("Search pattern: #{pattern}")
|
||||
|
||||
# Query for matching callsigns - optimized version
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue