This commit is contained in:
2025-08-09 23:09:01 +08:00
parent 1898376161
commit c9e4358bd8
10 changed files with 4582 additions and 17 deletions

11
test/common.ts Normal file
View File

@@ -0,0 +1,11 @@
import dotenv from 'dotenv';
import { MeiliSearch } from 'meilisearch';
dotenv.config();
const meiliSearchKey = process.env.MEILISEARCH_KEY;
const host = process.env.MEILISEARCH_URL!;
export const client = new MeiliSearch({
host: host,
apiKey: meiliSearchKey,
});

20
test/get-index.ts Normal file
View File

@@ -0,0 +1,20 @@
import { client } from './common';
import util from 'node:util';
const getIndex = async () => {
const index = await client.getIndexes({ limit: 3 });
return index;
};
// getIndex().then((result) => {
// console.log(result);
// });
const getTasks = async () => {
const tasks = await client.tasks.getTasks();
return tasks;
};
getTasks().then((result) => {
console.log(util.inspect(result, { depth: null }));
});

43
test/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import { client } from './common';
// 必须要id
const data = [
{
id: 1,
title: 'Document 1',
description: 'This is the content of document 1',
},
{
id: 2,
title: 'Document 2',
description: 'This is the content of document 2',
},
];
const createData = async () => {
const index = client.index('test_documents');
const task = await index.addDocuments(data);
console.log(task);
// task.status === 'succeeded' ? console.log('Documents added') : console.log('Failed to add documents');
// getAllData().then((result) => {
// console.log(result);
// });
};
createData();
const getAllData = async () => {
const index = client.index('test_documents');
const result = await index.getDocuments();
return result;
};
getAllData().then((result) => {
console.log(result);
});
const searchData = async (query) => {
const index = client.index('test_documents');
const result = await index.search(query);
return result;
};
// searchData('Document 1').then((result) => {
// console.log(result);
// });