Class: OpenLibraryAutocompleteAdapter

OpenLibraryAutocompleteAdapter()

Perform book metadata lookups on openlibrary.org. Like other frontend adapters, it is shallow and does not care for language, authorship, or other details.

Constructor

new OpenLibraryAutocompleteAdapter()

See AbstractAutocompleteAdapter for parameter documentation, not shown here due to jsdoc bug.

Source:

Extends

Members

ac :AC

After AbstractAutocompleteAdapter#setupAutocomplete is run, holds a reference to the autocomplete widget used by this instance.

Type:
  • AC
Overrides:
Source:

acCSSPrefix :String

CSS prefix for the autocomplete widget.

Type:
  • String
Overrides:
Source:

acDelay :Number

Delay in milliseconds before performing a search.

Type:
  • Number
Overrides:
Source:

acPrimaryTextKey :String

Key (into the row objects retrieved via the request handler) that determines which value is used as the main text in the autocomplete widget.

'label' corresponds to what the main application expects, but if you want to show something different than what gets passed to the application, you may want to change it.

Type:
  • String
Overrides:
Source:

acSecondaryTextKey :String

Default row key for the optional secondary, smaller text shown in the autocomplete widget below each result.

Type:
  • String
Overrides:
Source:

limit :Number

How many results to get per query. This is pretty low since a result takes up a fair amount of space in the UI, esp. on mobile.

Type:
  • Number
Source:

sourceID :String

Canonical identifier for this source. Lower-case string, no whitespace.

Type:
  • String
Overrides:
Source:

supportedPattern :RegExp

RegExp for URLs this adapter can handle.

Type:
  • RegExp
Overrides:
Source:

Methods

_renderNoResultsHandler()

Render "No search results" text row at the bottom with default styles.

This:
Overrides:
Source:

_renderRowHandler(row) → {Element}

Render callback for the autocomplete widget. For each result, we show authorship and edition information, which goes a bit beyond what we could cram into the default rendering.

This:
Parameters:
Name Type Description
row Object

row data object as obtained via OpenLibraryAutocompleteAdapter#_requestHandler

Overrides:
Source:
Returns:

the element to insert into the DOM for this row

Type
Element

_requestHandler(query)

Query the Open Library's main search endpoint for this search string, store the results in the instance of the autocomplete widget, and render them.

Fires off two requests per query to perform both a stemmed search and a wildcard search. Optionally also supports author searches if split off from main query string with ";".

This:
Parameters:
Name Type Description
query String

the unescaped query string

Overrides:
Source:

_selectRowHandler(row, event)

Pass along row data we can handle to the main application. Will also query lib.reviews itself (through the native adapter) for the URL, so we can give preferential treatment to an existing native record for the review subject.

This:
Parameters:
Name Type Description
row Object

row data object. All properties except "url" are only used for display purposes, since the server performs its own lookup on the URL.

Properties
Name Type Attributes Description
url String

the URL for this review subject

label String

the main name shown for this review subject

subtitle String <optional>

shown as secondary title for the subject

description String <optional>

shown as short description below label and subtitle

event Event

the click or keyboard event which triggered this row selection.

Overrides:
Source:

ask(url) → {Boolean}

Does this adapter support the given URL? By default, performs a simple regex check.

Parameters:
Name Type Description
url String

the URL to test

Overrides:
Source:
Returns:

true if supported

Type
Boolean

disableSpinner()

Hide activity indicator in the input widget. Must be called in handler code via this.adapter.

Overrides:
Source:

enableSpinner()

Show activity indicator in the input widget. Must be called in handler code via this.adapter.

Overrides:
Source:

getSourceID() → {String}

Return the canonical source identifier for this adapter

Overrides:
Source:
Returns:
Type
String

lookup(url) → {Promise}

Obtain data from Open Library for a given URL.

Parameters:
Name Type Description
url String

URL to an Open Library book or work

Overrides:
Source:
Returns:

resolves to a LookupResult if successful, rejects with an error if not

Type
Promise

mergeResults(results) → {array}

Merge results from two Open Library search queries into a single array. The overall size will not exceed this.limit.

Parameters:
Name Type Description
results array

set of results from two or more search queries

Source:
Returns:

de-duplicated result array

Type
array

removeAutocomplete()

Remove the autocomplete widget including all its event listeners.

Overrides:
Source:

runAutocomplete()

Run the autocomplete widget on the current input.

Overrides:
Source:

setupAutocomplete()

Initialize the autocomplete widget. You can add additional callbacks / custom properties in the inherited class; just remember to call super.setupAutocomplete() first.

Overrides:
Source:

sortMatches(docs, query)

Perform an in-place sort on results from a search query, putting any exact matches against the query first

Parameters:
Name Type Description
docs Array

"docs" array from the Open Library JSON search API

query String

original query text that yielded this result

Source: