Skip to content

Commit e1aef58

Browse files
committed
Fix track search with #hashtags
1 parent 6133d41 commit e1aef58

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

cli/lib/data.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,23 @@ export async function deleteTrack(id) {
152152

153153
/** @param {string} query */
154154
export async function searchChannels(query, options = {}) {
155+
const tag = query.startsWith('#') ? query.slice(1) : null
156+
// Channels don't have tags, so tag queries search fts with the tag name stripped of #
155157
const {data, error} = await sdk.supabase
156158
.from('channels')
157159
.select()
158-
.textSearch('fts', `'${query}':*`)
160+
.textSearch('fts', `'${tag || query}':*`)
159161
if (error) throw new Error(error.message)
160162
return takeMaybe(options.limit)(data.map((ch) => channelSchema.parse(ch)))
161163
}
162164

163165
export async function searchTracks(query, options = {}) {
164-
const {data, error} = await sdk.supabase
165-
.from('channel_tracks')
166-
.select()
167-
.textSearch('fts', `'${query}':*`)
166+
const tag = query.startsWith('#') ? query.slice(1) : null
167+
let request = sdk.supabase.from('channel_tracks').select()
168+
request = tag
169+
? request.contains('tags', [tag])
170+
: request.textSearch('fts', `'${query}':*`)
171+
const {data, error} = await request
168172
if (error) throw new Error(error.message)
169173
return takeMaybe(options.limit)(data.map((t) => trackSchema.parse(t)))
170174
}

0 commit comments

Comments
 (0)