Constructor
new OpenSearchService()
Constructs a service for interacting with OpenSearch servers.
Members
descriptionDocument :OpenSearchDescriptionDocument
The latest parsed OpenSearch description document.
Type:
parserRegistry :OpenSearchParserRegistry
A registry of parsers (Atom, GeoJSON) to be used by this service.
Type:
rawDescriptionDocument :XmlDocument
The latest OpenSearch description document in the raw xml form.
Type:
- XmlDocument
url :String
URL of the OpenSearch description document.
Type:
- String
Methods
(static) create(options) → {Promise}
Fetches and parses an OpenSearch description document.
Parameters:
Name | Type | Description |
---|---|---|
options |
OpenSearchRequest | See OpenSearchRequest for possible options. A url is required. |
Returns:
A promise which when resolved returns this service, or an error when rejected
- Type
- Promise
Example
openSearchService
.discover({url: 'http://example.com/opensearch'})
.then(result => console.log(result))
.catch(err => console.error(err));
findUrl(predicate, context) → {OpenSearchUrl|undefined}
Finds an URL that satisfies the provided predicate function.
Parameters:
Name | Type | Description |
---|---|---|
predicate |
function | Function to execute on each value in the description document URLs array, taking three arguments: element The current element being processed in the array. index The index of the current element being processed in the array. array The array find was called upon. |
context |
Object | null | Object to use as "this" when executing the predicate function. |
Returns:
The first URL in the array that satisfies the provided predicate
function. Otherwise, undefined is returned.
- Type
- OpenSearchUrl | undefined
getParser(type, rel) → {Object|undefined}
Returns the response parser for the specified mime type and relation.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Mime type of the parser. |
rel |
String | Relation type of the parser. |
Returns:
The response parser.
- Type
- Object | undefined
getSupportedFormats() → {Array.<String>}
Returns the list of supported mime types.
Returns:
The list of supported mime types.
- Type
- Array.<String>
registerDefaultParsers()
Internal. Applications should not call this function.
Registers the default parsers for an OpenSearchService.
registerParser(type, rel, parser)
Registers a parser for the specified mime type and relation.
The parse method of the parser will be called with the response of the server when the mime type and
relation type matches.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Mime type of the parser to register. |
rel |
String | Relation type of the parser to register. |
parser |
Object | An object with a parse method. |
removeParser(type, rel)
Removes the response parser for the specified mime type and relation.
Parameters:
Name | Type | Description |
---|---|---|
type |
String | Mime type of the registered parser. |
rel |
String | Relation type of the registered parser. |
search(searchParams, options) → {Promise}
Performs a search query.
Parameters:
Name | Type | Description |
---|---|---|
searchParams |
Array | null | A list of objects, each object must have a name and value property. |
options |
OpenSearchRequest | null | See OpenSearchRequest for possible options. |
Returns:
A promise which when resolved returns a GeoJSON collection, or an error when rejected.
- Type
- Promise
Example
openSearchService
.search([
{name: 'count', value: 10}, {name: 'lat', value: 50}, {name: 'lon', value: 20}
])
.then(result => console.log(result))
.catch(err => console.error(err));