import { Aggregation } from '../models/aggregation'; import { SearchResult, HitType } from '../models/hit-types/hit'; import { CollectionExtraInfo } from './collection-extra-info'; import type { SearchHitSchema } from './search-hit-schema'; import { AccountExtraInfo } from './account-extra-info'; import { PageElementMap, SearchResponseHits } from './page-elements'; import { ExtraInfo } from './extra-info'; /** * The structure of the response body returned from the PPS endpoint. */ export interface SearchResponseBody { hits?: SearchResponseHits; aggregations?: Record; collection_titles?: Record; tv_channel_aliases?: Record; collection_extra_info?: CollectionExtraInfo; account_extra_info?: AccountExtraInfo; page_elements?: PageElementMap; extra_info?: Record; } /** * The structure of the optional federated results to be added to the results */ export interface FederatedResults { [key: string]: SearchResult[]; } /** * This is the search response details inside the SearchResponse object that contains * the search results, under the `results` key. * * @export */ export interface SearchResponseDetailsInterface { /** * Total number of results found */ totalResults: number; /** * Number of returned hits in this response */ returnedCount: number; /** * The array of search results */ results: SearchResult[]; /** * The array of federated search results */ federatedResults?: FederatedResults; /** * Requested aggregations such as facets or histogram data * * @type {Record} * @memberof SearchResponseDetails */ aggregations?: Record; /** * A map from collection identifiers (those present on the hits/aggregations) * to their titles. */ collectionTitles?: Record; /** * A map from TV channel names (creators) to their network names. */ tvChannelAliases?: Record; /** * Extra info about the target collection, returned when the page type is * `collection_details`. */ collectionExtraInfo?: CollectionExtraInfo; /** * Extra info about the target account, returned when the page type is * `account_details`. */ accountExtraInfo?: AccountExtraInfo; /** * Extra info about the target item, returned when the page type is * `item_details`. */ extraInfo?: ExtraInfo | null; /** * Specific page elements requested from the PPS will be present in this map */ pageElements?: PageElementMap; /** * The hit schema for this response */ schema?: SearchHitSchema; /** * The hit type from the schema for this resopnse */ schemaHitType?: HitType; } /** * Implementation for search response details, converting raw response bodies * into a more consistent set of properties & types. */ export declare class SearchResponseDetails implements SearchResponseDetailsInterface { /** * @inheritdoc */ totalResults: number; /** * @inheritdoc */ returnedCount: number; /** * @inheritdoc */ results: SearchResult[]; /** * @inheritdoc */ federatedResults?: FederatedResults; /** * @inheritdoc */ aggregations?: Record; /** * @inheritdoc */ collectionTitles?: Record; /** * @inheritdoc */ tvChannelAliases?: Record; /** * @inheritdoc */ collectionExtraInfo?: CollectionExtraInfo; /** * @inheritdoc */ accountExtraInfo?: AccountExtraInfo; /** * @inheritdoc */ extraInfo?: ExtraInfo | null; /** * @inheritdoc */ pageElements?: PageElementMap; /** * @inheritdoc */ schema?: SearchHitSchema; /** * @inheritdoc */ schemaHitType?: HitType; constructor(body: SearchResponseBody, schema: SearchHitSchema); /** * Constructs correctly typed search results objects from raw hits. * * @param hits An array of raw hits data from the PPS * @returns An array of correctly-typed hits given each hit type */ private formatHits; /** * Constructs Aggregation objects from raw aggregations data and applies them * to this instance's aggregations property. * @param aggregations The raw aggregations data from the PPS */ private buildAggregations; /** * Special handling for when the 'lending' page element is present on the response. * @returns An array of raw hits representing current loans. */ private handleLendingPageElement; /** * Special handling for when the 'web_archives' page element is present on the response. * @returns An array of raw hits representing the web archive results. */ private handleWebArchivesPageElement; /** * Special handling for when the federated search elements are present in the response. * Formats all non-metadata hits to a new federatedResults object in the results. */ private handleFederatedPageElements; /** * Utility method to remove 'service___' or 'metadata___mediatype___' from the beginning of * federated page element names, so that output will be cleaner. * * @param name Original page element name * @returns Page element name with prefix removed */ private removePageElementPrefix; /** * Returns a correctly-typed search result depending on the schema's hit_type. */ private static createResult; }