overleaf/services/web/frontend/js/services/algolia-search.js
Jessica Lawshe c34d5997e9 Merge pull request #4157 from overleaf/jel-gallery-search-via-algolia
Add gallery search via Algolia

GitOrigin-RevId: 82f306154c990e5ba047b7a7ab9e98f193995ede
2021-06-17 02:09:33 +00:00

20 lines
553 B
JavaScript

import _ from 'lodash'
import App from '../base'
import AlgoliaSearch from 'algoliasearch'
import getMeta from '../utils/meta'
export default App.factory('algoliaSearch', function () {
let wikiIdx
const algoliaConfig = getMeta('ol-algolia')
const wikiIndex = _.get(algoliaConfig, 'indexes.wiki')
if (wikiIndex) {
const client = AlgoliaSearch(algoliaConfig.appId, algoliaConfig.apiKey)
wikiIdx = client.initIndex(wikiIndex)
}
const service = {
searchWiki: wikiIdx ? wikiIdx.search.bind(wikiIdx) : null,
}
return service
})