-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 1.07 KB
/
index.js
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
const algoliasearch = require('algoliasearch');
const client = algoliasearch('W69XAGVDFM', 'ee09f84e8fc1021b9336fd5d5e6d246c')
const ALGOLIA_INDEX_NAME = 'documents'
const index = client.initIndex(ALGOLIA_INDEX_NAME)
const moment = require('moment')
moment.locale('tr')
index.searchCacheEnabled = true
index.searchCacheExpiringTimeInterval = 300
module.exports = options => {
return new Promise((resolve, reject) => {
index.search(options, (err, content) => {
if (err) {
reject(err)
}
let response = content.hits.map(content => ({
title: content.title,
displayName: content.displayName,
thumbnail: content.thumbnail.url,
date: moment(content.date).fromNow(),
url: `https://ders.im/dokuman/${content.slug}`,
publisher: `https://ders.im/@${content.userSlug}`,
keywords: content.keywords || '',
deepLink: {
document: `dersim://dersim/document/${content.slug}`,
publisher: `dersim://dersim/user/${content.userSlug}`,
},
}))
resolve(response)
});
});
}