| 3 | import config from 'ember-api-docs/config/environment'; |
| 4 | |
| 5 | export default class AlgoliaService extends Service { |
| 6 | async search(query, params) { |
| 7 | if (query) { |
| 8 | if (Array.isArray(query) && !params) { |
| 9 | // if multiple indices |
| 10 | return this._client.search(query); |
| 11 | } else if (!params) { |
| 12 | // if no params |
| 13 | return this.accessIndex(query.indexName).search(query.query); |
| 14 | } else { |
| 15 | // if params and callback |
| 16 | return this.accessIndex(query.indexName).search(query.query, params); |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | accessIndex(IndexName) { |
| 22 | if (!this._indices[IndexName]) { |
| 23 | this._indices[IndexName] = this._client.initIndex(IndexName); |
| 24 | } |
| 25 | return this._indices[IndexName]; |
| 26 | } |
| 27 | |
| 28 | constructor() { |
| 29 | super(...arguments); |
| 30 | this._client = algoliasearch( |
| 31 | config.algolia.algoliaId, |
| 32 | config.algolia.algoliaKey, |
| 33 | ); |
| 34 | this._indices = {}; |
| 35 | } |
| 36 | } |
nothing calls this directly
no outgoing calls
no test coverage detected