mirror of
https://github.com/sakaljurgis/kobo.git
synced 2026-07-08 22:17:42 +00:00
add meili
This commit is contained in:
@@ -27,3 +27,9 @@ services:
|
||||
ports:
|
||||
- 9200:9200
|
||||
# - 9300:9300
|
||||
meilisearch:
|
||||
image: getmeili/meilisearch:latest
|
||||
environment:
|
||||
- MEILI_NO_ANALYTICS=true
|
||||
ports:
|
||||
- 7700:7700
|
||||
|
||||
Generated
+36
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "app",
|
||||
"name": "kobo",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
@@ -12,6 +12,7 @@
|
||||
"express-handlebars": "^7.1.2",
|
||||
"fs-promise": "^0.3.1",
|
||||
"jszip": "^2.5.0",
|
||||
"meilisearch": "^0.40.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"xml-mapping": "^1.7.0"
|
||||
},
|
||||
@@ -3248,6 +3249,22 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/meilisearch": {
|
||||
"version": "0.40.0",
|
||||
"resolved": "https://registry.npmjs.org/meilisearch/-/meilisearch-0.40.0.tgz",
|
||||
"integrity": "sha512-BoRhQMr2mBFLEeCfsvPluksGb01IaOiWvV3Deu3iEY+yYJ4jdGTu+IQi5FCjKlNQ7/TMWSN2XUToSgvH1tj0BQ==",
|
||||
"dependencies": {
|
||||
"cross-fetch": "^3.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/meilisearch/node_modules/cross-fetch": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz",
|
||||
"integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.12"
|
||||
}
|
||||
},
|
||||
"node_modules/meow": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz",
|
||||
@@ -7551,6 +7568,24 @@
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ=="
|
||||
},
|
||||
"meilisearch": {
|
||||
"version": "0.40.0",
|
||||
"resolved": "https://registry.npmjs.org/meilisearch/-/meilisearch-0.40.0.tgz",
|
||||
"integrity": "sha512-BoRhQMr2mBFLEeCfsvPluksGb01IaOiWvV3Deu3iEY+yYJ4jdGTu+IQi5FCjKlNQ7/TMWSN2XUToSgvH1tj0BQ==",
|
||||
"requires": {
|
||||
"cross-fetch": "^3.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"cross-fetch": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz",
|
||||
"integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==",
|
||||
"requires": {
|
||||
"node-fetch": "^2.6.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"meow": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"express-handlebars": "^7.1.2",
|
||||
"fs-promise": "^0.3.1",
|
||||
"jszip": "^2.5.0",
|
||||
"meilisearch": "^0.40.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"xml-mapping": "^1.7.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Client, errors } from '@elastic/elasticsearch';
|
||||
import { meiliSearch } from '../meili';
|
||||
|
||||
interface DataType {
|
||||
export interface DataType {
|
||||
path: string;
|
||||
title: string;
|
||||
creator: string;
|
||||
@@ -65,6 +66,7 @@ export class ElasticSearch {
|
||||
};
|
||||
|
||||
async addDocument(payload: DataType) {
|
||||
meiliSearch.addDocument(payload).then();
|
||||
return this.client.index({
|
||||
index: this.indexName,
|
||||
id: payload.path,
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { MeiliSearch as MS } from 'meilisearch'
|
||||
import { DataType } from '../elasticsearch';
|
||||
|
||||
class MeiliSearch {
|
||||
private readonly client: MS
|
||||
|
||||
constructor() {
|
||||
this.client = new MS({
|
||||
host: process.env.MEILI_HOST || 'http://localhost:7700',
|
||||
});
|
||||
}
|
||||
|
||||
async createIndex() {
|
||||
//todo add searchable and filterable fields
|
||||
let index = null;
|
||||
try {
|
||||
index = await this.client.getIndex('books')
|
||||
console.log('index found');
|
||||
} catch (e) {
|
||||
console.log('index not found');
|
||||
index = await this.client.createIndex('books')
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
async addDocument(document: DataType) {
|
||||
return this.client.index('books').addDocuments([document]);
|
||||
}
|
||||
}
|
||||
|
||||
export const meiliSearch = new MeiliSearch();
|
||||
|
||||
meiliSearch.createIndex();
|
||||
Reference in New Issue
Block a user