Add names from the guides to the search index

This commit is contained in:
freearhey 2025-03-08 18:57:34 +03:00
parent 7f861663d8
commit ef3b16d019
3 changed files with 23 additions and 7 deletions

View file

@ -1,5 +1,9 @@
export class Channel { export class Channel {
constructor(data) { constructor(data) {
const _streams = Array.isArray(data.streams) ? data.streams : []
const _guides = Array.isArray(data.guides) ? data.guides : []
const _blocklistRecords = Array.isArray(data.blocklistRecords) ? data.blocklistRecords : []
this.id = data.id this.id = data.id
this.name = data.name this.name = data.name
this.alt_names = this.alt_name = data.altNames this.alt_names = this.alt_name = data.altNames
@ -26,9 +30,9 @@ export class Channel {
this.replaced_by = data.replacedBy this.replaced_by = data.replacedBy
this.website = data.website this.website = data.website
this.logo = data.logo this.logo = data.logo
this.streams = Array.isArray(data.streams) ? data.streams.length : 0 this.streams = _streams.length
this.guides = Array.isArray(data.guides) ? data.guides.length : 0 this.guides = _guides.length
this.is_blocked = Array.isArray(data.blocklistRecords) && data.blocklistRecords.length > 0 this.is_blocked = _blocklistRecords.length > 0
this._hasUniqueName = data.hasUniqueName this._hasUniqueName = data.hasUniqueName
this._displayName = data.hasUniqueName ? data.name : `${data.name} (${data.country?.name})` this._displayName = data.hasUniqueName ? data.name : `${data.name} (${data.country?.name})`
@ -37,9 +41,10 @@ export class Channel {
this._languages = data.languages this._languages = data.languages
this._categories = data.categories this._categories = data.categories
this._broadcastArea = data.broadcastArea this._broadcastArea = data.broadcastArea
this._streams = data.streams || [] this._streams = _streams
this._guides = data.guides || [] this._guides = _guides
this._blocklistRecords = data.blocklistRecords || [] this._blocklistRecords = _blocklistRecords
this._guideNames = _guides.map(guide => guide.site_name).filter(Boolean)
} }
toObject() { toObject() {

View file

@ -63,7 +63,8 @@ export async function fetchChannels() {
'guides', 'guides',
'is_nsfw', 'is_nsfw',
'is_closed', 'is_closed',
'is_blocked' 'is_blocked',
'_guideNames'
] ]
}) })
} }

View file

@ -303,6 +303,16 @@ describe('search', () => {
id: 'ORF2Europe.at' id: 'ORF2Europe.at'
}) })
}) })
it('can find channel by display name from the guides', () => {
search('La Liga HD')
const results = get(filteredChannels)
expect(results.length).toBe(1)
expect(results[0]).toMatchObject({
id: 'LaLiganaZap.ao'
})
})
}) })
function mockFetch() { function mockFetch() {