1
0
mirror of synced 2025-12-26 05:02:55 -05:00
Files
docs/lib/search/algolia-search.js
Kevin Heis c51f5390d4 Move search results to use relative urls (#17411)
* Move search results to use relative urls

* ..and now we have real mark tags instead of em tags

Co-authored-by: Chiedo John <2156688+chiedo@users.noreply.github.com>
2021-01-21 17:23:16 +00:00

30 lines
1.1 KiB
JavaScript

const algoliasearch = require('algoliasearch')
const { get } = require('lodash')
const { namePrefix } = require('./config')
// https://www.algolia.com/apps/ZI5KPY1HBE/dashboard
// This API key is public. There's also a private API key for writing to the Algolia API
const searchClient = algoliasearch('ZI5KPY1HBE', '685df617246c3a10abba589b4599288f')
module.exports = async function loadAlgoliaResults ({ version, language, query, limit }) {
const indexName = `${namePrefix}-${version}-${language}`
const index = searchClient.initIndex(indexName)
// allows "phrase queries" and "prohibit operator"
// https://www.algolia.com/doc/api-reference/api-parameters/advancedSyntax/
const { hits } = await index.search(query, {
hitsPerPage: limit,
advancedSyntax: true,
highlightPreTag: '<mark>',
highlightPostTag: '</mark>'
})
return hits.map(hit => ({
url: hit.objectID,
breadcrumbs: get(hit, '_highlightResult.breadcrumbs.value'),
heading: get(hit, '_highlightResult.heading.value'),
title: get(hit, '_highlightResult.title.value'),
content: get(hit, '_highlightResult.content.value')
}))
}