overleaf/services/web/frontend/js/features/algolia-search/search-wiki.js
Jakob Ackermann 7919017118 Merge pull request #4956 from overleaf/jpa-jk-contact-form-de-ng
[web] de-ng contact form

GitOrigin-RevId: 8a92b37163555d6466e4b8c565f1ef490f73d49a
2021-09-09 08:03:07 +00:00

19 lines
543 B
JavaScript

import _ from 'lodash'
import AlgoliaSearch from 'algoliasearch'
import getMeta from '../../utils/meta'
let wikiIdx
export async function searchWiki(...args) {
if (!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)
}
}
if (!wikiIdx) {
return { hits: [], nbHits: 0, nbPages: 0 }
}
return wikiIdx.search(...args)
}