mirror of
https://github.com/home-assistant/core.git
synced 2026-10-06 22:38:02 -04:00
Limit and rank Radio Browser search results (#183387)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
e48acea9d3
commit
500b461fe5
@@ -35,6 +35,8 @@ CODEC_TO_MIMETYPE = {
|
||||
"OGG": "application/ogg",
|
||||
}
|
||||
|
||||
MAX_SEARCH_RESULTS = 100
|
||||
|
||||
|
||||
async def async_get_media_source(hass: HomeAssistant) -> RadioMediaSource:
|
||||
"""Set up Radio Browser media source."""
|
||||
@@ -144,7 +146,14 @@ class RadioMediaSource(MediaSource):
|
||||
return SearchMedia(
|
||||
result=self._async_build_stations(
|
||||
radios,
|
||||
await radios.search(name=query.search_query, hide_broken=True),
|
||||
# Order by popularity so the limit keeps the best matches
|
||||
await radios.search(
|
||||
name=query.search_query,
|
||||
hide_broken=True,
|
||||
limit=MAX_SEARCH_RESULTS,
|
||||
order=Order.CLICK_COUNT,
|
||||
reverse=True,
|
||||
),
|
||||
)
|
||||
)
|
||||
except (DNSError, RadioBrowserError) as e:
|
||||
|
||||
@@ -148,7 +148,13 @@ async def test_search_media(
|
||||
SearchMediaQuery(search_query="my search"),
|
||||
)
|
||||
|
||||
source.radios.search.assert_awaited_with(name="my search", hide_broken=True)
|
||||
source.radios.search.assert_awaited_with(
|
||||
name="my search",
|
||||
hide_broken=True,
|
||||
limit=100,
|
||||
order=Order.CLICK_COUNT,
|
||||
reverse=True,
|
||||
)
|
||||
assert len(result.result) == 5
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user