@internetarchive/collection-browser 1.14.16-alpha.5 → 1.14.16-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/data-source/collection-browser-data-source.d.ts +1 -1
- package/dist/src/data-source/collection-browser-data-source.js +14 -8
- package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
- package/package.json +1 -1
- package/src/data-source/collection-browser-data-source.ts +12 -5
|
@@ -287,7 +287,7 @@ export declare class CollectionBrowserDataSource implements CollectionBrowserDat
|
|
|
287
287
|
* The query key is a string that uniquely identifies the current search.
|
|
288
288
|
* It consists of:
|
|
289
289
|
* - The current base query
|
|
290
|
-
* - The current collection
|
|
290
|
+
* - The current collection/profile target
|
|
291
291
|
* - The current search type
|
|
292
292
|
* - Any currently-applied facets
|
|
293
293
|
* - Any currently-applied date range
|
|
@@ -200,16 +200,19 @@ export class CollectionBrowserDataSource {
|
|
|
200
200
|
const trimmedQuery = (_a = this.host.baseQuery) === null || _a === void 0 ? void 0 : _a.trim();
|
|
201
201
|
const hasNonEmptyQuery = !!trimmedQuery;
|
|
202
202
|
const isCollectionSearch = !!this.host.withinCollection;
|
|
203
|
+
const isProfileSearch = !!this.host.withinProfile;
|
|
203
204
|
const isMetadataSearch = this.host.searchType === SearchType.METADATA;
|
|
204
|
-
// Metadata searches within a collection are allowed to have no query.
|
|
205
|
+
// Metadata searches within a collection/profile are allowed to have no query.
|
|
205
206
|
// Otherwise, a non-empty query must be set.
|
|
206
|
-
return hasNonEmptyQuery ||
|
|
207
|
+
return (hasNonEmptyQuery ||
|
|
208
|
+
(isCollectionSearch && isMetadataSearch) ||
|
|
209
|
+
(isProfileSearch && isMetadataSearch));
|
|
207
210
|
}
|
|
208
211
|
/**
|
|
209
212
|
* The query key is a string that uniquely identifies the current search.
|
|
210
213
|
* It consists of:
|
|
211
214
|
* - The current base query
|
|
212
|
-
* - The current collection
|
|
215
|
+
* - The current collection/profile target
|
|
213
216
|
* - The current search type
|
|
214
217
|
* - Any currently-applied facets
|
|
215
218
|
* - Any currently-applied date range
|
|
@@ -220,17 +223,20 @@ export class CollectionBrowserDataSource {
|
|
|
220
223
|
* no longer relevant.
|
|
221
224
|
*/
|
|
222
225
|
get pageFetchQueryKey() {
|
|
223
|
-
var _a, _b, _c, _d;
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
|
|
226
|
+
var _a, _b, _c, _d, _e;
|
|
227
|
+
const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : this.host.withinProfile;
|
|
228
|
+
const sortField = (_c = (_b = this.host.sortParam) === null || _b === void 0 ? void 0 : _b.field) !== null && _c !== void 0 ? _c : 'none';
|
|
229
|
+
const sortDirection = (_e = (_d = this.host.sortParam) === null || _d === void 0 ? void 0 : _d.direction) !== null && _e !== void 0 ? _e : 'none';
|
|
230
|
+
return `${this.fullQuery}-${pageTarget}-${this.host.searchType}-${sortField}-${sortDirection}`;
|
|
227
231
|
}
|
|
228
232
|
/**
|
|
229
233
|
* Similar to `pageFetchQueryKey` above, but excludes sort fields since they
|
|
230
234
|
* are not relevant in determining aggregation queries.
|
|
231
235
|
*/
|
|
232
236
|
get facetFetchQueryKey() {
|
|
233
|
-
|
|
237
|
+
var _a;
|
|
238
|
+
const pageTarget = (_a = this.host.withinCollection) !== null && _a !== void 0 ? _a : this.host.withinProfile;
|
|
239
|
+
return `${this.fullQuery}-${pageTarget}-${this.host.searchType}`;
|
|
234
240
|
}
|
|
235
241
|
/**
|
|
236
242
|
* Constructs a search service FilterMap object from the combination of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection-browser-data-source.js","sourceRoot":"","sources":["../../../src/data-source/collection-browser-data-source.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,gBAAgB,EAEhB,gBAAgB,EAIhB,UAAU,GACX,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,2BAA2B,GAK5B,MAAM,WAAW,CAAC;AAMnB,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,MAAM,CACpD,CAAC,GAA2B,EAAE,MAAc,EAAE,EAAE;YAC9C,GAAG,CAAE,MAAM,CAAC,GAAc,CAAC,WAAW,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC;YAC7D,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport {\n AccountExtraInfo,\n Aggregation,\n Bucket,\n CollectionExtraInfo,\n FilterConstraint,\n FilterMap,\n FilterMapBuilder,\n PageElementMap,\n SearchParams,\n SearchResult,\n SearchType,\n} from '@internetarchive/search-service';\nimport type { MediaType } from '@internetarchive/field-parsers';\nimport {\n prefixFilterAggregationKeys,\n type FacetBucket,\n type PrefixFilterType,\n type TileModel,\n PrefixFilterCounts,\n} from '../models';\nimport type {\n CollectionBrowserSearchInterface,\n CollectionTitles,\n PageSpecifierParams,\n} from './models';\nimport { sha1 } from '../utils/sha1';\n\ntype RequestKind = 'full' | 'hits' | 'aggregations';\n\nexport interface CollectionBrowserDataSourceInterface\n extends ReactiveController {\n /**\n * How many tile models are present in this data source\n */\n readonly size: number;\n\n /**\n * Whether the host has a valid set of properties for performing a search.\n * For instance, on the search page this requires a valid search service and a\n * non-empty query, while collection pages allow searching with an empty query\n * for MDS but not FTS.\n */\n readonly canPerformSearch: boolean;\n\n /**\n * A string key compactly representing the current full search state, which can\n * be used to determine, e.g., when a new search is required or whether an arriving\n * response is outdated.\n */\n readonly pageFetchQueryKey: string;\n\n /**\n * Similar to `pageFetchQueryKey`, but excluding properties that do not affect\n * the validity of a set of facets (e.g., sort).\n */\n readonly facetFetchQueryKey: string;\n\n /**\n * An object representing any collection- or profile-specific properties to be passed along\n * to the search service, specifying the exact page/tab to fetch results for.\n */\n readonly pageSpecifierParams: PageSpecifierParams | null;\n\n /**\n * A FilterMap object representing all filters applied to the current search,\n * including any facets, letter filters, and date ranges.\n */\n readonly filterMap: FilterMap;\n\n /**\n * The full set of aggregations retrieved for the current search.\n */\n readonly aggregations?: Record<string, Aggregation>;\n\n /**\n * The `year_histogram` aggregation retrieved for the current search.\n */\n readonly yearHistogramAggregation?: Aggregation;\n\n /**\n * A map from collection identifiers that appear on hits or aggregations for the\n * current search, to their human-readable collection titles.\n */\n readonly collectionTitles: CollectionTitles;\n\n /**\n * The \"extra info\" package provided by the PPS for collection pages, including details\n * used to populate the target collection header & About tab content.\n */\n readonly collectionExtraInfo?: CollectionExtraInfo;\n\n /**\n * The \"extra info\" package provided by the PPS for profile pages, including details\n * used to populate the profile header.\n */\n readonly accountExtraInfo?: AccountExtraInfo;\n\n /**\n * The set of requested page elements for profile pages, if applicable. These represent\n * any content specific to the current profile tab.\n */\n readonly pageElements?: PageElementMap;\n\n /**\n * An array of the current target collection's parent collections. Should include *all*\n * ancestors in the collection hierarchy, not just the immediate parent.\n */\n readonly parentCollections?: string[];\n\n /**\n * An object storing result counts for the current search bucketed by letter prefix.\n * Keys are the result field on which the prefixes are considered (e.g., title/creator)\n * and values are a Record mapping letters to their counts.\n */\n readonly prefixFilterCountMap: Partial<\n Record<PrefixFilterType, PrefixFilterCounts>\n >;\n\n /**\n * An array of all the tile models whose management checkboxes are checked\n */\n readonly checkedTileModels: TileModel[];\n\n /**\n * An array of all the tile models whose management checkboxes are unchecked\n */\n readonly uncheckedTileModels: TileModel[];\n\n /**\n * Adds the given page of tile models to the data source.\n * If the given page number already exists, that page will be overwritten.\n * @param pageNum Which page number to add (indexed starting from 1)\n * @param pageTiles The array of tile models for the new page\n */\n addPage(pageNum: number, pageTiles: TileModel[]): void;\n\n /**\n * Returns the given page of tile models from the data source.\n * @param pageNum Which page number to get (indexed starting from 1)\n */\n getPage(pageNum: number): TileModel[];\n\n /**\n * Returns the full set of paged tile models stored in this data source.\n */\n getAllPages(): Record<string, TileModel[]>;\n\n /**\n * Whether the data source contains any tiles for the given page number.\n * @param pageNum Which page number to query (indexed starting from 1)\n */\n hasPage(pageNum: number): boolean;\n\n /**\n * Returns the single tile model appearing at the given index in the\n * data source, with respect to the current page size. Returns `undefined` if\n * the corresponding page is not present on the data source or if it does not\n * contain a tile model at the corresponding index.\n * @param index The 0-based index (within the full data source) of the tile to get\n */\n getTileModelAt(index: number): TileModel | undefined;\n\n /**\n * Requests that the data source fire a backend request for the given page of results.\n * @param pageNum Which page number to fetch results for\n * @param numInitialPages How many pages should be batched together on an initial fetch\n */\n fetchPage(pageNum: number, numInitialPages?: number): Promise<void>;\n\n /**\n * Requests that the data source update its prefix bucket result counts for the given\n * type of prefix filter.\n * @param filterType Which prefixable field to update the buckets for (e.g., title/creator)\n */\n updatePrefixFilterCounts(filterType: PrefixFilterType): Promise<void>;\n\n /**\n * Changes the page size used by the data source, discarding any previously-fetched pages.\n *\n * **Note: this operation will reset any data stored in the data source!**\n * @param pageSize\n */\n setPageSize(pageSize: number): void;\n\n /**\n * Resets the data source to its empty state, with no result pages, aggregations, etc.\n */\n reset(): void;\n\n /**\n * Notifies the data source that a query change has occurred, which may trigger a data\n * reset & new fetches.\n */\n handleQueryChange(): void;\n\n /**\n * Applies the given map function to all of the tile models in every page of the data\n * source.\n * @param callback A callback function to apply on each tile model, as with Array.map\n */\n map(\n callback: (model: TileModel, index: number, array: TileModel[]) => TileModel\n ): void;\n\n /**\n * Checks every tile's management checkbox\n */\n checkAllTiles(): void;\n\n /**\n * Unchecks every tile's management checkbox\n */\n uncheckAllTiles(): void;\n\n /**\n * Removes all tile models that are currently checked & adjusts the paging\n * of the data source to account for any new gaps in the data.\n */\n removeCheckedTiles(): void;\n}\n\nexport class CollectionBrowserDataSource\n implements CollectionBrowserDataSourceInterface\n{\n private pages: Record<string, TileModel[]> = {};\n\n private offset = 0;\n\n private numTileModels = 0;\n\n /**\n * Maps the full query key to the pages being fetched for that query\n */\n private pageFetchesInProgress: Record<string, Set<number>> = {};\n\n totalResults = 0;\n\n endOfDataReached = false;\n\n /**\n * @inheritdoc\n */\n aggregations?: Record<string, Aggregation>;\n\n /**\n * @inheritdoc\n */\n yearHistogramAggregation?: Aggregation;\n\n /**\n * @inheritdoc\n */\n collectionTitles = new Map<string, string>();\n\n /**\n * @inheritdoc\n */\n collectionExtraInfo?: CollectionExtraInfo;\n\n /**\n * @inheritdoc\n */\n accountExtraInfo?: AccountExtraInfo;\n\n /**\n * @inheritdoc\n */\n pageElements?: PageElementMap;\n\n /**\n * @inheritdoc\n */\n parentCollections?: string[] = [];\n\n /**\n * @inheritdoc\n */\n prefixFilterCountMap: Partial<Record<PrefixFilterType, PrefixFilterCounts>> =\n {};\n\n constructor(\n /** The host element to which this controller should attach listeners */\n private readonly host: ReactiveControllerHost &\n CollectionBrowserSearchInterface,\n /** Default size of result pages */\n private pageSize: number\n ) {\n this.host.addController(this as CollectionBrowserDataSourceInterface);\n }\n\n /**\n * @inheritdoc\n */\n get size(): number {\n return this.numTileModels;\n }\n\n /**\n * @inheritdoc\n */\n addPage(pageNum: number, pageTiles: TileModel[]): void {\n this.pages[pageNum] = pageTiles;\n this.numTileModels += pageTiles.length;\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n getPage(pageNum: number): TileModel[] {\n return this.pages[pageNum];\n }\n\n /**\n * @inheritdoc\n */\n getAllPages(): Record<string, TileModel[]> {\n return this.pages;\n }\n\n /**\n * @inheritdoc\n */\n hasPage(pageNum: number): boolean {\n return !!this.pages[pageNum];\n }\n\n /**\n * @inheritdoc\n */\n getTileModelAt(index: number): TileModel | undefined {\n const pageNum = Math.floor(index / this.pageSize) + 1;\n const indexOnPage = index % this.pageSize;\n return this.pages[pageNum]?.[indexOnPage];\n }\n\n /**\n * @inheritdoc\n */\n setPageSize(pageSize: number): void {\n this.reset();\n this.pageSize = pageSize;\n }\n\n /**\n * @inheritdoc\n */\n reset(): void {\n this.pages = {};\n this.aggregations = {};\n this.yearHistogramAggregation = undefined;\n this.pageFetchesInProgress = {};\n\n this.offset = 0;\n this.numTileModels = 0;\n this.totalResults = 0;\n\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n async handleQueryChange(): Promise<void> {\n this.reset();\n await Promise.all([\n this.doInitialPageFetch(),\n this.host.suppressFacets ? null : this.fetchFacets(),\n ]);\n }\n\n /**\n * @inheritdoc\n */\n map(\n callback: (model: TileModel, index: number, array: TileModel[]) => TileModel\n ): void {\n this.pages = Object.fromEntries(\n Object.entries(this.pages).map(([page, tileModels]) => [\n page,\n tileModels.map((model, index, array) =>\n model ? callback(model, index, array) : model\n ),\n ])\n );\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n checkAllTiles(): void {\n this.map(model => ({ ...model, checked: true }));\n }\n\n /**\n * @inheritdoc\n */\n uncheckAllTiles(): void {\n this.map(model => ({ ...model, checked: false }));\n }\n\n /**\n * @inheritdoc\n */\n removeCheckedTiles(): void {\n // To make sure our data source remains page-aligned, we will offset our data source by\n // the number of removed tiles, so that we can just add the offset when the infinite\n // scroller queries for cell contents.\n // This only matters while we're still viewing the same set of results. If the user changes\n // their query/filters/sort, then the data source is overwritten and the offset cleared.\n const { checkedTileModels, uncheckedTileModels } = this;\n const numChecked = checkedTileModels.length;\n if (numChecked === 0) return;\n this.offset += numChecked;\n const newPages: typeof this.pages = {};\n\n // Which page the remaining tile models start on, post-offset\n let offsetPageNumber = Math.floor(this.offset / this.pageSize) + 1;\n let indexOnPage = this.offset % this.pageSize;\n\n // Fill the pages up to that point with empty models\n for (let page = 1; page <= offsetPageNumber; page += 1) {\n const remainingHidden = this.offset - this.pageSize * (page - 1);\n const offsetCellsOnPage = Math.min(this.pageSize, remainingHidden);\n newPages[page] = Array(offsetCellsOnPage).fill(undefined);\n }\n\n // Shift all the remaining tiles into their new positions in the data source\n for (const model of uncheckedTileModels) {\n if (!newPages[offsetPageNumber]) newPages[offsetPageNumber] = [];\n newPages[offsetPageNumber].push(model);\n indexOnPage += 1;\n if (indexOnPage >= this.pageSize) {\n offsetPageNumber += 1;\n indexOnPage = 0;\n }\n }\n\n // Swap in the new pages\n this.pages = newPages;\n this.numTileModels -= numChecked;\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n get checkedTileModels(): TileModel[] {\n return this.getFilteredTileModels(model => model.checked);\n }\n\n /**\n * @inheritdoc\n */\n get uncheckedTileModels(): TileModel[] {\n return this.getFilteredTileModels(model => !model.checked);\n }\n\n /**\n * Returns a flattened, filtered array of all the tile models in the data source\n * for which the given predicate returns a truthy value.\n *\n * @param predicate A callback function to apply on each tile model, as with Array.filter\n * @returns A filtered array of tile models satisfying the predicate\n */\n private getFilteredTileModels(\n predicate: (model: TileModel, index: number, array: TileModel[]) => unknown\n ): TileModel[] {\n return Object.values(this.pages)\n .flat()\n .filter((model, index, array) =>\n model ? predicate(model, index, array) : false\n );\n }\n\n // DATA FETCHES\n\n /**\n * @inheritdoc\n */\n get canPerformSearch(): boolean {\n if (!this.host.searchService) return false;\n\n const trimmedQuery = this.host.baseQuery?.trim();\n const hasNonEmptyQuery = !!trimmedQuery;\n const isCollectionSearch = !!this.host.withinCollection;\n const isMetadataSearch = this.host.searchType === SearchType.METADATA;\n\n // Metadata searches within a collection are allowed to have no query.\n // Otherwise, a non-empty query must be set.\n return hasNonEmptyQuery || (isCollectionSearch && isMetadataSearch);\n }\n\n /**\n * The query key is a string that uniquely identifies the current search.\n * It consists of:\n * - The current base query\n * - The current collection\n * - The current search type\n * - Any currently-applied facets\n * - Any currently-applied date range\n * - Any currently-applied prefix filters\n * - The current sort options\n *\n * This lets us keep track of queries so we don't persist data that's\n * no longer relevant.\n */\n get pageFetchQueryKey(): string {\n const sortField = this.host.sortParam?.field ?? 'none';\n const sortDirection = this.host.sortParam?.direction ?? 'none';\n return `${this.fullQuery}-${this.host.withinCollection}-${this.host.searchType}-${sortField}-${sortDirection}`;\n }\n\n /**\n * Similar to `pageFetchQueryKey` above, but excludes sort fields since they\n * are not relevant in determining aggregation queries.\n */\n get facetFetchQueryKey(): string {\n return `${this.fullQuery}-${this.host.withinCollection}-${this.host.searchType}`;\n }\n\n /**\n * Constructs a search service FilterMap object from the combination of\n * all the currently-applied filters. This includes any facets, letter\n * filters, and date range.\n */\n get filterMap(): FilterMap {\n const builder = new FilterMapBuilder();\n\n // Add the date range, if applicable\n if (this.host.minSelectedDate) {\n builder.addFilter(\n 'year',\n this.host.minSelectedDate,\n FilterConstraint.GREATER_OR_EQUAL\n );\n }\n if (this.host.maxSelectedDate) {\n builder.addFilter(\n 'year',\n this.host.maxSelectedDate,\n FilterConstraint.LESS_OR_EQUAL\n );\n }\n\n // Add any selected facets\n if (this.host.selectedFacets) {\n for (const [facetName, facetValues] of Object.entries(\n this.host.selectedFacets\n )) {\n const { name, values } = this.prepareFacetForFetch(\n facetName,\n facetValues\n );\n for (const [value, bucket] of Object.entries(values)) {\n let constraint;\n if (bucket.state === 'selected') {\n constraint = FilterConstraint.INCLUDE;\n } else if (bucket.state === 'hidden') {\n constraint = FilterConstraint.EXCLUDE;\n }\n\n if (constraint) {\n builder.addFilter(name, value, constraint);\n }\n }\n }\n }\n\n // Add any letter filters\n if (this.host.selectedTitleFilter) {\n builder.addFilter(\n 'firstTitle',\n this.host.selectedTitleFilter,\n FilterConstraint.INCLUDE\n );\n }\n if (this.host.selectedCreatorFilter) {\n builder.addFilter(\n 'firstCreator',\n this.host.selectedCreatorFilter,\n FilterConstraint.INCLUDE\n );\n }\n\n const filterMap = builder.build();\n return filterMap;\n }\n\n /**\n * Produces a compact unique ID for a search request that can help with debugging\n * on the backend by making related requests easier to trace through different services.\n * (e.g., tying the hits/aggregations requests for the same page back to a single hash).\n *\n * @param params The search service parameters for the request\n * @param kind The kind of request (hits-only, aggregations-only, or both)\n * @returns A Promise resolving to the uid to apply to the request\n */\n async requestUID(params: SearchParams, kind: RequestKind): Promise<string> {\n const paramsToHash = JSON.stringify({\n pageType: params.pageType,\n pageTarget: params.pageTarget,\n query: params.query,\n fields: params.fields,\n filters: params.filters,\n sort: params.sort,\n searchType: this.host.searchType,\n });\n\n const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this\n const sessionId = (await this.host.getSessionId()).slice(0, 20); // Likewise\n const page = params.page ?? 0;\n const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations\n const currentTime = Date.now();\n\n return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;\n }\n\n /**\n * @inheritdoc\n */\n get pageSpecifierParams(): PageSpecifierParams | null {\n if (this.host.withinCollection) {\n return {\n pageType: 'collection_details',\n pageTarget: this.host.withinCollection,\n };\n }\n if (this.host.withinProfile) {\n return {\n pageType: 'account_details',\n pageTarget: this.host.withinProfile,\n pageElements: this.host.profileElement\n ? [this.host.profileElement]\n : [],\n };\n }\n return null;\n }\n\n /**\n * The full query, including year facets and date range clauses\n */\n private get fullQuery(): string | undefined {\n let fullQuery = this.host.baseQuery?.trim() ?? '';\n\n const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;\n\n if (facetQuery) {\n fullQuery += ` AND ${facetQuery}`;\n }\n if (dateRangeQueryClause) {\n fullQuery += ` AND ${dateRangeQueryClause}`;\n }\n if (sortFilterQueries) {\n fullQuery += ` AND ${sortFilterQueries}`;\n }\n return fullQuery.trim();\n }\n\n /**\n * Generates a query string representing the current set of applied facets\n *\n * Example: `mediatype:(\"collection\" OR \"audio\" OR -\"etree\") AND year:(\"2000\" OR \"2001\")`\n */\n private get facetQuery(): string | undefined {\n if (!this.host.selectedFacets) return undefined;\n const facetClauses = [];\n for (const [facetName, facetValues] of Object.entries(\n this.host.selectedFacets\n )) {\n facetClauses.push(this.buildFacetClause(facetName, facetValues));\n }\n return this.joinFacetClauses(facetClauses)?.trim();\n }\n\n private get dateRangeQueryClause(): string | undefined {\n if (!this.host.minSelectedDate || !this.host.maxSelectedDate) {\n return undefined;\n }\n\n return `year:[${this.host.minSelectedDate} TO ${this.host.maxSelectedDate}]`;\n }\n\n private get sortFilterQueries(): string {\n const queries = [this.titleQuery, this.creatorQuery];\n return queries.filter(q => q).join(' AND ');\n }\n\n /**\n * Returns a query clause identifying the currently selected title filter,\n * e.g., `firstTitle:X`.\n */\n private get titleQuery(): string | undefined {\n return this.host.selectedTitleFilter\n ? `firstTitle:${this.host.selectedTitleFilter}`\n : undefined;\n }\n\n /**\n * Returns a query clause identifying the currently selected creator filter,\n * e.g., `firstCreator:X`.\n */\n private get creatorQuery(): string | undefined {\n return this.host.selectedCreatorFilter\n ? `firstCreator:${this.host.selectedCreatorFilter}`\n : undefined;\n }\n\n /**\n * Builds an OR-joined facet clause for the given facet name and values.\n *\n * E.g., for name `subject` and values\n * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`\n * this will produce the clause\n * `subject:(\"foo\" OR -\"bar\")`.\n *\n * @param facetName The facet type (e.g., 'collection')\n * @param facetValues The facet buckets, mapped by their keys\n */\n private buildFacetClause(\n facetName: string,\n facetValues: Record<string, FacetBucket>\n ): string {\n const { name: facetQueryName, values } = this.prepareFacetForFetch(\n facetName,\n facetValues\n );\n const facetEntries = Object.entries(values);\n if (facetEntries.length === 0) return '';\n\n const facetValuesArray: string[] = [];\n for (const [key, facetData] of facetEntries) {\n const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';\n facetValuesArray.push(`${plusMinusPrefix}\"${key}\"`);\n }\n\n const valueQuery = facetValuesArray.join(` OR `);\n return `${facetQueryName}:(${valueQuery})`;\n }\n\n /**\n * Handles some special pre-request normalization steps for certain facet types\n * that require them.\n *\n * @param facetName The name of the facet type (e.g., 'language')\n * @param facetValues An array of values for that facet type\n */\n private prepareFacetForFetch(\n facetName: string,\n facetValues: Record<string, FacetBucket>\n ): { name: string; values: Record<string, FacetBucket> } {\n // eslint-disable-next-line prefer-const\n let [normalizedName, normalizedValues] = [facetName, facetValues];\n\n // The full \"search engine\" name of the lending field is \"lending___status\"\n if (facetName === 'lending') {\n normalizedName = 'lending___status';\n }\n\n return {\n name: normalizedName,\n values: normalizedValues,\n };\n }\n\n /**\n * Takes an array of facet clauses, and combines them into a\n * full AND-joined facet query string. Empty clauses are ignored.\n */\n private joinFacetClauses(facetClauses: string[]): string | undefined {\n const nonEmptyFacetClauses = facetClauses.filter(\n clause => clause.length > 0\n );\n return nonEmptyFacetClauses.length > 0\n ? `(${nonEmptyFacetClauses.join(' AND ')})`\n : undefined;\n }\n\n /**\n * Fires a backend request to fetch a set of aggregations (representing UI facets) for\n * the current search state.\n */\n private async fetchFacets(): Promise<void> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return;\n\n const { facetFetchQueryKey } = this;\n\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n rows: 0,\n filters: this.filterMap,\n // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed\n aggregationsSize: 10,\n // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.\n // The default aggregations for the search_results page type should be what we need here.\n };\n params.uid = await this.requestUID(\n { ...params, sort: sortParams },\n 'aggregations'\n );\n\n this.host.setFacetsLoading(true);\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n const success = searchResponse?.success;\n\n // This is checking to see if the query has changed since the data was fetched.\n // If so, we just want to discard this set of aggregations because they are\n // likely no longer valid for the newer query.\n const queryChangedSinceFetch =\n facetFetchQueryKey !== this.facetFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n if (!success) {\n const errorMsg = searchResponse?.error?.message;\n const detailMsg = searchResponse?.error?.details?.message;\n\n if (!errorMsg && !detailMsg) {\n // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'\n window?.Sentry?.captureMessage?.(\n 'Missing or malformed facet response from backend',\n 'error'\n );\n }\n\n return;\n }\n\n const { aggregations, collectionTitles } = success.response;\n this.aggregations = aggregations;\n\n if (collectionTitles) {\n for (const [id, title] of Object.entries(collectionTitles)) {\n this.collectionTitles.set(id, title);\n }\n }\n\n this.yearHistogramAggregation =\n success?.response?.aggregations?.year_histogram;\n\n this.host.setFacetsLoading(false);\n }\n\n /**\n * Performs the initial page fetch(es) for the current search state.\n */\n private async doInitialPageFetch(): Promise<void> {\n this.host.setSearchResultsLoading(true);\n // Try to batch 2 initial page requests when possible\n await this.fetchPage(this.host.initialPageNumber, 2);\n this.host.setSearchResultsLoading(false);\n }\n\n /**\n * Fetches one or more pages of results and updates the data source.\n *\n * @param pageNumber The page number to fetch\n * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),\n * specifies how many pages to batch together in one request. Ignored\n * if `pageNumber != 1`, defaulting to a single page.\n */\n async fetchPage(pageNumber: number, numInitialPages = 1): Promise<void> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return;\n\n // if we already have data, don't fetch again\n if (this.hasPage(pageNumber)) return;\n\n if (this.endOfDataReached) return;\n\n // Batch multiple initial page requests together if needed (e.g., can request\n // pages 1 and 2 together in a single request).\n const numPages = pageNumber === 1 ? numInitialPages : 1;\n const numRows = this.pageSize * numPages;\n\n // if a fetch is already in progress for this query and page, don't fetch again\n const { pageFetchQueryKey } = this;\n const pageFetches =\n this.pageFetchesInProgress[pageFetchQueryKey] ?? new Set();\n if (pageFetches.has(pageNumber)) return;\n for (let i = 0; i < numPages; i += 1) {\n pageFetches.add(pageNumber + i);\n }\n this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;\n\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n page: pageNumber,\n rows: numRows,\n sort: sortParams,\n filters: this.filterMap,\n aggregations: { omit: true },\n };\n params.uid = await this.requestUID(params, 'hits');\n\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n const success = searchResponse?.success;\n\n // This is checking to see if the query has changed since the data was fetched.\n // If so, we just want to discard the data since there should be a new query\n // right behind it.\n const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n if (!success) {\n const errorMsg = searchResponse?.error?.message;\n const detailMsg = searchResponse?.error?.details?.message;\n\n this.host.queryErrorMessage = `${errorMsg ?? ''}${\n detailMsg ? `; ${detailMsg}` : ''\n }`;\n\n if (!this.host.queryErrorMessage) {\n this.host.queryErrorMessage =\n 'Missing or malformed response from backend';\n // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'\n window?.Sentry?.captureMessage?.(this.queryErrorMessage, 'error');\n }\n\n for (let i = 0; i < numPages; i += 1) {\n this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber + i);\n }\n\n this.host.setSearchResultsLoading(false);\n return;\n }\n\n this.totalResults = success.response.totalResults - this.offset;\n\n // display event to offshoot when result count is zero.\n if (this.totalResults === 0) {\n this.host.emitEmptyResults();\n }\n\n if (this.host.withinCollection) {\n this.collectionExtraInfo = success.response.collectionExtraInfo;\n\n // For collections, we want the UI to respect the default sort option\n // which can be specified in metadata, or otherwise assumed to be week:desc\n this.host.applyDefaultCollectionSort(this.collectionExtraInfo);\n\n if (this.collectionExtraInfo) {\n this.parentCollections = [].concat(\n this.collectionExtraInfo.public_metadata?.collection ?? []\n );\n }\n }\n\n const { results, collectionTitles } = success.response;\n if (results && results.length > 0) {\n // Load any collection titles present on the response into the cache,\n // or queue up preload fetches for them if none were present.\n if (collectionTitles) {\n for (const [id, title] of Object.entries(collectionTitles)) {\n this.collectionTitles.set(id, title);\n }\n }\n\n // Update the data source for each returned page\n for (let i = 0; i < numPages; i += 1) {\n const pageStartIndex = this.pageSize * i;\n this.addTilesToDataSource(\n pageNumber + i,\n results.slice(pageStartIndex, pageStartIndex + this.pageSize)\n );\n }\n }\n\n // When we reach the end of the data, we can set the infinite scroller's\n // item count to the real total number of results (rather than the\n // temporary estimates based on pages rendered so far).\n const resultCountDiscrepancy = numRows - results.length;\n if (resultCountDiscrepancy > 0) {\n this.endOfDataReached = true;\n this.host.setTotalResultCount(this.totalResults);\n }\n\n for (let i = 0; i < numPages; i += 1) {\n this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber + i);\n }\n }\n\n /**\n * Update the datasource from the fetch response\n *\n * @param pageNumber\n * @param results\n */\n private addTilesToDataSource(\n pageNumber: number,\n results: SearchResult[]\n ): void {\n // copy our existing datasource so when we set it below, it gets set\n // instead of modifying the existing dataSource since object changes\n // don't trigger a re-render\n // const datasource = { ...this.dataSource };\n const tiles: TileModel[] = [];\n results?.forEach(result => {\n if (!result.identifier) return;\n\n let loginRequired = false;\n let contentWarning = false;\n // Check if item and item in \"modifying\" collection, setting above flags\n if (\n result.collection?.values.length &&\n result.mediatype?.value !== 'collection'\n ) {\n for (const collection of result.collection?.values ?? []) {\n if (collection === 'loggedin') {\n loginRequired = true;\n if (contentWarning) break;\n }\n if (collection === 'no-preview') {\n contentWarning = true;\n if (loginRequired) break;\n }\n }\n }\n\n tiles.push({\n averageRating: result.avg_rating?.value,\n checked: false,\n collections: result.collection?.values ?? [],\n collectionFilesCount: result.collection_files_count?.value ?? 0,\n collectionSize: result.collection_size?.value ?? 0,\n commentCount: result.num_reviews?.value ?? 0,\n creator: result.creator?.value,\n creators: result.creator?.values ?? [],\n dateAdded: result.addeddate?.value,\n dateArchived: result.publicdate?.value,\n datePublished: result.date?.value,\n dateReviewed: result.reviewdate?.value,\n description: result.description?.values.join('\\n'),\n favCount: result.num_favorites?.value ?? 0,\n href: this.collapseRepeatedQuotes(result.__href__?.value),\n identifier: result.identifier,\n issue: result.issue?.value,\n itemCount: result.item_count?.value ?? 0,\n mediatype: this.getMediatype(result),\n snippets: result.highlight?.values ?? [],\n source: result.source?.value,\n subjects: result.subject?.values ?? [],\n title: result.title?.value ?? '',\n volume: result.volume?.value,\n viewCount: result.downloads?.value ?? 0,\n weeklyViewCount: result.week?.value,\n loginRequired,\n contentWarning,\n });\n });\n this.addPage(pageNumber, tiles);\n const visiblePages = this.host.currentVisiblePageNumbers;\n const needsReload = visiblePages.includes(pageNumber);\n if (needsReload) {\n this.host.refreshVisibleResults();\n }\n }\n\n /**\n * Returns the mediatype string for the given search result, taking into account\n * the special `favorited_search` hit type.\n * @param result The search result to extract a mediatype from\n */\n private getMediatype(result: SearchResult): MediaType {\n /**\n * hit_type == 'favorited_search' is basically a new hit_type\n * - we are getting from PPS.\n * - which gives response for fav- collection\n * - having favorited items like account/collection/item etc..\n * - as user can also favorite a search result (a search page)\n * - so we need to have response (having fav- items and fav- search results)\n *\n * if backend hit_type == 'favorited_search'\n * - let's assume a \"search\" as new mediatype\n */\n if (result?.rawMetadata?.hit_type === 'favorited_search') {\n return 'search';\n }\n\n return result.mediatype?.value ?? 'data';\n }\n\n /**\n * Returns the input string, but removing one set of quotes from all instances of\n * \"\"clauses wrapped in two sets of quotes\"\". This assumes the quotes are already\n * URL-encoded.\n *\n * This should be a temporary measure to address the fact that the __href__ field\n * sometimes acquires extra quotation marks during query rewriting. Once there is a\n * full Lucene parser in place that handles quoted queries correctly, this can likely\n * be removed.\n */\n private collapseRepeatedQuotes(str?: string): string | undefined {\n return str?.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');\n }\n\n /**\n * Fetches the aggregation buckets for the given prefix filter type.\n */\n private async fetchPrefixFilterBuckets(\n filterType: PrefixFilterType\n ): Promise<Bucket[]> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return [];\n\n const filterAggregationKey = prefixFilterAggregationKeys[filterType];\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n rows: 0,\n filters: this.filterMap,\n // Only fetch the firstTitle or firstCreator aggregation\n aggregations: { simpleParams: [filterAggregationKey] },\n // Fetch all 26 letter buckets\n aggregationsSize: 26,\n };\n params.uid = await this.requestUID(\n { ...params, sort: sortParams },\n 'aggregations'\n );\n\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n\n return (searchResponse?.success?.response?.aggregations?.[\n filterAggregationKey\n ]?.buckets ?? []) as Bucket[];\n }\n\n /**\n * Fetches and caches the prefix filter counts for the given filter type.\n */\n async updatePrefixFilterCounts(filterType: PrefixFilterType): Promise<void> {\n const { facetFetchQueryKey } = this;\n const buckets = await this.fetchPrefixFilterBuckets(filterType);\n\n // Don't update the filter counts for an outdated query (if it has been changed\n // since we sent the request)\n const queryChangedSinceFetch =\n facetFetchQueryKey !== this.facetFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }\n this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update\n this.prefixFilterCountMap[filterType] = buckets.reduce(\n (acc: Record<string, number>, bucket: Bucket) => {\n acc[(bucket.key as string).toUpperCase()] = bucket.doc_count;\n return acc;\n },\n {}\n );\n\n this.host.requestUpdate();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"collection-browser-data-source.js","sourceRoot":"","sources":["../../../src/data-source/collection-browser-data-source.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,gBAAgB,EAEhB,gBAAgB,EAIhB,UAAU,GACX,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,2BAA2B,GAK5B,MAAM,WAAW,CAAC;AAMnB,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAoMrC,MAAM,OAAO,2BAA2B;IA2DtC;IACE,wEAAwE;IACvD,IACiB;IAClC,mCAAmC;IAC3B,QAAgB;QAHP,SAAI,GAAJ,IAAI,CACa;QAE1B,aAAQ,GAAR,QAAQ,CAAQ;QA7DlB,UAAK,GAAgC,EAAE,CAAC;QAExC,WAAM,GAAG,CAAC,CAAC;QAEX,kBAAa,GAAG,CAAC,CAAC;QAE1B;;WAEG;QACK,0BAAqB,GAAgC,EAAE,CAAC;QAEhE,iBAAY,GAAG,CAAC,CAAC;QAEjB,qBAAgB,GAAG,KAAK,CAAC;QAYzB;;WAEG;QACH,qBAAgB,GAAG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AAG,CAAC;QACb,CAAC,EACD,EAAE,CACH,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\nimport {\n AccountExtraInfo,\n Aggregation,\n Bucket,\n CollectionExtraInfo,\n FilterConstraint,\n FilterMap,\n FilterMapBuilder,\n PageElementMap,\n SearchParams,\n SearchResult,\n SearchType,\n} from '@internetarchive/search-service';\nimport type { MediaType } from '@internetarchive/field-parsers';\nimport {\n prefixFilterAggregationKeys,\n type FacetBucket,\n type PrefixFilterType,\n type TileModel,\n PrefixFilterCounts,\n} from '../models';\nimport type {\n CollectionBrowserSearchInterface,\n CollectionTitles,\n PageSpecifierParams,\n} from './models';\nimport { sha1 } from '../utils/sha1';\n\ntype RequestKind = 'full' | 'hits' | 'aggregations';\n\nexport interface CollectionBrowserDataSourceInterface\n extends ReactiveController {\n /**\n * How many tile models are present in this data source\n */\n readonly size: number;\n\n /**\n * Whether the host has a valid set of properties for performing a search.\n * For instance, on the search page this requires a valid search service and a\n * non-empty query, while collection pages allow searching with an empty query\n * for MDS but not FTS.\n */\n readonly canPerformSearch: boolean;\n\n /**\n * A string key compactly representing the current full search state, which can\n * be used to determine, e.g., when a new search is required or whether an arriving\n * response is outdated.\n */\n readonly pageFetchQueryKey: string;\n\n /**\n * Similar to `pageFetchQueryKey`, but excluding properties that do not affect\n * the validity of a set of facets (e.g., sort).\n */\n readonly facetFetchQueryKey: string;\n\n /**\n * An object representing any collection- or profile-specific properties to be passed along\n * to the search service, specifying the exact page/tab to fetch results for.\n */\n readonly pageSpecifierParams: PageSpecifierParams | null;\n\n /**\n * A FilterMap object representing all filters applied to the current search,\n * including any facets, letter filters, and date ranges.\n */\n readonly filterMap: FilterMap;\n\n /**\n * The full set of aggregations retrieved for the current search.\n */\n readonly aggregations?: Record<string, Aggregation>;\n\n /**\n * The `year_histogram` aggregation retrieved for the current search.\n */\n readonly yearHistogramAggregation?: Aggregation;\n\n /**\n * A map from collection identifiers that appear on hits or aggregations for the\n * current search, to their human-readable collection titles.\n */\n readonly collectionTitles: CollectionTitles;\n\n /**\n * The \"extra info\" package provided by the PPS for collection pages, including details\n * used to populate the target collection header & About tab content.\n */\n readonly collectionExtraInfo?: CollectionExtraInfo;\n\n /**\n * The \"extra info\" package provided by the PPS for profile pages, including details\n * used to populate the profile header.\n */\n readonly accountExtraInfo?: AccountExtraInfo;\n\n /**\n * The set of requested page elements for profile pages, if applicable. These represent\n * any content specific to the current profile tab.\n */\n readonly pageElements?: PageElementMap;\n\n /**\n * An array of the current target collection's parent collections. Should include *all*\n * ancestors in the collection hierarchy, not just the immediate parent.\n */\n readonly parentCollections?: string[];\n\n /**\n * An object storing result counts for the current search bucketed by letter prefix.\n * Keys are the result field on which the prefixes are considered (e.g., title/creator)\n * and values are a Record mapping letters to their counts.\n */\n readonly prefixFilterCountMap: Partial<\n Record<PrefixFilterType, PrefixFilterCounts>\n >;\n\n /**\n * An array of all the tile models whose management checkboxes are checked\n */\n readonly checkedTileModels: TileModel[];\n\n /**\n * An array of all the tile models whose management checkboxes are unchecked\n */\n readonly uncheckedTileModels: TileModel[];\n\n /**\n * Adds the given page of tile models to the data source.\n * If the given page number already exists, that page will be overwritten.\n * @param pageNum Which page number to add (indexed starting from 1)\n * @param pageTiles The array of tile models for the new page\n */\n addPage(pageNum: number, pageTiles: TileModel[]): void;\n\n /**\n * Returns the given page of tile models from the data source.\n * @param pageNum Which page number to get (indexed starting from 1)\n */\n getPage(pageNum: number): TileModel[];\n\n /**\n * Returns the full set of paged tile models stored in this data source.\n */\n getAllPages(): Record<string, TileModel[]>;\n\n /**\n * Whether the data source contains any tiles for the given page number.\n * @param pageNum Which page number to query (indexed starting from 1)\n */\n hasPage(pageNum: number): boolean;\n\n /**\n * Returns the single tile model appearing at the given index in the\n * data source, with respect to the current page size. Returns `undefined` if\n * the corresponding page is not present on the data source or if it does not\n * contain a tile model at the corresponding index.\n * @param index The 0-based index (within the full data source) of the tile to get\n */\n getTileModelAt(index: number): TileModel | undefined;\n\n /**\n * Requests that the data source fire a backend request for the given page of results.\n * @param pageNum Which page number to fetch results for\n * @param numInitialPages How many pages should be batched together on an initial fetch\n */\n fetchPage(pageNum: number, numInitialPages?: number): Promise<void>;\n\n /**\n * Requests that the data source update its prefix bucket result counts for the given\n * type of prefix filter.\n * @param filterType Which prefixable field to update the buckets for (e.g., title/creator)\n */\n updatePrefixFilterCounts(filterType: PrefixFilterType): Promise<void>;\n\n /**\n * Changes the page size used by the data source, discarding any previously-fetched pages.\n *\n * **Note: this operation will reset any data stored in the data source!**\n * @param pageSize\n */\n setPageSize(pageSize: number): void;\n\n /**\n * Resets the data source to its empty state, with no result pages, aggregations, etc.\n */\n reset(): void;\n\n /**\n * Notifies the data source that a query change has occurred, which may trigger a data\n * reset & new fetches.\n */\n handleQueryChange(): void;\n\n /**\n * Applies the given map function to all of the tile models in every page of the data\n * source.\n * @param callback A callback function to apply on each tile model, as with Array.map\n */\n map(\n callback: (model: TileModel, index: number, array: TileModel[]) => TileModel\n ): void;\n\n /**\n * Checks every tile's management checkbox\n */\n checkAllTiles(): void;\n\n /**\n * Unchecks every tile's management checkbox\n */\n uncheckAllTiles(): void;\n\n /**\n * Removes all tile models that are currently checked & adjusts the paging\n * of the data source to account for any new gaps in the data.\n */\n removeCheckedTiles(): void;\n}\n\nexport class CollectionBrowserDataSource\n implements CollectionBrowserDataSourceInterface\n{\n private pages: Record<string, TileModel[]> = {};\n\n private offset = 0;\n\n private numTileModels = 0;\n\n /**\n * Maps the full query key to the pages being fetched for that query\n */\n private pageFetchesInProgress: Record<string, Set<number>> = {};\n\n totalResults = 0;\n\n endOfDataReached = false;\n\n /**\n * @inheritdoc\n */\n aggregations?: Record<string, Aggregation>;\n\n /**\n * @inheritdoc\n */\n yearHistogramAggregation?: Aggregation;\n\n /**\n * @inheritdoc\n */\n collectionTitles = new Map<string, string>();\n\n /**\n * @inheritdoc\n */\n collectionExtraInfo?: CollectionExtraInfo;\n\n /**\n * @inheritdoc\n */\n accountExtraInfo?: AccountExtraInfo;\n\n /**\n * @inheritdoc\n */\n pageElements?: PageElementMap;\n\n /**\n * @inheritdoc\n */\n parentCollections?: string[] = [];\n\n /**\n * @inheritdoc\n */\n prefixFilterCountMap: Partial<Record<PrefixFilterType, PrefixFilterCounts>> =\n {};\n\n constructor(\n /** The host element to which this controller should attach listeners */\n private readonly host: ReactiveControllerHost &\n CollectionBrowserSearchInterface,\n /** Default size of result pages */\n private pageSize: number\n ) {\n this.host.addController(this as CollectionBrowserDataSourceInterface);\n }\n\n /**\n * @inheritdoc\n */\n get size(): number {\n return this.numTileModels;\n }\n\n /**\n * @inheritdoc\n */\n addPage(pageNum: number, pageTiles: TileModel[]): void {\n this.pages[pageNum] = pageTiles;\n this.numTileModels += pageTiles.length;\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n getPage(pageNum: number): TileModel[] {\n return this.pages[pageNum];\n }\n\n /**\n * @inheritdoc\n */\n getAllPages(): Record<string, TileModel[]> {\n return this.pages;\n }\n\n /**\n * @inheritdoc\n */\n hasPage(pageNum: number): boolean {\n return !!this.pages[pageNum];\n }\n\n /**\n * @inheritdoc\n */\n getTileModelAt(index: number): TileModel | undefined {\n const pageNum = Math.floor(index / this.pageSize) + 1;\n const indexOnPage = index % this.pageSize;\n return this.pages[pageNum]?.[indexOnPage];\n }\n\n /**\n * @inheritdoc\n */\n setPageSize(pageSize: number): void {\n this.reset();\n this.pageSize = pageSize;\n }\n\n /**\n * @inheritdoc\n */\n reset(): void {\n this.pages = {};\n this.aggregations = {};\n this.yearHistogramAggregation = undefined;\n this.pageFetchesInProgress = {};\n\n this.offset = 0;\n this.numTileModels = 0;\n this.totalResults = 0;\n\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n async handleQueryChange(): Promise<void> {\n this.reset();\n await Promise.all([\n this.doInitialPageFetch(),\n this.host.suppressFacets ? null : this.fetchFacets(),\n ]);\n }\n\n /**\n * @inheritdoc\n */\n map(\n callback: (model: TileModel, index: number, array: TileModel[]) => TileModel\n ): void {\n this.pages = Object.fromEntries(\n Object.entries(this.pages).map(([page, tileModels]) => [\n page,\n tileModels.map((model, index, array) =>\n model ? callback(model, index, array) : model\n ),\n ])\n );\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n checkAllTiles(): void {\n this.map(model => ({ ...model, checked: true }));\n }\n\n /**\n * @inheritdoc\n */\n uncheckAllTiles(): void {\n this.map(model => ({ ...model, checked: false }));\n }\n\n /**\n * @inheritdoc\n */\n removeCheckedTiles(): void {\n // To make sure our data source remains page-aligned, we will offset our data source by\n // the number of removed tiles, so that we can just add the offset when the infinite\n // scroller queries for cell contents.\n // This only matters while we're still viewing the same set of results. If the user changes\n // their query/filters/sort, then the data source is overwritten and the offset cleared.\n const { checkedTileModels, uncheckedTileModels } = this;\n const numChecked = checkedTileModels.length;\n if (numChecked === 0) return;\n this.offset += numChecked;\n const newPages: typeof this.pages = {};\n\n // Which page the remaining tile models start on, post-offset\n let offsetPageNumber = Math.floor(this.offset / this.pageSize) + 1;\n let indexOnPage = this.offset % this.pageSize;\n\n // Fill the pages up to that point with empty models\n for (let page = 1; page <= offsetPageNumber; page += 1) {\n const remainingHidden = this.offset - this.pageSize * (page - 1);\n const offsetCellsOnPage = Math.min(this.pageSize, remainingHidden);\n newPages[page] = Array(offsetCellsOnPage).fill(undefined);\n }\n\n // Shift all the remaining tiles into their new positions in the data source\n for (const model of uncheckedTileModels) {\n if (!newPages[offsetPageNumber]) newPages[offsetPageNumber] = [];\n newPages[offsetPageNumber].push(model);\n indexOnPage += 1;\n if (indexOnPage >= this.pageSize) {\n offsetPageNumber += 1;\n indexOnPage = 0;\n }\n }\n\n // Swap in the new pages\n this.pages = newPages;\n this.numTileModels -= numChecked;\n this.host.requestUpdate();\n }\n\n /**\n * @inheritdoc\n */\n get checkedTileModels(): TileModel[] {\n return this.getFilteredTileModels(model => model.checked);\n }\n\n /**\n * @inheritdoc\n */\n get uncheckedTileModels(): TileModel[] {\n return this.getFilteredTileModels(model => !model.checked);\n }\n\n /**\n * Returns a flattened, filtered array of all the tile models in the data source\n * for which the given predicate returns a truthy value.\n *\n * @param predicate A callback function to apply on each tile model, as with Array.filter\n * @returns A filtered array of tile models satisfying the predicate\n */\n private getFilteredTileModels(\n predicate: (model: TileModel, index: number, array: TileModel[]) => unknown\n ): TileModel[] {\n return Object.values(this.pages)\n .flat()\n .filter((model, index, array) =>\n model ? predicate(model, index, array) : false\n );\n }\n\n // DATA FETCHES\n\n /**\n * @inheritdoc\n */\n get canPerformSearch(): boolean {\n if (!this.host.searchService) return false;\n\n const trimmedQuery = this.host.baseQuery?.trim();\n const hasNonEmptyQuery = !!trimmedQuery;\n const isCollectionSearch = !!this.host.withinCollection;\n const isProfileSearch = !!this.host.withinProfile;\n const isMetadataSearch = this.host.searchType === SearchType.METADATA;\n\n // Metadata searches within a collection/profile are allowed to have no query.\n // Otherwise, a non-empty query must be set.\n return (\n hasNonEmptyQuery ||\n (isCollectionSearch && isMetadataSearch) ||\n (isProfileSearch && isMetadataSearch)\n );\n }\n\n /**\n * The query key is a string that uniquely identifies the current search.\n * It consists of:\n * - The current base query\n * - The current collection/profile target\n * - The current search type\n * - Any currently-applied facets\n * - Any currently-applied date range\n * - Any currently-applied prefix filters\n * - The current sort options\n *\n * This lets us keep track of queries so we don't persist data that's\n * no longer relevant.\n */\n get pageFetchQueryKey(): string {\n const pageTarget = this.host.withinCollection ?? this.host.withinProfile;\n const sortField = this.host.sortParam?.field ?? 'none';\n const sortDirection = this.host.sortParam?.direction ?? 'none';\n return `${this.fullQuery}-${pageTarget}-${this.host.searchType}-${sortField}-${sortDirection}`;\n }\n\n /**\n * Similar to `pageFetchQueryKey` above, but excludes sort fields since they\n * are not relevant in determining aggregation queries.\n */\n get facetFetchQueryKey(): string {\n const pageTarget = this.host.withinCollection ?? this.host.withinProfile;\n return `${this.fullQuery}-${pageTarget}-${this.host.searchType}`;\n }\n\n /**\n * Constructs a search service FilterMap object from the combination of\n * all the currently-applied filters. This includes any facets, letter\n * filters, and date range.\n */\n get filterMap(): FilterMap {\n const builder = new FilterMapBuilder();\n\n // Add the date range, if applicable\n if (this.host.minSelectedDate) {\n builder.addFilter(\n 'year',\n this.host.minSelectedDate,\n FilterConstraint.GREATER_OR_EQUAL\n );\n }\n if (this.host.maxSelectedDate) {\n builder.addFilter(\n 'year',\n this.host.maxSelectedDate,\n FilterConstraint.LESS_OR_EQUAL\n );\n }\n\n // Add any selected facets\n if (this.host.selectedFacets) {\n for (const [facetName, facetValues] of Object.entries(\n this.host.selectedFacets\n )) {\n const { name, values } = this.prepareFacetForFetch(\n facetName,\n facetValues\n );\n for (const [value, bucket] of Object.entries(values)) {\n let constraint;\n if (bucket.state === 'selected') {\n constraint = FilterConstraint.INCLUDE;\n } else if (bucket.state === 'hidden') {\n constraint = FilterConstraint.EXCLUDE;\n }\n\n if (constraint) {\n builder.addFilter(name, value, constraint);\n }\n }\n }\n }\n\n // Add any letter filters\n if (this.host.selectedTitleFilter) {\n builder.addFilter(\n 'firstTitle',\n this.host.selectedTitleFilter,\n FilterConstraint.INCLUDE\n );\n }\n if (this.host.selectedCreatorFilter) {\n builder.addFilter(\n 'firstCreator',\n this.host.selectedCreatorFilter,\n FilterConstraint.INCLUDE\n );\n }\n\n const filterMap = builder.build();\n return filterMap;\n }\n\n /**\n * Produces a compact unique ID for a search request that can help with debugging\n * on the backend by making related requests easier to trace through different services.\n * (e.g., tying the hits/aggregations requests for the same page back to a single hash).\n *\n * @param params The search service parameters for the request\n * @param kind The kind of request (hits-only, aggregations-only, or both)\n * @returns A Promise resolving to the uid to apply to the request\n */\n async requestUID(params: SearchParams, kind: RequestKind): Promise<string> {\n const paramsToHash = JSON.stringify({\n pageType: params.pageType,\n pageTarget: params.pageTarget,\n query: params.query,\n fields: params.fields,\n filters: params.filters,\n sort: params.sort,\n searchType: this.host.searchType,\n });\n\n const fullQueryHash = (await sha1(paramsToHash)).slice(0, 20); // First 80 bits of SHA-1 are plenty for this\n const sessionId = (await this.host.getSessionId()).slice(0, 20); // Likewise\n const page = params.page ?? 0;\n const kindPrefix = kind.charAt(0); // f = full, h = hits, a = aggregations\n const currentTime = Date.now();\n\n return `R:${fullQueryHash}-S:${sessionId}-P:${page}-K:${kindPrefix}-T:${currentTime}`;\n }\n\n /**\n * @inheritdoc\n */\n get pageSpecifierParams(): PageSpecifierParams | null {\n if (this.host.withinCollection) {\n return {\n pageType: 'collection_details',\n pageTarget: this.host.withinCollection,\n };\n }\n if (this.host.withinProfile) {\n return {\n pageType: 'account_details',\n pageTarget: this.host.withinProfile,\n pageElements: this.host.profileElement\n ? [this.host.profileElement]\n : [],\n };\n }\n return null;\n }\n\n /**\n * The full query, including year facets and date range clauses\n */\n private get fullQuery(): string | undefined {\n let fullQuery = this.host.baseQuery?.trim() ?? '';\n\n const { facetQuery, dateRangeQueryClause, sortFilterQueries } = this;\n\n if (facetQuery) {\n fullQuery += ` AND ${facetQuery}`;\n }\n if (dateRangeQueryClause) {\n fullQuery += ` AND ${dateRangeQueryClause}`;\n }\n if (sortFilterQueries) {\n fullQuery += ` AND ${sortFilterQueries}`;\n }\n return fullQuery.trim();\n }\n\n /**\n * Generates a query string representing the current set of applied facets\n *\n * Example: `mediatype:(\"collection\" OR \"audio\" OR -\"etree\") AND year:(\"2000\" OR \"2001\")`\n */\n private get facetQuery(): string | undefined {\n if (!this.host.selectedFacets) return undefined;\n const facetClauses = [];\n for (const [facetName, facetValues] of Object.entries(\n this.host.selectedFacets\n )) {\n facetClauses.push(this.buildFacetClause(facetName, facetValues));\n }\n return this.joinFacetClauses(facetClauses)?.trim();\n }\n\n private get dateRangeQueryClause(): string | undefined {\n if (!this.host.minSelectedDate || !this.host.maxSelectedDate) {\n return undefined;\n }\n\n return `year:[${this.host.minSelectedDate} TO ${this.host.maxSelectedDate}]`;\n }\n\n private get sortFilterQueries(): string {\n const queries = [this.titleQuery, this.creatorQuery];\n return queries.filter(q => q).join(' AND ');\n }\n\n /**\n * Returns a query clause identifying the currently selected title filter,\n * e.g., `firstTitle:X`.\n */\n private get titleQuery(): string | undefined {\n return this.host.selectedTitleFilter\n ? `firstTitle:${this.host.selectedTitleFilter}`\n : undefined;\n }\n\n /**\n * Returns a query clause identifying the currently selected creator filter,\n * e.g., `firstCreator:X`.\n */\n private get creatorQuery(): string | undefined {\n return this.host.selectedCreatorFilter\n ? `firstCreator:${this.host.selectedCreatorFilter}`\n : undefined;\n }\n\n /**\n * Builds an OR-joined facet clause for the given facet name and values.\n *\n * E.g., for name `subject` and values\n * `{ foo: { state: 'selected' }, bar: { state: 'hidden' } }`\n * this will produce the clause\n * `subject:(\"foo\" OR -\"bar\")`.\n *\n * @param facetName The facet type (e.g., 'collection')\n * @param facetValues The facet buckets, mapped by their keys\n */\n private buildFacetClause(\n facetName: string,\n facetValues: Record<string, FacetBucket>\n ): string {\n const { name: facetQueryName, values } = this.prepareFacetForFetch(\n facetName,\n facetValues\n );\n const facetEntries = Object.entries(values);\n if (facetEntries.length === 0) return '';\n\n const facetValuesArray: string[] = [];\n for (const [key, facetData] of facetEntries) {\n const plusMinusPrefix = facetData.state === 'hidden' ? '-' : '';\n facetValuesArray.push(`${plusMinusPrefix}\"${key}\"`);\n }\n\n const valueQuery = facetValuesArray.join(` OR `);\n return `${facetQueryName}:(${valueQuery})`;\n }\n\n /**\n * Handles some special pre-request normalization steps for certain facet types\n * that require them.\n *\n * @param facetName The name of the facet type (e.g., 'language')\n * @param facetValues An array of values for that facet type\n */\n private prepareFacetForFetch(\n facetName: string,\n facetValues: Record<string, FacetBucket>\n ): { name: string; values: Record<string, FacetBucket> } {\n // eslint-disable-next-line prefer-const\n let [normalizedName, normalizedValues] = [facetName, facetValues];\n\n // The full \"search engine\" name of the lending field is \"lending___status\"\n if (facetName === 'lending') {\n normalizedName = 'lending___status';\n }\n\n return {\n name: normalizedName,\n values: normalizedValues,\n };\n }\n\n /**\n * Takes an array of facet clauses, and combines them into a\n * full AND-joined facet query string. Empty clauses are ignored.\n */\n private joinFacetClauses(facetClauses: string[]): string | undefined {\n const nonEmptyFacetClauses = facetClauses.filter(\n clause => clause.length > 0\n );\n return nonEmptyFacetClauses.length > 0\n ? `(${nonEmptyFacetClauses.join(' AND ')})`\n : undefined;\n }\n\n /**\n * Fires a backend request to fetch a set of aggregations (representing UI facets) for\n * the current search state.\n */\n private async fetchFacets(): Promise<void> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return;\n\n const { facetFetchQueryKey } = this;\n\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n rows: 0,\n filters: this.filterMap,\n // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed\n aggregationsSize: 10,\n // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.\n // The default aggregations for the search_results page type should be what we need here.\n };\n params.uid = await this.requestUID(\n { ...params, sort: sortParams },\n 'aggregations'\n );\n\n this.host.setFacetsLoading(true);\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n const success = searchResponse?.success;\n\n // This is checking to see if the query has changed since the data was fetched.\n // If so, we just want to discard this set of aggregations because they are\n // likely no longer valid for the newer query.\n const queryChangedSinceFetch =\n facetFetchQueryKey !== this.facetFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n if (!success) {\n const errorMsg = searchResponse?.error?.message;\n const detailMsg = searchResponse?.error?.details?.message;\n\n if (!errorMsg && !detailMsg) {\n // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'\n window?.Sentry?.captureMessage?.(\n 'Missing or malformed facet response from backend',\n 'error'\n );\n }\n\n return;\n }\n\n const { aggregations, collectionTitles } = success.response;\n this.aggregations = aggregations;\n\n if (collectionTitles) {\n for (const [id, title] of Object.entries(collectionTitles)) {\n this.collectionTitles.set(id, title);\n }\n }\n\n this.yearHistogramAggregation =\n success?.response?.aggregations?.year_histogram;\n\n this.host.setFacetsLoading(false);\n }\n\n /**\n * Performs the initial page fetch(es) for the current search state.\n */\n private async doInitialPageFetch(): Promise<void> {\n this.host.setSearchResultsLoading(true);\n // Try to batch 2 initial page requests when possible\n await this.fetchPage(this.host.initialPageNumber, 2);\n this.host.setSearchResultsLoading(false);\n }\n\n /**\n * Fetches one or more pages of results and updates the data source.\n *\n * @param pageNumber The page number to fetch\n * @param numInitialPages If this is an initial page fetch (`pageNumber = 1`),\n * specifies how many pages to batch together in one request. Ignored\n * if `pageNumber != 1`, defaulting to a single page.\n */\n async fetchPage(pageNumber: number, numInitialPages = 1): Promise<void> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return;\n\n // if we already have data, don't fetch again\n if (this.hasPage(pageNumber)) return;\n\n if (this.endOfDataReached) return;\n\n // Batch multiple initial page requests together if needed (e.g., can request\n // pages 1 and 2 together in a single request).\n const numPages = pageNumber === 1 ? numInitialPages : 1;\n const numRows = this.pageSize * numPages;\n\n // if a fetch is already in progress for this query and page, don't fetch again\n const { pageFetchQueryKey } = this;\n const pageFetches =\n this.pageFetchesInProgress[pageFetchQueryKey] ?? new Set();\n if (pageFetches.has(pageNumber)) return;\n for (let i = 0; i < numPages; i += 1) {\n pageFetches.add(pageNumber + i);\n }\n this.pageFetchesInProgress[pageFetchQueryKey] = pageFetches;\n\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n page: pageNumber,\n rows: numRows,\n sort: sortParams,\n filters: this.filterMap,\n aggregations: { omit: true },\n };\n params.uid = await this.requestUID(params, 'hits');\n\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n const success = searchResponse?.success;\n\n // This is checking to see if the query has changed since the data was fetched.\n // If so, we just want to discard the data since there should be a new query\n // right behind it.\n const queryChangedSinceFetch = pageFetchQueryKey !== this.pageFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n if (!success) {\n const errorMsg = searchResponse?.error?.message;\n const detailMsg = searchResponse?.error?.details?.message;\n\n this.host.queryErrorMessage = `${errorMsg ?? ''}${\n detailMsg ? `; ${detailMsg}` : ''\n }`;\n\n if (!this.host.queryErrorMessage) {\n this.host.queryErrorMessage =\n 'Missing or malformed response from backend';\n // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'\n window?.Sentry?.captureMessage?.(this.queryErrorMessage, 'error');\n }\n\n for (let i = 0; i < numPages; i += 1) {\n this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber + i);\n }\n\n this.host.setSearchResultsLoading(false);\n return;\n }\n\n this.totalResults = success.response.totalResults - this.offset;\n\n // display event to offshoot when result count is zero.\n if (this.totalResults === 0) {\n this.host.emitEmptyResults();\n }\n\n if (this.host.withinCollection) {\n this.collectionExtraInfo = success.response.collectionExtraInfo;\n\n // For collections, we want the UI to respect the default sort option\n // which can be specified in metadata, or otherwise assumed to be week:desc\n this.host.applyDefaultCollectionSort(this.collectionExtraInfo);\n\n if (this.collectionExtraInfo) {\n this.parentCollections = [].concat(\n this.collectionExtraInfo.public_metadata?.collection ?? []\n );\n }\n }\n\n const { results, collectionTitles } = success.response;\n if (results && results.length > 0) {\n // Load any collection titles present on the response into the cache,\n // or queue up preload fetches for them if none were present.\n if (collectionTitles) {\n for (const [id, title] of Object.entries(collectionTitles)) {\n this.collectionTitles.set(id, title);\n }\n }\n\n // Update the data source for each returned page\n for (let i = 0; i < numPages; i += 1) {\n const pageStartIndex = this.pageSize * i;\n this.addTilesToDataSource(\n pageNumber + i,\n results.slice(pageStartIndex, pageStartIndex + this.pageSize)\n );\n }\n }\n\n // When we reach the end of the data, we can set the infinite scroller's\n // item count to the real total number of results (rather than the\n // temporary estimates based on pages rendered so far).\n const resultCountDiscrepancy = numRows - results.length;\n if (resultCountDiscrepancy > 0) {\n this.endOfDataReached = true;\n this.host.setTotalResultCount(this.totalResults);\n }\n\n for (let i = 0; i < numPages; i += 1) {\n this.pageFetchesInProgress[pageFetchQueryKey]?.delete(pageNumber + i);\n }\n }\n\n /**\n * Update the datasource from the fetch response\n *\n * @param pageNumber\n * @param results\n */\n private addTilesToDataSource(\n pageNumber: number,\n results: SearchResult[]\n ): void {\n // copy our existing datasource so when we set it below, it gets set\n // instead of modifying the existing dataSource since object changes\n // don't trigger a re-render\n // const datasource = { ...this.dataSource };\n const tiles: TileModel[] = [];\n results?.forEach(result => {\n if (!result.identifier) return;\n\n let loginRequired = false;\n let contentWarning = false;\n // Check if item and item in \"modifying\" collection, setting above flags\n if (\n result.collection?.values.length &&\n result.mediatype?.value !== 'collection'\n ) {\n for (const collection of result.collection?.values ?? []) {\n if (collection === 'loggedin') {\n loginRequired = true;\n if (contentWarning) break;\n }\n if (collection === 'no-preview') {\n contentWarning = true;\n if (loginRequired) break;\n }\n }\n }\n\n tiles.push({\n averageRating: result.avg_rating?.value,\n checked: false,\n collections: result.collection?.values ?? [],\n collectionFilesCount: result.collection_files_count?.value ?? 0,\n collectionSize: result.collection_size?.value ?? 0,\n commentCount: result.num_reviews?.value ?? 0,\n creator: result.creator?.value,\n creators: result.creator?.values ?? [],\n dateAdded: result.addeddate?.value,\n dateArchived: result.publicdate?.value,\n datePublished: result.date?.value,\n dateReviewed: result.reviewdate?.value,\n description: result.description?.values.join('\\n'),\n favCount: result.num_favorites?.value ?? 0,\n href: this.collapseRepeatedQuotes(result.__href__?.value),\n identifier: result.identifier,\n issue: result.issue?.value,\n itemCount: result.item_count?.value ?? 0,\n mediatype: this.getMediatype(result),\n snippets: result.highlight?.values ?? [],\n source: result.source?.value,\n subjects: result.subject?.values ?? [],\n title: result.title?.value ?? '',\n volume: result.volume?.value,\n viewCount: result.downloads?.value ?? 0,\n weeklyViewCount: result.week?.value,\n loginRequired,\n contentWarning,\n });\n });\n this.addPage(pageNumber, tiles);\n const visiblePages = this.host.currentVisiblePageNumbers;\n const needsReload = visiblePages.includes(pageNumber);\n if (needsReload) {\n this.host.refreshVisibleResults();\n }\n }\n\n /**\n * Returns the mediatype string for the given search result, taking into account\n * the special `favorited_search` hit type.\n * @param result The search result to extract a mediatype from\n */\n private getMediatype(result: SearchResult): MediaType {\n /**\n * hit_type == 'favorited_search' is basically a new hit_type\n * - we are getting from PPS.\n * - which gives response for fav- collection\n * - having favorited items like account/collection/item etc..\n * - as user can also favorite a search result (a search page)\n * - so we need to have response (having fav- items and fav- search results)\n *\n * if backend hit_type == 'favorited_search'\n * - let's assume a \"search\" as new mediatype\n */\n if (result?.rawMetadata?.hit_type === 'favorited_search') {\n return 'search';\n }\n\n return result.mediatype?.value ?? 'data';\n }\n\n /**\n * Returns the input string, but removing one set of quotes from all instances of\n * \"\"clauses wrapped in two sets of quotes\"\". This assumes the quotes are already\n * URL-encoded.\n *\n * This should be a temporary measure to address the fact that the __href__ field\n * sometimes acquires extra quotation marks during query rewriting. Once there is a\n * full Lucene parser in place that handles quoted queries correctly, this can likely\n * be removed.\n */\n private collapseRepeatedQuotes(str?: string): string | undefined {\n return str?.replace(/%22%22(?!%22%22)(.+?)%22%22/g, '%22$1%22');\n }\n\n /**\n * Fetches the aggregation buckets for the given prefix filter type.\n */\n private async fetchPrefixFilterBuckets(\n filterType: PrefixFilterType\n ): Promise<Bucket[]> {\n const trimmedQuery = this.host.baseQuery?.trim();\n if (!this.canPerformSearch) return [];\n\n const filterAggregationKey = prefixFilterAggregationKeys[filterType];\n const sortParams = this.host.sortParam ? [this.host.sortParam] : [];\n\n const params: SearchParams = {\n ...this.pageSpecifierParams,\n query: trimmedQuery || '',\n rows: 0,\n filters: this.filterMap,\n // Only fetch the firstTitle or firstCreator aggregation\n aggregations: { simpleParams: [filterAggregationKey] },\n // Fetch all 26 letter buckets\n aggregationsSize: 26,\n };\n params.uid = await this.requestUID(\n { ...params, sort: sortParams },\n 'aggregations'\n );\n\n const searchResponse = await this.host.searchService?.search(\n params,\n this.host.searchType\n );\n\n return (searchResponse?.success?.response?.aggregations?.[\n filterAggregationKey\n ]?.buckets ?? []) as Bucket[];\n }\n\n /**\n * Fetches and caches the prefix filter counts for the given filter type.\n */\n async updatePrefixFilterCounts(filterType: PrefixFilterType): Promise<void> {\n const { facetFetchQueryKey } = this;\n const buckets = await this.fetchPrefixFilterBuckets(filterType);\n\n // Don't update the filter counts for an outdated query (if it has been changed\n // since we sent the request)\n const queryChangedSinceFetch =\n facetFetchQueryKey !== this.facetFetchQueryKey;\n if (queryChangedSinceFetch) return;\n\n // Unpack the aggregation buckets into a simple map like { 'A': 50, 'B': 25, ... }\n this.prefixFilterCountMap = { ...this.prefixFilterCountMap }; // Clone the object to trigger an update\n this.prefixFilterCountMap[filterType] = buckets.reduce(\n (acc: Record<string, number>, bucket: Bucket) => {\n acc[(bucket.key as string).toUpperCase()] = bucket.doc_count;\n return acc;\n },\n {}\n );\n\n this.host.requestUpdate();\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -487,18 +487,23 @@ export class CollectionBrowserDataSource
|
|
|
487
487
|
const trimmedQuery = this.host.baseQuery?.trim();
|
|
488
488
|
const hasNonEmptyQuery = !!trimmedQuery;
|
|
489
489
|
const isCollectionSearch = !!this.host.withinCollection;
|
|
490
|
+
const isProfileSearch = !!this.host.withinProfile;
|
|
490
491
|
const isMetadataSearch = this.host.searchType === SearchType.METADATA;
|
|
491
492
|
|
|
492
|
-
// Metadata searches within a collection are allowed to have no query.
|
|
493
|
+
// Metadata searches within a collection/profile are allowed to have no query.
|
|
493
494
|
// Otherwise, a non-empty query must be set.
|
|
494
|
-
return
|
|
495
|
+
return (
|
|
496
|
+
hasNonEmptyQuery ||
|
|
497
|
+
(isCollectionSearch && isMetadataSearch) ||
|
|
498
|
+
(isProfileSearch && isMetadataSearch)
|
|
499
|
+
);
|
|
495
500
|
}
|
|
496
501
|
|
|
497
502
|
/**
|
|
498
503
|
* The query key is a string that uniquely identifies the current search.
|
|
499
504
|
* It consists of:
|
|
500
505
|
* - The current base query
|
|
501
|
-
* - The current collection
|
|
506
|
+
* - The current collection/profile target
|
|
502
507
|
* - The current search type
|
|
503
508
|
* - Any currently-applied facets
|
|
504
509
|
* - Any currently-applied date range
|
|
@@ -509,9 +514,10 @@ export class CollectionBrowserDataSource
|
|
|
509
514
|
* no longer relevant.
|
|
510
515
|
*/
|
|
511
516
|
get pageFetchQueryKey(): string {
|
|
517
|
+
const pageTarget = this.host.withinCollection ?? this.host.withinProfile;
|
|
512
518
|
const sortField = this.host.sortParam?.field ?? 'none';
|
|
513
519
|
const sortDirection = this.host.sortParam?.direction ?? 'none';
|
|
514
|
-
return `${this.fullQuery}-${
|
|
520
|
+
return `${this.fullQuery}-${pageTarget}-${this.host.searchType}-${sortField}-${sortDirection}`;
|
|
515
521
|
}
|
|
516
522
|
|
|
517
523
|
/**
|
|
@@ -519,7 +525,8 @@ export class CollectionBrowserDataSource
|
|
|
519
525
|
* are not relevant in determining aggregation queries.
|
|
520
526
|
*/
|
|
521
527
|
get facetFetchQueryKey(): string {
|
|
522
|
-
|
|
528
|
+
const pageTarget = this.host.withinCollection ?? this.host.withinProfile;
|
|
529
|
+
return `${this.fullQuery}-${pageTarget}-${this.host.searchType}`;
|
|
523
530
|
}
|
|
524
531
|
|
|
525
532
|
/**
|