Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

search.js 1.1 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  1. const express = require('express')
  2. const languages = new Set(Object.keys(require('../lib/languages')))
  3. const versions = new Set(Object.values(require('../lib/search/versions')))
  4. const loadLunrResults = require('../lib/search/lunr-search')
  5. const loadAlgoliaResults = require('../lib/search/algolia-search')
  6. const router = express.Router()
  7. router.get('/', async (req, res) => {
  8. res.set({
  9. 'surrogate-control': 'private, no-store',
  10. 'cache-control': 'private, no-store'
  11. })
  12. const { query, version, language, limit: limit_ } = req.query
  13. const limit = Math.min(parseInt(limit_, 10) || 10, 100)
  14. if (!versions.has(version) || !languages.has(language)) {
  15. return res.status(400).json([])
  16. }
  17. if (!query || !limit) {
  18. return res.status(200).json([])
  19. }
  20. try {
  21. const results = process.env.AIRGAP
  22. ? await loadLunrResults({ version, language, query, limit })
  23. : await loadAlgoliaResults({ version, language, query, limit })
  24. return res.status(200).json(results)
  25. } catch (err) {
  26. console.error(err)
  27. return res.status(400).json([])
  28. }
  29. })
  30. module.exports = router
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...