Constructor
new OpenLibraryAutocompleteAdapter()
See AbstractAutocompleteAdapter for parameter documentation, not shown here due to jsdoc bug.
Extends
- AbstractAutocompleteAdapter
Members
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
Methods
_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:
- OpenLibraryAutocompleteAdapter#ac
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Object | row data object as obtained via OpenLibraryAutocompleteAdapter#_requestHandler |
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:
- OpenLibraryAutocompleteAdapter#ac
Parameters:
| Name | Type | Description |
|---|---|---|
query |
String | the unescaped query 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 |
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 |
Returns:
de-duplicated result array
- Type
- array
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 |