@internetarchive/search-service
Advanced tools
Comparing version 0.4.1-alpha.2 to 0.4.1
@@ -10,6 +10,7 @@ import { html, css, LitElement, TemplateResult, CSSResult, nothing } from 'lit'; | ||
import { Aggregation, Bucket } from '../src/models/aggregation'; | ||
import { SearchBackendOptionsInterface } from '../src/search-backend/search-backend-options'; | ||
@customElement('app-root') | ||
export class AppRoot extends LitElement { | ||
private searchService: SearchServiceInterface = SearchService.default; | ||
@query('#search-input') | ||
@@ -31,5 +32,2 @@ private searchInput!: HTMLInputElement; | ||
@state() | ||
private searchServiceUrlOptions?: SearchBackendOptionsInterface = this.initSearchServiceUrlOptions(); | ||
@state() | ||
private searchResponse?: SearchResponse; | ||
@@ -46,6 +44,2 @@ | ||
private searchService: SearchServiceInterface = new SearchService( | ||
this.searchServiceUrlOptions | ||
); | ||
private get searchResults(): SearchResult[] | undefined { | ||
@@ -59,11 +53,2 @@ return this.searchResponse?.response.results; | ||
private initSearchServiceUrlOptions() { | ||
const params = new URL(window.location.href).searchParams; | ||
return { | ||
baseUrl: params.get('search_base_url') ?? undefined, | ||
servicePath: params.get('search_service_path') ?? undefined, | ||
debuggingEnabled: !!params.get('debugging') ?? undefined, | ||
}; | ||
} | ||
/** @inheritdoc */ | ||
@@ -79,7 +64,3 @@ render(): TemplateResult { | ||
<input | ||
type="checkbox" | ||
id="debug-info-check" | ||
?checked=${this.searchServiceUrlOptions?.debuggingEnabled} | ||
/> | ||
<input type="checkbox" id="debug-info-check" /> | ||
<label for="debug-info-check">Include debugging info</label> | ||
@@ -332,3 +313,2 @@ | ||
const numAggs = Number(this.numAggsInput?.value); | ||
const includeDebugging = this.debugCheck?.checked; | ||
@@ -340,3 +320,2 @@ const searchParams: SearchParams = { | ||
aggregationsSize: numAggs, | ||
debugging: includeDebugging, | ||
}; | ||
@@ -343,0 +322,0 @@ |
import { LitElement, TemplateResult, CSSResult } from 'lit'; | ||
export declare class AppRoot extends LitElement { | ||
private searchService; | ||
private searchInput; | ||
@@ -8,3 +9,2 @@ private debugCheck; | ||
private checkedSort; | ||
private searchServiceUrlOptions?; | ||
private searchResponse?; | ||
@@ -14,6 +14,4 @@ private aggregationsResponse?; | ||
private loadingAggregations; | ||
private searchService; | ||
private get searchResults(); | ||
private get searchAggregations(); | ||
private initSearchServiceUrlOptions; | ||
/** @inheritdoc */ | ||
@@ -20,0 +18,0 @@ render(): TemplateResult; |
@@ -9,6 +9,5 @@ import { __decorate } from "tslib"; | ||
super(...arguments); | ||
this.searchServiceUrlOptions = this.initSearchServiceUrlOptions(); | ||
this.searchService = SearchService.default; | ||
this.loadingSearchResults = false; | ||
this.loadingAggregations = false; | ||
this.searchService = new SearchService(this.searchServiceUrlOptions); | ||
} | ||
@@ -23,14 +22,4 @@ get searchResults() { | ||
} | ||
initSearchServiceUrlOptions() { | ||
var _a, _b, _c; | ||
const params = new URL(window.location.href).searchParams; | ||
return { | ||
baseUrl: (_a = params.get('search_base_url')) !== null && _a !== void 0 ? _a : undefined, | ||
servicePath: (_b = params.get('search_service_path')) !== null && _b !== void 0 ? _b : undefined, | ||
debuggingEnabled: (_c = !!params.get('debugging')) !== null && _c !== void 0 ? _c : undefined, | ||
}; | ||
} | ||
/** @inheritdoc */ | ||
render() { | ||
var _a; | ||
return html ` | ||
@@ -44,7 +33,3 @@ <fieldset> | ||
<input | ||
type="checkbox" | ||
id="debug-info-check" | ||
?checked=${(_a = this.searchServiceUrlOptions) === null || _a === void 0 ? void 0 : _a.debuggingEnabled} | ||
/> | ||
<input type="checkbox" id="debug-info-check" /> | ||
<label for="debug-info-check">Include debugging info</label> | ||
@@ -276,3 +261,3 @@ | ||
async fetchAggregations(query, searchType) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c; | ||
const checkedAggs = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`input[name='aggs']:checked`); | ||
@@ -285,3 +270,2 @@ const aggregations = { | ||
const numAggs = Number((_b = this.numAggsInput) === null || _b === void 0 ? void 0 : _b.value); | ||
const includeDebugging = (_c = this.debugCheck) === null || _c === void 0 ? void 0 : _c.checked; | ||
const searchParams = { | ||
@@ -292,3 +276,2 @@ query, | ||
aggregationsSize: numAggs, | ||
debugging: includeDebugging, | ||
}; | ||
@@ -302,3 +285,3 @@ this.loadingAggregations = true; | ||
else { | ||
alert(`Oh noes: ${(_d = result === null || result === void 0 ? void 0 : result.error) === null || _d === void 0 ? void 0 : _d.message}`); | ||
alert(`Oh noes: ${(_c = result === null || result === void 0 ? void 0 : result.error) === null || _c === void 0 ? void 0 : _c.message}`); | ||
console.error('Error searching', result === null || result === void 0 ? void 0 : result.error); | ||
@@ -336,5 +319,2 @@ } | ||
state() | ||
], AppRoot.prototype, "searchServiceUrlOptions", void 0); | ||
__decorate([ | ||
state() | ||
], AppRoot.prototype, "searchResponse", void 0); | ||
@@ -341,0 +321,0 @@ __decorate([ |
@@ -29,2 +29,6 @@ import type { Metadata } from '../metadata'; | ||
get identifier(): typeof Metadata.prototype.identifier; | ||
/** Optional. */ | ||
get addeddate(): typeof Metadata.prototype.addeddate; | ||
/** Optional. */ | ||
get avg_rating(): typeof Metadata.prototype.avg_rating; | ||
/** | ||
@@ -76,2 +80,12 @@ * May be a superset of metadata collection field. | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get issue(): typeof Metadata.prototype.issue; | ||
/** | ||
* Computed during document construction. | ||
* Optional. | ||
*/ | ||
get item_count(): typeof Metadata.prototype.item_count; | ||
/** | ||
* In bytes; computed during document construction. | ||
@@ -126,3 +140,8 @@ */ | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get source(): typeof Metadata.prototype.source; | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -129,0 +148,0 @@ */ |
@@ -5,2 +5,3 @@ import { __decorate } from "tslib"; | ||
import { BooleanField } from '../metadata-fields/field-types/boolean'; | ||
import { ByteField } from '../metadata-fields/field-types/byte'; | ||
import { DateField } from '../metadata-fields/field-types/date'; | ||
@@ -34,2 +35,16 @@ import { MediaTypeField } from '../metadata-fields/field-types/mediatype'; | ||
} | ||
/** Optional. */ | ||
get addeddate() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.addeddate) | ||
? new DateField(this.rawMetadata.fields.addeddate) | ||
: undefined; | ||
} | ||
/** Optional. */ | ||
get avg_rating() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.avg_rating) != null | ||
? new NumberField(this.rawMetadata.fields.avg_rating) | ||
: undefined; | ||
} | ||
/** | ||
@@ -51,3 +66,3 @@ * May be a superset of metadata collection field. | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.collection_files_count) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.collection_files_count) != null | ||
? new NumberField(this.rawMetadata.fields.collection_files_count) | ||
@@ -62,4 +77,4 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.collection_size) | ||
? new NumberField(this.rawMetadata.fields.collection_size) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.collection_size) != null | ||
? new ByteField(this.rawMetadata.fields.collection_size) | ||
: undefined; | ||
@@ -99,3 +114,3 @@ } | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.downloads) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.downloads) != null | ||
? new NumberField(this.rawMetadata.fields.downloads) | ||
@@ -109,3 +124,3 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.files_count) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.files_count) != null | ||
? new NumberField(this.rawMetadata.fields.files_count) | ||
@@ -135,2 +150,22 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get issue() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.issue) | ||
? new StringField(this.rawMetadata.fields.issue) | ||
: undefined; | ||
} | ||
/** | ||
* Computed during document construction. | ||
* Optional. | ||
*/ | ||
get item_count() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.item_count) != null | ||
? new NumberField(this.rawMetadata.fields.item_count) | ||
: undefined; | ||
} | ||
/** | ||
* In bytes; computed during document construction. | ||
@@ -140,4 +175,4 @@ */ | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.item_size) | ||
? new NumberField(this.rawMetadata.fields.item_size) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.item_size) != null | ||
? new ByteField(this.rawMetadata.fields.item_size) | ||
: undefined; | ||
@@ -214,3 +249,3 @@ } | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.month) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.month) != null | ||
? new NumberField(this.rawMetadata.fields.month) | ||
@@ -232,3 +267,3 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.num_favorites) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.num_favorites) != null | ||
? new NumberField(this.rawMetadata.fields.num_favorites) | ||
@@ -243,3 +278,3 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.num_reviews) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.num_reviews) != null | ||
? new NumberField(this.rawMetadata.fields.num_reviews) | ||
@@ -249,3 +284,13 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get source() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.source) | ||
? new StringField(this.rawMetadata.fields.source) | ||
: undefined; | ||
} | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -286,3 +331,3 @@ */ | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.week) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.week) != null | ||
? new NumberField(this.rawMetadata.fields.week) | ||
@@ -297,3 +342,3 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.year) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.year) != null | ||
? new NumberField(this.rawMetadata.fields.year) | ||
@@ -305,2 +350,8 @@ : undefined; | ||
Memoize() | ||
], ItemHit.prototype, "addeddate", null); | ||
__decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "avg_rating", null); | ||
__decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "collection", null); | ||
@@ -336,2 +387,8 @@ __decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "issue", null); | ||
__decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "item_count", null); | ||
__decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "item_size", null); | ||
@@ -373,2 +430,5 @@ __decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "source", null); | ||
__decorate([ | ||
Memoize() | ||
], ItemHit.prototype, "subject", null); | ||
@@ -375,0 +435,0 @@ __decorate([ |
@@ -35,2 +35,9 @@ import type { Metadata } from '../metadata'; | ||
get highlight(): StringField | undefined; | ||
/** | ||
* May be stale in FTS. | ||
* Optional. | ||
*/ | ||
get addeddate(): typeof Metadata.prototype.addeddate; | ||
/** Optional. */ | ||
get avg_rating(): typeof Metadata.prototype.avg_rating; | ||
/** Multivalued. */ | ||
@@ -60,2 +67,7 @@ get collection(): typeof Metadata.prototype.collection; | ||
get file_creation_mtime(): NumberField | undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get issue(): typeof Metadata.prototype.issue; | ||
get mediatype(): typeof Metadata.prototype.mediatype; | ||
@@ -73,3 +85,8 @@ /** Optional. */ | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get source(): typeof Metadata.prototype.source; | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -76,0 +93,0 @@ */ |
@@ -44,2 +44,19 @@ import { __decorate } from "tslib"; | ||
} | ||
/** | ||
* May be stale in FTS. | ||
* Optional. | ||
*/ | ||
get addeddate() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.addeddate) | ||
? new DateField(this.rawMetadata.fields.addeddate) | ||
: undefined; | ||
} | ||
/** Optional. */ | ||
get avg_rating() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.avg_rating) != null | ||
? new NumberField(this.rawMetadata.fields.avg_rating) | ||
: undefined; | ||
} | ||
/** Multivalued. */ | ||
@@ -92,3 +109,3 @@ get collection() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.downloads) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.downloads) != null | ||
? new NumberField(this.rawMetadata.fields.downloads) | ||
@@ -111,6 +128,16 @@ : undefined; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.file_creation_mtime) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.file_creation_mtime) != null | ||
? new NumberField(this.rawMetadata.fields.file_creation_mtime) | ||
: undefined; | ||
} | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get issue() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.issue) | ||
? new StringField(this.rawMetadata.fields.issue) | ||
: undefined; | ||
} | ||
get mediatype() { | ||
@@ -125,3 +152,3 @@ var _a, _b; | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.page_num) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.page_num) != null | ||
? new NumberField(this.rawMetadata.fields.page_num) | ||
@@ -154,3 +181,13 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
get source() { | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.source) | ||
? new StringField(this.rawMetadata.fields.source) | ||
: undefined; | ||
} | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -183,3 +220,3 @@ */ | ||
var _a, _b; | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.year) | ||
return ((_b = (_a = this.rawMetadata) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.year) != null | ||
? new NumberField(this.rawMetadata.fields.year) | ||
@@ -204,2 +241,8 @@ : undefined; | ||
Memoize() | ||
], TextHit.prototype, "addeddate", null); | ||
__decorate([ | ||
Memoize() | ||
], TextHit.prototype, "avg_rating", null); | ||
__decorate([ | ||
Memoize() | ||
], TextHit.prototype, "collection", null); | ||
@@ -232,2 +275,5 @@ __decorate([ | ||
Memoize() | ||
], TextHit.prototype, "issue", null); | ||
__decorate([ | ||
Memoize() | ||
], TextHit.prototype, "mediatype", null); | ||
@@ -248,2 +294,5 @@ __decorate([ | ||
Memoize() | ||
], TextHit.prototype, "source", null); | ||
__decorate([ | ||
Memoize() | ||
], TextHit.prototype, "subject", null); | ||
@@ -250,0 +299,0 @@ __decorate([ |
@@ -17,3 +17,2 @@ import { SearchBackendInterface } from './search-backend-interface'; | ||
protected requestScope?: string; | ||
protected debuggingEnabled?: boolean; | ||
constructor(options?: SearchBackendOptionsInterface); | ||
@@ -20,0 +19,0 @@ /** @inheritdoc */ |
@@ -7,5 +7,4 @@ import { SearchServiceError, SearchServiceErrorType, } from '../search-service-error'; | ||
constructor(options) { | ||
var _a, _b; | ||
var _a; | ||
this.baseUrl = (_a = options === null || options === void 0 ? void 0 : options.baseUrl) !== null && _a !== void 0 ? _a : 'archive.org'; | ||
this.debuggingEnabled = (_b = options === null || options === void 0 ? void 0 : options.debuggingEnabled) !== null && _b !== void 0 ? _b : false; | ||
if ((options === null || options === void 0 ? void 0 : options.includeCredentials) !== undefined) { | ||
@@ -97,6 +96,6 @@ this.includeCredentials = options.includeCredentials; | ||
printDebuggingInfo(json) { | ||
var _a, _b; | ||
const debugInfo = json.debugging; | ||
const messages = (_a = debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.messages) !== null && _a !== void 0 ? _a : []; | ||
const data = (_b = debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.data) !== null && _b !== void 0 ? _b : {}; | ||
var _a, _b, _c; | ||
const debugInfo = (_a = json.debugging) === null || _a === void 0 ? void 0 : _a.debugging; // PPS debugging info is doubly-nested, not sure why | ||
const messages = (_b = debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.messages) !== null && _b !== void 0 ? _b : []; | ||
const data = (_c = debugInfo === null || debugInfo === void 0 ? void 0 : debugInfo.data) !== null && _c !== void 0 ? _c : {}; | ||
console.group('Debug messages'); | ||
@@ -103,0 +102,0 @@ for (const message of messages) { |
@@ -11,5 +11,7 @@ import type { SearchParams } from '../search-params'; | ||
private servicePath; | ||
constructor(options?: SearchBackendOptionsInterface); | ||
constructor(options?: SearchBackendOptionsInterface & { | ||
servicePath?: string; | ||
}); | ||
/** @inheritdoc */ | ||
performSearch(params: SearchParams): Promise<Result<any, SearchServiceError>>; | ||
} |
@@ -15,5 +15,2 @@ import { SearchParamURLGenerator } from '../search-param-url-generator'; | ||
async performSearch(params) { | ||
if (this.debuggingEnabled && params.debugging == null) { | ||
params.debugging = true; | ||
} | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams(params); | ||
@@ -20,0 +17,0 @@ const queryAsString = urlSearchParam.toString(); |
@@ -11,5 +11,7 @@ import type { SearchParams } from '../search-params'; | ||
private servicePath; | ||
constructor(options?: SearchBackendOptionsInterface); | ||
constructor(options?: SearchBackendOptionsInterface & { | ||
servicePath?: string; | ||
}); | ||
/** @inheritdoc */ | ||
performSearch(params: SearchParams): Promise<Result<any, SearchServiceError>>; | ||
} |
@@ -15,5 +15,2 @@ import { SearchParamURLGenerator } from '../search-param-url-generator'; | ||
async performSearch(params) { | ||
if (this.debuggingEnabled && params.debugging == null) { | ||
params.debugging = true; | ||
} | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams(params); | ||
@@ -20,0 +17,0 @@ const queryAsString = urlSearchParam.toString(); |
@@ -10,6 +10,4 @@ /** | ||
baseUrl?: string; | ||
servicePath?: string; | ||
includeCredentials?: boolean; | ||
scope?: string; | ||
debuggingEnabled?: boolean; | ||
} |
@@ -5,2 +5,38 @@ import { DateParser } from '@internetarchive/field-parsers'; | ||
import { DateField } from '../../../src/models/metadata-fields/field-types/date'; | ||
const fieldNames = [ | ||
'identifier', | ||
'addeddate', | ||
'avg_rating', | ||
'collection', | ||
'collection_files_count', | ||
'collection_size', | ||
'creator', | ||
'date', | ||
'description', | ||
'downloads', | ||
'files_count', | ||
'genre', | ||
'indexflag', | ||
'issue', | ||
'item_count', | ||
'item_size', | ||
'lending___available_to_borrow', | ||
'lending___available_to_browse', | ||
'lending___available_to_waitlist', | ||
'lending___status', | ||
'language', | ||
'licenseurl', | ||
'mediatype', | ||
'month', | ||
'noindex', | ||
'num_favorites', | ||
'num_reviews', | ||
'source', | ||
'subject', | ||
'title', | ||
'type', | ||
'volume', | ||
'week', | ||
'year', | ||
]; | ||
describe('ItemHit', () => { | ||
@@ -17,12 +53,16 @@ it('constructs basic item hit', () => { | ||
}); | ||
it('handles incomplete data without throwing', () => { | ||
it('handles missing data gracefully', () => { | ||
const hit = new ItemHit({}); | ||
expect(hit.creator).to.be.undefined; | ||
expect(hit.date).to.be.undefined; | ||
expect(hit.description).to.be.undefined; | ||
expect(hit.subject).to.be.undefined; | ||
expect(hit.title).to.be.undefined; | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('handles incomplete field data gracefully', () => { | ||
const hit = new ItemHit({ fields: {} }); | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('constructs item hit with partial fields', () => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; | ||
const json = { | ||
@@ -70,13 +110,18 @@ fields: { | ||
} | ||
expect((_d = hit.collection_files_count) === null || _d === void 0 ? void 0 : _d.value).to.be.undefined; | ||
expect((_e = hit.collection_size) === null || _e === void 0 ? void 0 : _e.value).to.be.undefined; | ||
expect((_f = hit.genre) === null || _f === void 0 ? void 0 : _f.value).to.be.undefined; | ||
expect((_g = hit.language) === null || _g === void 0 ? void 0 : _g.value).to.be.undefined; | ||
expect((_h = hit.lending___status) === null || _h === void 0 ? void 0 : _h.value).to.be.undefined; | ||
expect((_j = hit.licenseurl) === null || _j === void 0 ? void 0 : _j.value).to.be.undefined; | ||
expect((_k = hit.noindex) === null || _k === void 0 ? void 0 : _k.value).to.be.undefined; | ||
expect((_l = hit.num_favorites) === null || _l === void 0 ? void 0 : _l.value).to.be.undefined; | ||
expect((_m = hit.num_reviews) === null || _m === void 0 ? void 0 : _m.value).to.be.undefined; | ||
expect((_o = hit.type) === null || _o === void 0 ? void 0 : _o.value).to.be.undefined; | ||
expect((_p = hit.volume) === null || _p === void 0 ? void 0 : _p.value).to.be.undefined; | ||
expect((_d = hit.addeddate) === null || _d === void 0 ? void 0 : _d.value).to.be.undefined; | ||
expect((_e = hit.avg_rating) === null || _e === void 0 ? void 0 : _e.value).to.be.undefined; | ||
expect((_f = hit.collection_files_count) === null || _f === void 0 ? void 0 : _f.value).to.be.undefined; | ||
expect((_g = hit.collection_size) === null || _g === void 0 ? void 0 : _g.value).to.be.undefined; | ||
expect((_h = hit.issue) === null || _h === void 0 ? void 0 : _h.value).to.be.undefined; | ||
expect((_j = hit.item_count) === null || _j === void 0 ? void 0 : _j.value).to.be.undefined; | ||
expect((_k = hit.genre) === null || _k === void 0 ? void 0 : _k.value).to.be.undefined; | ||
expect((_l = hit.language) === null || _l === void 0 ? void 0 : _l.value).to.be.undefined; | ||
expect((_m = hit.lending___status) === null || _m === void 0 ? void 0 : _m.value).to.be.undefined; | ||
expect((_o = hit.licenseurl) === null || _o === void 0 ? void 0 : _o.value).to.be.undefined; | ||
expect((_p = hit.noindex) === null || _p === void 0 ? void 0 : _p.value).to.be.undefined; | ||
expect((_q = hit.num_favorites) === null || _q === void 0 ? void 0 : _q.value).to.be.undefined; | ||
expect((_r = hit.num_reviews) === null || _r === void 0 ? void 0 : _r.value).to.be.undefined; | ||
expect((_s = hit.source) === null || _s === void 0 ? void 0 : _s.value).to.be.undefined; | ||
expect((_t = hit.type) === null || _t === void 0 ? void 0 : _t.value).to.be.undefined; | ||
expect((_u = hit.volume) === null || _u === void 0 ? void 0 : _u.value).to.be.undefined; | ||
}); | ||
@@ -100,3 +145,3 @@ it('constructs item hit with all fields', () => { | ||
week: 2, | ||
month: 15, | ||
month: 11, | ||
indexflag: ['index', 'nonoindex'], | ||
@@ -107,5 +152,9 @@ lending___available_to_borrow: false, | ||
lending___status: 'foo-status', | ||
addeddate: '2011-07-20T00:00:00Z', | ||
avg_rating: 3, | ||
collection_files_count: 124, | ||
collection_size: 125, | ||
genre: 'foo-genre', | ||
issue: 'foo-issue', | ||
item_count: 0, | ||
language: 'foo-language', | ||
@@ -116,2 +165,3 @@ licenseurl: 'foo-license', | ||
num_reviews: 127, | ||
source: 'foo-source', | ||
type: 'foo-type', | ||
@@ -132,13 +182,56 @@ volume: 'foo-volume', | ||
if (Array.isArray(json.fields[fieldName])) { | ||
expect((_a = hit[fieldName]) === null || _a === void 0 ? void 0 : _a.values).to.deep.equal(json.fields[fieldName]); | ||
expect((_a = hit[fieldName]) === null || _a === void 0 ? void 0 : _a.values).to.deep.equal(json.fields[fieldName], fieldName); | ||
} | ||
else if (hit[fieldName] instanceof DateField) { | ||
expect((_b = hit[fieldName]) === null || _b === void 0 ? void 0 : _b.value).to.deep.equal(DateParser.shared.parseValue(json.fields[fieldName].toString())); | ||
expect((_b = hit[fieldName]) === null || _b === void 0 ? void 0 : _b.value).to.deep.equal(DateParser.shared.parseValue(json.fields[fieldName].toString()), fieldName); | ||
} | ||
else { | ||
expect((_c = hit[fieldName]) === null || _c === void 0 ? void 0 : _c.value).to.equal(json.fields[fieldName]); | ||
expect((_c = hit[fieldName]) === null || _c === void 0 ? void 0 : _c.value).to.equal(json.fields[fieldName], fieldName); | ||
} | ||
} | ||
}); | ||
it('correctly parses falsey boolean/numeric fields', () => { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; | ||
const json = { | ||
fields: { | ||
identifier: 'foo', | ||
lending___available_to_borrow: false, | ||
lending___available_to_browse: false, | ||
lending___available_to_waitlist: false, | ||
noindex: false, | ||
item_size: 0, | ||
files_count: 0, | ||
downloads: 0, | ||
week: 0, | ||
month: 0, | ||
year: 0, | ||
avg_rating: 0, | ||
collection_files_count: 0, | ||
collection_size: 0, | ||
item_count: 0, | ||
num_favorites: 0, | ||
num_reviews: 0, | ||
}, | ||
highlight: null, | ||
_score: 0, | ||
}; | ||
const hit = new ItemHit(json); | ||
expect((_a = hit.lending___available_to_borrow) === null || _a === void 0 ? void 0 : _a.value).to.be.false; | ||
expect((_b = hit.lending___available_to_browse) === null || _b === void 0 ? void 0 : _b.value).to.be.false; | ||
expect((_c = hit.lending___available_to_waitlist) === null || _c === void 0 ? void 0 : _c.value).to.be.false; | ||
expect((_d = hit.noindex) === null || _d === void 0 ? void 0 : _d.value).to.be.false; | ||
expect((_e = hit.item_size) === null || _e === void 0 ? void 0 : _e.value).to.equal(0); | ||
expect((_f = hit.files_count) === null || _f === void 0 ? void 0 : _f.value).to.equal(0); | ||
expect((_g = hit.downloads) === null || _g === void 0 ? void 0 : _g.value).to.equal(0); | ||
expect((_h = hit.week) === null || _h === void 0 ? void 0 : _h.value).to.equal(0); | ||
expect((_j = hit.month) === null || _j === void 0 ? void 0 : _j.value).to.equal(0); | ||
expect((_k = hit.year) === null || _k === void 0 ? void 0 : _k.value).to.equal(0); | ||
expect((_l = hit.avg_rating) === null || _l === void 0 ? void 0 : _l.value).to.equal(0); | ||
expect((_m = hit.collection_files_count) === null || _m === void 0 ? void 0 : _m.value).to.equal(0); | ||
expect((_o = hit.collection_size) === null || _o === void 0 ? void 0 : _o.value).to.equal(0); | ||
expect((_p = hit.item_count) === null || _p === void 0 ? void 0 : _p.value).to.equal(0); | ||
expect((_q = hit.num_favorites) === null || _q === void 0 ? void 0 : _q.value).to.equal(0); | ||
expect((_r = hit.num_reviews) === null || _r === void 0 ? void 0 : _r.value).to.equal(0); | ||
}); | ||
}); | ||
//# sourceMappingURL=item-hit.test.js.map |
@@ -5,2 +5,29 @@ import { DateParser } from '@internetarchive/field-parsers'; | ||
import { DateField } from '../../../src/models/metadata-fields/field-types/date'; | ||
const fieldNames = [ | ||
'identifier', | ||
'addeddate', | ||
'avg_rating', | ||
'collection', | ||
'created_on', | ||
'creator', | ||
'date', | ||
'description', | ||
'downloads', | ||
'filename', | ||
'file_basename', | ||
'file_creation_mtime', | ||
'highlight', | ||
'issue', | ||
'mediatype', | ||
'page_num', | ||
'publicdate', | ||
'result_in_subfile', | ||
'reviewdate', | ||
'source', | ||
'subject', | ||
'title', | ||
'updated_on', | ||
'year', | ||
'__href__', | ||
]; | ||
describe('TextHit', () => { | ||
@@ -12,10 +39,14 @@ it('constructs basic text hit', () => { | ||
}); | ||
it('handles incomplete data without throwing', () => { | ||
it('handles missing data gracefully', () => { | ||
const hit = new TextHit({}); | ||
expect(hit.creator).to.be.undefined; | ||
expect(hit.date).to.be.undefined; | ||
expect(hit.description).to.be.undefined; | ||
expect(hit.subject).to.be.undefined; | ||
expect(hit.title).to.be.undefined; | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('handles incomplete field data gracefully', () => { | ||
const hit = new TextHit({ fields: {} }); | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('constructs text hit with all fields', () => { | ||
@@ -36,3 +67,8 @@ var _a, _b, _c, _d; | ||
subject: ['foo-subject1', 'foo-subject2'], | ||
addeddate: '1904-01-01T00:00:00Z', | ||
avg_rating: 3, | ||
issue: 'foo-issue', | ||
source: 'foo-source', | ||
date: '1904-01-01T00:00:00Z', | ||
reviewdate: '1904-01-01T00:00:00Z', | ||
publicdate: '2006-10-11T08:19:20Z', | ||
@@ -60,9 +96,9 @@ downloads: 1234, | ||
if (Array.isArray(json.fields[fieldName])) { | ||
expect((_a = hit[fieldName]) === null || _a === void 0 ? void 0 : _a.values).to.deep.equal(json.fields[fieldName]); | ||
expect((_a = hit[fieldName]) === null || _a === void 0 ? void 0 : _a.values).to.deep.equal(json.fields[fieldName], fieldName); | ||
} | ||
else if (hit[fieldName] instanceof DateField) { | ||
expect((_b = hit[fieldName]) === null || _b === void 0 ? void 0 : _b.value).to.deep.equal(DateParser.shared.parseValue(json.fields[fieldName].toString())); | ||
expect((_b = hit[fieldName]) === null || _b === void 0 ? void 0 : _b.value).to.deep.equal(DateParser.shared.parseValue(json.fields[fieldName].toString()), fieldName); | ||
} | ||
else { | ||
expect((_c = hit[fieldName]) === null || _c === void 0 ? void 0 : _c.value).to.equal(json.fields[fieldName]); | ||
expect((_c = hit[fieldName]) === null || _c === void 0 ? void 0 : _c.value).to.equal(json.fields[fieldName], fieldName); | ||
} | ||
@@ -72,3 +108,28 @@ } | ||
}); | ||
it('correctly parses falsey boolean/numeric fields', () => { | ||
var _a, _b, _c, _d, _e, _f; | ||
const json = { | ||
fields: { | ||
identifier: 'foo', | ||
result_in_subfile: false, | ||
file_creation_mtime: 0, | ||
page_num: 0, | ||
avg_rating: 0, | ||
downloads: 0, | ||
year: 0, | ||
}, | ||
highlight: { | ||
text: [], | ||
}, | ||
_score: 0, | ||
}; | ||
const hit = new TextHit(json); | ||
expect((_a = hit.result_in_subfile) === null || _a === void 0 ? void 0 : _a.value).to.be.false; | ||
expect((_b = hit.file_creation_mtime) === null || _b === void 0 ? void 0 : _b.value).to.equal(0); | ||
expect((_c = hit.page_num) === null || _c === void 0 ? void 0 : _c.value).to.equal(0); | ||
expect((_d = hit.avg_rating) === null || _d === void 0 ? void 0 : _d.value).to.equal(0); | ||
expect((_e = hit.downloads) === null || _e === void 0 ? void 0 : _e.value).to.equal(0); | ||
expect((_f = hit.year) === null || _f === void 0 ? void 0 : _f.value).to.equal(0); | ||
}); | ||
}); | ||
//# sourceMappingURL=text-hit.test.js.map |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect } from '@open-wc/testing'; | ||
@@ -57,20 +56,2 @@ import Sinon from 'sinon'; | ||
}); | ||
it('can enable debugging by default on all searches', async () => { | ||
const backend = new FulltextSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop' }); | ||
expect(urlCalled.toString()).to.equal('https://foo.bar/baz/?service_backend=fts&user_query=boop&debugging=true'); | ||
}); | ||
it('can disable default debugging on individual searches', async () => { | ||
const backend = new FulltextSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop', debugging: false }); | ||
expect(urlCalled.toString()).to.equal('https://foo.bar/baz/?service_backend=fts&user_query=boop'); | ||
}); | ||
}); | ||
@@ -97,5 +78,7 @@ it('returns a network error result upon fetch errors', async () => { | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
}, | ||
}, | ||
@@ -102,0 +85,0 @@ }, |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect } from '@open-wc/testing'; | ||
@@ -57,20 +56,2 @@ import Sinon from 'sinon'; | ||
}); | ||
it('can enable debugging by default on all searches', async () => { | ||
const backend = new MetadataSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop' }); | ||
expect(urlCalled.toString()).to.equal('https://foo.bar/baz/?service_backend=metadata&user_query=boop&debugging=true'); | ||
}); | ||
it('can disable default debugging on individual searches', async () => { | ||
const backend = new MetadataSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop', debugging: false }); | ||
expect(urlCalled.toString()).to.equal('https://foo.bar/baz/?service_backend=metadata&user_query=boop'); | ||
}); | ||
}); | ||
@@ -97,5 +78,7 @@ it('returns a network error result upon fetch errors', async () => { | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
}, | ||
}, | ||
@@ -102,0 +85,0 @@ }, |
@@ -183,14 +183,3 @@ import { expect } from '@open-wc/testing'; | ||
}); | ||
it('properly generates a URLSearchParam with debugging enabled', async () => { | ||
const query = 'title:foo'; | ||
const params = { | ||
query, | ||
debugging: true, | ||
}; | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams(params); | ||
const queryAsString = urlSearchParam.toString(); | ||
const expected = 'user_query=title%3Afoo&debugging=true'; | ||
expect(queryAsString).to.equal(expected); | ||
}); | ||
}); | ||
//# sourceMappingURL=search-params.test.js.map |
{ | ||
"name": "@internetarchive/search-service", | ||
"version": "0.4.1-alpha.2", | ||
"version": "0.4.1", | ||
"description": "A search service for the Internet Archive", | ||
@@ -26,3 +26,7 @@ "license": "AGPL-3.0-only", | ||
"test:watch": "web-test-runner --watch", | ||
"codecov": "npx codecov" | ||
"codecov": "npx codecov", | ||
"ghpages:build": "rimraf ghpages && npm run prepare && vite build", | ||
"ghpages:publish": "npm run ghpages:prepare -e $(git branch --show-current)", | ||
"ghpages:prepare": "npm run ghpages:build && touch ghpages/.nojekyll && npm run ghpages:generate", | ||
"ghpages:generate": "gh-pages -t -d ghpages -m \"Build for $(git log --pretty=format:\"%h %an %ai %s\" -n1) [skip ci]\"" | ||
}, | ||
@@ -45,6 +49,8 @@ "devDependencies": { | ||
"prettier": "^2.0.4", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^12.0.1", | ||
"tslib": "^1.14.1", | ||
"typedoc": "^0.20.29", | ||
"typescript": "^4.2.2" | ||
"typescript": "^4.2.2", | ||
"vite": "^2.9.13" | ||
}, | ||
@@ -51,0 +57,0 @@ "eslintConfig": { |
@@ -5,2 +5,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { BooleanField } from '../metadata-fields/field-types/boolean'; | ||
import { ByteField } from '../metadata-fields/field-types/byte'; | ||
import { DateField } from '../metadata-fields/field-types/date'; | ||
@@ -42,2 +43,16 @@ import { MediaTypeField } from '../metadata-fields/field-types/mediatype'; | ||
/** Optional. */ | ||
@Memoize() get addeddate(): typeof Metadata.prototype.addeddate { | ||
return this.rawMetadata?.fields?.addeddate | ||
? new DateField(this.rawMetadata.fields.addeddate) | ||
: undefined; | ||
} | ||
/** Optional. */ | ||
@Memoize() get avg_rating(): typeof Metadata.prototype.avg_rating { | ||
return this.rawMetadata?.fields?.avg_rating != null | ||
? new NumberField(this.rawMetadata.fields.avg_rating) | ||
: undefined; | ||
} | ||
/** | ||
@@ -58,3 +73,3 @@ * May be a superset of metadata collection field. | ||
@Memoize() get collection_files_count(): NumberField | undefined { | ||
return this.rawMetadata?.fields?.collection_files_count | ||
return this.rawMetadata?.fields?.collection_files_count != null | ||
? new NumberField(this.rawMetadata.fields.collection_files_count) | ||
@@ -69,4 +84,4 @@ : undefined; | ||
@Memoize() get collection_size(): typeof Metadata.prototype.collection_size { | ||
return this.rawMetadata?.fields?.collection_size | ||
? new NumberField(this.rawMetadata.fields.collection_size) | ||
return this.rawMetadata?.fields?.collection_size != null | ||
? new ByteField(this.rawMetadata.fields.collection_size) | ||
: undefined; | ||
@@ -106,3 +121,3 @@ } | ||
@Memoize() get downloads(): typeof Metadata.prototype.downloads { | ||
return this.rawMetadata?.fields?.downloads | ||
return this.rawMetadata?.fields?.downloads != null | ||
? new NumberField(this.rawMetadata.fields.downloads) | ||
@@ -116,3 +131,3 @@ : undefined; | ||
@Memoize() get files_count(): typeof Metadata.prototype.files_count { | ||
return this.rawMetadata?.fields?.files_count | ||
return this.rawMetadata?.fields?.files_count != null | ||
? new NumberField(this.rawMetadata.fields.files_count) | ||
@@ -143,7 +158,27 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
@Memoize() get issue(): typeof Metadata.prototype.issue { | ||
return this.rawMetadata?.fields?.issue | ||
? new StringField(this.rawMetadata.fields.issue) | ||
: undefined; | ||
} | ||
/** | ||
* Computed during document construction. | ||
* Optional. | ||
*/ | ||
@Memoize() get item_count(): typeof Metadata.prototype.item_count { | ||
return this.rawMetadata?.fields?.item_count != null | ||
? new NumberField(this.rawMetadata.fields.item_count) | ||
: undefined; | ||
} | ||
/** | ||
* In bytes; computed during document construction. | ||
*/ | ||
@Memoize() get item_size(): typeof Metadata.prototype.item_size { | ||
return this.rawMetadata?.fields?.item_size | ||
? new NumberField(this.rawMetadata.fields.item_size) | ||
return this.rawMetadata?.fields?.item_size != null | ||
? new ByteField(this.rawMetadata.fields.item_size) | ||
: undefined; | ||
@@ -222,3 +257,3 @@ } | ||
@Memoize() get month(): typeof Metadata.prototype.month { | ||
return this.rawMetadata?.fields?.month | ||
return this.rawMetadata?.fields?.month != null | ||
? new NumberField(this.rawMetadata.fields.month) | ||
@@ -240,3 +275,3 @@ : undefined; | ||
@Memoize() get num_favorites(): typeof Metadata.prototype.num_favorites { | ||
return this.rawMetadata?.fields?.num_favorites | ||
return this.rawMetadata?.fields?.num_favorites != null | ||
? new NumberField(this.rawMetadata.fields.num_favorites) | ||
@@ -251,3 +286,3 @@ : undefined; | ||
@Memoize() get num_reviews(): typeof Metadata.prototype.num_reviews { | ||
return this.rawMetadata?.fields?.num_reviews | ||
return this.rawMetadata?.fields?.num_reviews != null | ||
? new NumberField(this.rawMetadata.fields.num_reviews) | ||
@@ -258,3 +293,13 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
@Memoize() get source(): typeof Metadata.prototype.source { | ||
return this.rawMetadata?.fields?.source | ||
? new StringField(this.rawMetadata.fields.source) | ||
: undefined; | ||
} | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -294,3 +339,3 @@ */ | ||
@Memoize() get week(): typeof Metadata.prototype.week { | ||
return this.rawMetadata?.fields?.week | ||
return this.rawMetadata?.fields?.week != null | ||
? new NumberField(this.rawMetadata.fields.week) | ||
@@ -305,3 +350,3 @@ : undefined; | ||
@Memoize() get year(): NumberField | undefined { | ||
return this.rawMetadata?.fields?.year | ||
return this.rawMetadata?.fields?.year != null | ||
? new NumberField(this.rawMetadata.fields.year) | ||
@@ -308,0 +353,0 @@ : undefined; |
@@ -52,2 +52,19 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/** | ||
* May be stale in FTS. | ||
* Optional. | ||
*/ | ||
@Memoize() get addeddate(): typeof Metadata.prototype.addeddate { | ||
return this.rawMetadata?.fields?.addeddate | ||
? new DateField(this.rawMetadata.fields.addeddate) | ||
: undefined; | ||
} | ||
/** Optional. */ | ||
@Memoize() get avg_rating(): typeof Metadata.prototype.avg_rating { | ||
return this.rawMetadata?.fields?.avg_rating != null | ||
? new NumberField(this.rawMetadata.fields.avg_rating) | ||
: undefined; | ||
} | ||
/** Multivalued. */ | ||
@@ -99,3 +116,3 @@ @Memoize() get collection(): typeof Metadata.prototype.collection { | ||
@Memoize() get downloads(): typeof Metadata.prototype.downloads { | ||
return this.rawMetadata?.fields?.downloads | ||
return this.rawMetadata?.fields?.downloads != null | ||
? new NumberField(this.rawMetadata.fields.downloads) | ||
@@ -118,3 +135,3 @@ : undefined; | ||
@Memoize() get file_creation_mtime(): NumberField | undefined { | ||
return this.rawMetadata?.fields?.file_creation_mtime | ||
return this.rawMetadata?.fields?.file_creation_mtime != null | ||
? new NumberField(this.rawMetadata.fields.file_creation_mtime) | ||
@@ -124,2 +141,12 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
@Memoize() get issue(): typeof Metadata.prototype.issue { | ||
return this.rawMetadata?.fields?.issue | ||
? new StringField(this.rawMetadata.fields.issue) | ||
: undefined; | ||
} | ||
@Memoize() get mediatype(): typeof Metadata.prototype.mediatype { | ||
@@ -133,3 +160,3 @@ return this.rawMetadata?.fields?.mediatype | ||
@Memoize() get page_num(): NumberField | undefined { | ||
return this.rawMetadata?.fields?.page_num | ||
return this.rawMetadata?.fields?.page_num != null | ||
? new NumberField(this.rawMetadata.fields.page_num) | ||
@@ -163,3 +190,13 @@ : undefined; | ||
/** | ||
* Format varies. | ||
* Optional. | ||
*/ | ||
@Memoize() get source(): typeof Metadata.prototype.source { | ||
return this.rawMetadata?.fields?.source | ||
? new StringField(this.rawMetadata.fields.source) | ||
: undefined; | ||
} | ||
/** | ||
* Optional. | ||
* Multivalued. | ||
@@ -191,3 +228,3 @@ */ | ||
@Memoize() get year(): NumberField | undefined { | ||
return this.rawMetadata?.fields?.year | ||
return this.rawMetadata?.fields?.year != null | ||
? new NumberField(this.rawMetadata.fields.year) | ||
@@ -194,0 +231,0 @@ : undefined; |
@@ -25,7 +25,4 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
protected debuggingEnabled?: boolean; | ||
constructor(options?: SearchBackendOptionsInterface) { | ||
this.baseUrl = options?.baseUrl ?? 'archive.org'; | ||
this.debuggingEnabled = options?.debuggingEnabled ?? false; | ||
@@ -140,3 +137,3 @@ if (options?.includeCredentials !== undefined) { | ||
private printDebuggingInfo(json: Record<string, any>) { | ||
const debugInfo = json.debugging; | ||
const debugInfo = json.debugging?.debugging; // PPS debugging info is doubly-nested, not sure why | ||
const messages = debugInfo?.messages ?? []; | ||
@@ -143,0 +140,0 @@ const data = debugInfo?.data ?? {}; |
@@ -15,3 +15,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
constructor(options?: SearchBackendOptionsInterface) { | ||
constructor( | ||
options?: SearchBackendOptionsInterface & { | ||
servicePath?: string; | ||
} | ||
) { | ||
super(options); | ||
@@ -26,6 +30,2 @@ this.servicePath = | ||
): Promise<Result<any, SearchServiceError>> { | ||
if (this.debuggingEnabled && params.debugging == null) { | ||
params.debugging = true; | ||
} | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams( | ||
@@ -32,0 +32,0 @@ params |
@@ -15,3 +15,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
constructor(options?: SearchBackendOptionsInterface) { | ||
constructor( | ||
options?: SearchBackendOptionsInterface & { | ||
servicePath?: string; | ||
} | ||
) { | ||
super(options); | ||
@@ -26,6 +30,2 @@ this.servicePath = | ||
): Promise<Result<any, SearchServiceError>> { | ||
if (this.debuggingEnabled && params.debugging == null) { | ||
params.debugging = true; | ||
} | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams( | ||
@@ -32,0 +32,0 @@ params |
@@ -10,6 +10,4 @@ /** | ||
baseUrl?: string; | ||
servicePath?: string; | ||
includeCredentials?: boolean; | ||
scope?: string; | ||
debuggingEnabled?: boolean; | ||
} |
@@ -6,2 +6,39 @@ import { DateParser } from '@internetarchive/field-parsers'; | ||
const fieldNames: (keyof ItemHit)[] = [ | ||
'identifier', | ||
'addeddate', | ||
'avg_rating', | ||
'collection', | ||
'collection_files_count', | ||
'collection_size', | ||
'creator', | ||
'date', | ||
'description', | ||
'downloads', | ||
'files_count', | ||
'genre', | ||
'indexflag', | ||
'issue', | ||
'item_count', | ||
'item_size', | ||
'lending___available_to_borrow', | ||
'lending___available_to_browse', | ||
'lending___available_to_waitlist', | ||
'lending___status', | ||
'language', | ||
'licenseurl', | ||
'mediatype', | ||
'month', | ||
'noindex', | ||
'num_favorites', | ||
'num_reviews', | ||
'source', | ||
'subject', | ||
'title', | ||
'type', | ||
'volume', | ||
'week', | ||
'year', | ||
]; | ||
describe('ItemHit', () => { | ||
@@ -20,11 +57,16 @@ it('constructs basic item hit', () => { | ||
it('handles incomplete data without throwing', () => { | ||
it('handles missing data gracefully', () => { | ||
const hit = new ItemHit({}); | ||
expect(hit.creator).to.be.undefined; | ||
expect(hit.date).to.be.undefined; | ||
expect(hit.description).to.be.undefined; | ||
expect(hit.subject).to.be.undefined; | ||
expect(hit.title).to.be.undefined; | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('handles incomplete field data gracefully', () => { | ||
const hit = new ItemHit({ fields: {} }); | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('constructs item hit with partial fields', () => { | ||
@@ -76,4 +118,8 @@ const json = { | ||
expect(hit.addeddate?.value).to.be.undefined; | ||
expect(hit.avg_rating?.value).to.be.undefined; | ||
expect(hit.collection_files_count?.value).to.be.undefined; | ||
expect(hit.collection_size?.value).to.be.undefined; | ||
expect(hit.issue?.value).to.be.undefined; | ||
expect(hit.item_count?.value).to.be.undefined; | ||
expect(hit.genre?.value).to.be.undefined; | ||
@@ -86,2 +132,3 @@ expect(hit.language?.value).to.be.undefined; | ||
expect(hit.num_reviews?.value).to.be.undefined; | ||
expect(hit.source?.value).to.be.undefined; | ||
expect(hit.type?.value).to.be.undefined; | ||
@@ -107,3 +154,3 @@ expect(hit.volume?.value).to.be.undefined; | ||
week: 2, | ||
month: 15, | ||
month: 11, | ||
indexflag: ['index', 'nonoindex'], | ||
@@ -114,5 +161,9 @@ lending___available_to_borrow: false, | ||
lending___status: 'foo-status', | ||
addeddate: '2011-07-20T00:00:00Z', | ||
avg_rating: 3, | ||
collection_files_count: 124, | ||
collection_size: 125, | ||
genre: 'foo-genre', | ||
issue: 'foo-issue', | ||
item_count: 0, | ||
language: 'foo-language', | ||
@@ -123,2 +174,3 @@ licenseurl: 'foo-license', | ||
num_reviews: 127, | ||
source: 'foo-source', | ||
type: 'foo-type', | ||
@@ -141,12 +193,63 @@ volume: 'foo-volume', | ||
if (Array.isArray(json.fields[fieldName])) { | ||
expect(hit[fieldName]?.values).to.deep.equal(json.fields[fieldName]); | ||
expect(hit[fieldName]?.values).to.deep.equal( | ||
json.fields[fieldName], | ||
fieldName | ||
); | ||
} else if (hit[fieldName] instanceof DateField) { | ||
expect(hit[fieldName]?.value).to.deep.equal( | ||
DateParser.shared.parseValue(json.fields[fieldName].toString()) | ||
DateParser.shared.parseValue(json.fields[fieldName].toString()), | ||
fieldName | ||
); | ||
} else { | ||
expect(hit[fieldName]?.value).to.equal(json.fields[fieldName]); | ||
expect(hit[fieldName]?.value).to.equal( | ||
json.fields[fieldName], | ||
fieldName | ||
); | ||
} | ||
} | ||
}); | ||
it('correctly parses falsey boolean/numeric fields', () => { | ||
const json = { | ||
fields: { | ||
identifier: 'foo', | ||
lending___available_to_borrow: false, | ||
lending___available_to_browse: false, | ||
lending___available_to_waitlist: false, | ||
noindex: false, | ||
item_size: 0, | ||
files_count: 0, | ||
downloads: 0, | ||
week: 0, | ||
month: 0, | ||
year: 0, | ||
avg_rating: 0, | ||
collection_files_count: 0, | ||
collection_size: 0, | ||
item_count: 0, | ||
num_favorites: 0, | ||
num_reviews: 0, | ||
}, | ||
highlight: null, | ||
_score: 0, | ||
}; | ||
const hit = new ItemHit(json); | ||
expect(hit.lending___available_to_borrow?.value).to.be.false; | ||
expect(hit.lending___available_to_browse?.value).to.be.false; | ||
expect(hit.lending___available_to_waitlist?.value).to.be.false; | ||
expect(hit.noindex?.value).to.be.false; | ||
expect(hit.item_size?.value).to.equal(0); | ||
expect(hit.files_count?.value).to.equal(0); | ||
expect(hit.downloads?.value).to.equal(0); | ||
expect(hit.week?.value).to.equal(0); | ||
expect(hit.month?.value).to.equal(0); | ||
expect(hit.year?.value).to.equal(0); | ||
expect(hit.avg_rating?.value).to.equal(0); | ||
expect(hit.collection_files_count?.value).to.equal(0); | ||
expect(hit.collection_size?.value).to.equal(0); | ||
expect(hit.item_count?.value).to.equal(0); | ||
expect(hit.num_favorites?.value).to.equal(0); | ||
expect(hit.num_reviews?.value).to.equal(0); | ||
}); | ||
}); |
@@ -6,2 +6,30 @@ import { DateParser } from '@internetarchive/field-parsers'; | ||
const fieldNames: (keyof TextHit)[] = [ | ||
'identifier', | ||
'addeddate', | ||
'avg_rating', | ||
'collection', | ||
'created_on', | ||
'creator', | ||
'date', | ||
'description', | ||
'downloads', | ||
'filename', | ||
'file_basename', | ||
'file_creation_mtime', | ||
'highlight', | ||
'issue', | ||
'mediatype', | ||
'page_num', | ||
'publicdate', | ||
'result_in_subfile', | ||
'reviewdate', | ||
'source', | ||
'subject', | ||
'title', | ||
'updated_on', | ||
'year', | ||
'__href__', | ||
]; | ||
describe('TextHit', () => { | ||
@@ -14,11 +42,16 @@ it('constructs basic text hit', () => { | ||
it('handles incomplete data without throwing', () => { | ||
it('handles missing data gracefully', () => { | ||
const hit = new TextHit({}); | ||
expect(hit.creator).to.be.undefined; | ||
expect(hit.date).to.be.undefined; | ||
expect(hit.description).to.be.undefined; | ||
expect(hit.subject).to.be.undefined; | ||
expect(hit.title).to.be.undefined; | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('handles incomplete field data gracefully', () => { | ||
const hit = new TextHit({ fields: {} }); | ||
for (const key of fieldNames) { | ||
expect(hit[key]).to.be.undefined; | ||
} | ||
}); | ||
it('constructs text hit with all fields', () => { | ||
@@ -38,3 +71,8 @@ const json = { | ||
subject: ['foo-subject1', 'foo-subject2'], | ||
addeddate: '1904-01-01T00:00:00Z', | ||
avg_rating: 3, | ||
issue: 'foo-issue', | ||
source: 'foo-source', | ||
date: '1904-01-01T00:00:00Z', | ||
reviewdate: '1904-01-01T00:00:00Z', | ||
publicdate: '2006-10-11T08:19:20Z', | ||
@@ -64,9 +102,16 @@ downloads: 1234, | ||
if (Array.isArray(json.fields[fieldName])) { | ||
expect(hit[fieldName]?.values).to.deep.equal(json.fields[fieldName]); | ||
expect(hit[fieldName]?.values).to.deep.equal( | ||
json.fields[fieldName], | ||
fieldName | ||
); | ||
} else if (hit[fieldName] instanceof DateField) { | ||
expect(hit[fieldName]?.value).to.deep.equal( | ||
DateParser.shared.parseValue(json.fields[fieldName].toString()) | ||
DateParser.shared.parseValue(json.fields[fieldName].toString()), | ||
fieldName | ||
); | ||
} else { | ||
expect(hit[fieldName]?.value).to.equal(json.fields[fieldName]); | ||
expect(hit[fieldName]?.value).to.equal( | ||
json.fields[fieldName], | ||
fieldName | ||
); | ||
} | ||
@@ -77,2 +122,28 @@ } | ||
}); | ||
it('correctly parses falsey boolean/numeric fields', () => { | ||
const json = { | ||
fields: { | ||
identifier: 'foo', | ||
result_in_subfile: false, | ||
file_creation_mtime: 0, | ||
page_num: 0, | ||
avg_rating: 0, | ||
downloads: 0, | ||
year: 0, | ||
}, | ||
highlight: { | ||
text: [], | ||
}, | ||
_score: 0, | ||
}; | ||
const hit = new TextHit(json); | ||
expect(hit.result_in_subfile?.value).to.be.false; | ||
expect(hit.file_creation_mtime?.value).to.equal(0); | ||
expect(hit.page_num?.value).to.equal(0); | ||
expect(hit.avg_rating?.value).to.equal(0); | ||
expect(hit.downloads?.value).to.equal(0); | ||
expect(hit.year?.value).to.equal(0); | ||
}); | ||
}); |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect } from '@open-wc/testing'; | ||
@@ -77,28 +76,2 @@ import Sinon from 'sinon'; | ||
}); | ||
it('can enable debugging by default on all searches', async () => { | ||
const backend = new FulltextSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop' }); | ||
expect(urlCalled!.toString()).to.equal( | ||
'https://foo.bar/baz/?service_backend=fts&user_query=boop&debugging=true' | ||
); | ||
}); | ||
it('can disable default debugging on individual searches', async () => { | ||
const backend = new FulltextSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop', debugging: false }); | ||
expect(urlCalled!.toString()).to.equal( | ||
'https://foo.bar/baz/?service_backend=fts&user_query=boop' | ||
); | ||
}); | ||
}); | ||
@@ -129,5 +102,7 @@ | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
}, | ||
}, | ||
@@ -134,0 +109,0 @@ }, |
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { expect } from '@open-wc/testing'; | ||
@@ -77,28 +76,2 @@ import Sinon from 'sinon'; | ||
}); | ||
it('can enable debugging by default on all searches', async () => { | ||
const backend = new MetadataSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop' }); | ||
expect(urlCalled!.toString()).to.equal( | ||
'https://foo.bar/baz/?service_backend=metadata&user_query=boop&debugging=true' | ||
); | ||
}); | ||
it('can disable default debugging on individual searches', async () => { | ||
const backend = new MetadataSearchBackend({ | ||
baseUrl: 'foo.bar', | ||
servicePath: '/baz', | ||
debuggingEnabled: true, | ||
}); | ||
await backend.performSearch({ query: 'boop', debugging: false }); | ||
expect(urlCalled!.toString()).to.equal( | ||
'https://foo.bar/baz/?service_backend=metadata&user_query=boop' | ||
); | ||
}); | ||
}); | ||
@@ -129,5 +102,7 @@ | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
debugging: { | ||
messages: ['boop'], | ||
data: { | ||
bar: 'baz', | ||
}, | ||
}, | ||
@@ -134,0 +109,0 @@ }, |
@@ -230,16 +230,2 @@ import { expect } from '@open-wc/testing'; | ||
}); | ||
it('properly generates a URLSearchParam with debugging enabled', async () => { | ||
const query = 'title:foo'; | ||
const params = { | ||
query, | ||
debugging: true, | ||
}; | ||
const urlSearchParam = SearchParamURLGenerator.generateURLSearchParams( | ||
params | ||
); | ||
const queryAsString = urlSearchParam.toString(); | ||
const expected = 'user_query=title%3Afoo&debugging=true'; | ||
expect(queryAsString).to.equal(expected); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
627638
226
9002
21