@@ -3,6 +3,7 @@ import { msg } from '@lit/localize';
33import type { MediaType } from '@internetarchive/field-parsers' ;
44import {
55 AggregationSortType ,
6+ HitType ,
67 Review ,
78 SearchResult ,
89 SortDirection ,
@@ -36,6 +37,19 @@ export const TILE_OVERLAY_ICONS: Record<TileOverlayType, TemplateResult> = {
3637 'content-warning' : restrictedIcon ,
3738} ;
3839
40+ /**
41+ * What type of request produced a given set of hits:
42+ * - `search_query`: Hits produced by an explicit user query and/or applied filters on any page
43+ * - `collection_members`: Hits produced for a collection page without any query or filters
44+ * - `profile_tab`: Hits produced for a tab of the profile page without any query or filters
45+ * - `unknown`: Hits produced via any other means
46+ */
47+ export type HitRequestSource =
48+ | 'search_query'
49+ | 'collection_members'
50+ | 'profile_tab'
51+ | 'unknown' ;
52+
3953/**
4054 * Class for converting & storing raw search results in the correct format for UI tiles.
4155 */
@@ -76,6 +90,10 @@ export class TileModel {
7690
7791 favCount : number ;
7892
93+ hitRequestSource : HitRequestSource ;
94+
95+ hitType ?: HitType ;
96+
7997 href ?: string ;
8098
8199 identifier ?: string ;
@@ -110,7 +128,10 @@ export class TileModel {
110128
111129 contentWarning : boolean ;
112130
113- constructor ( result : SearchResult ) {
131+ constructor (
132+ result : SearchResult ,
133+ hitRequestSource : HitRequestSource = 'unknown' ,
134+ ) {
114135 const flags = this . getFlags ( result ) ;
115136
116137 this . averageRating = result . avg_rating ?. value ;
@@ -128,6 +149,8 @@ export class TileModel {
128149 this . dateReviewed = result . reviewdate ?. value ;
129150 this . description = result . description ?. values . join ( '\n' ) ;
130151 this . favCount = result . num_favorites ?. value ?? 0 ;
152+ this . hitRequestSource = hitRequestSource ;
153+ this . hitType = result . rawMetadata ?. hit_type ;
131154 this . href = collapseRepeatedQuotes (
132155 result . review ?. __href__ ?? result . __href__ ?. value ,
133156 ) ;
@@ -170,6 +193,8 @@ export class TileModel {
170193 cloned . dateReviewed = this . dateReviewed ;
171194 cloned . description = this . description ;
172195 cloned . favCount = this . favCount ;
196+ cloned . hitRequestSource = this . hitRequestSource ;
197+ cloned . hitType = this . hitType ;
173198 cloned . href = this . href ;
174199 cloned . identifier = this . identifier ;
175200 cloned . issue = this . issue ;
@@ -189,6 +214,15 @@ export class TileModel {
189214 return cloned ;
190215 }
191216
217+ /**
218+ * Whether this model represents the result of a TV search query.
219+ */
220+ get isTvSearchResult ( ) : boolean {
221+ return (
222+ this . hitType === 'tv_clip' && this . hitRequestSource === 'search_query'
223+ ) ;
224+ }
225+
192226 /**
193227 * Determines the appropriate tile flags for the given search result
194228 * (login required and/or content warning)
0 commit comments