This commit is contained in:
熊潇 2025-05-11 00:16:16 +08:00
commit 92bd43d4e7
8 changed files with 394 additions and 0 deletions

66
.gitignore vendored Normal file
View File

@ -0,0 +1,66 @@
node_modules
# mac
.DS_Store
.env*
!.env*example
/dist
# build
/build
/logs
.turbo
/pack-dist
# astro
.astro
# next
.next
# nuxt
.nuxt
# vercel
.vercel
# vuepress
.vuepress/dist
# coverage
coverage/
# typescript
*.tsbuildinfo
# debug logs
*.log
*.tmp
# vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# idea
.idea
# system
Thumbs.db
ehthumbs.db
Desktop.ini
# temp files
*.tmp
*.temp
# local development
*.local
movies.json

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "search-test",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
"license": "MIT",
"packageManager": "pnpm@10.6.2",
"type": "module",
"dependencies": {
"meilisearch": "^0.50.0"
},
"devDependencies": {
"@kevisual/types": "^0.0.10",
"@types/node": "^22.15.17",
"dayjs": "^1.11.13",
"fast-glob": "^3.3.3"
}
}

191
pnpm-lock.yaml generated Normal file
View File

@ -0,0 +1,191 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
meilisearch:
specifier: ^0.50.0
version: 0.50.0
devDependencies:
'@kevisual/types':
specifier: ^0.0.10
version: 0.0.10
'@types/node':
specifier: ^22.15.17
version: 22.15.17
dayjs:
specifier: ^1.11.13
version: 1.11.13
fast-glob:
specifier: ^3.3.3
version: 3.3.3
packages:
'@kevisual/types@0.0.10':
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
'@nodelib/fs.scandir@2.1.5':
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
engines: {node: '>= 8'}
'@nodelib/fs.stat@2.0.5':
resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==}
engines: {node: '>= 8'}
'@nodelib/fs.walk@1.2.8':
resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==}
engines: {node: '>= 8'}
'@types/node@22.15.17':
resolution: {integrity: sha512-wIX2aSZL5FE+MR0JlvF87BNVrtFWf6AE6rxSE9X7OwnVvoyCQjpzSRJ+M87se/4QCkCiebQAqrJ0y6fwIyi7nw==}
braces@3.0.3:
resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==}
engines: {node: '>=8'}
dayjs@1.11.13:
resolution: {integrity: sha512-oaMBel6gjolK862uaPQOVTA7q3TZhuSvuMQAAglQDOWYO9A91IrAOUJEyKVlqJlHE0vq5p5UXxzdPfMH/x6xNg==}
fast-glob@3.3.3:
resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==}
engines: {node: '>=8.6.0'}
fastq@1.19.1:
resolution: {integrity: sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==}
fill-range@7.1.1:
resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==}
engines: {node: '>=8'}
glob-parent@5.1.2:
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
engines: {node: '>= 6'}
is-extglob@2.1.1:
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
is-glob@4.0.3:
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
engines: {node: '>=0.10.0'}
is-number@7.0.0:
resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==}
engines: {node: '>=0.12.0'}
meilisearch@0.50.0:
resolution: {integrity: sha512-9IzIkobvnuS18Eg4dq/eJB9W+eXqeLZjNRgq/kKMswSmVYYSQsXqGgSuCA0JkF+o5RwJlwIsieQee6rh313VhA==}
merge2@1.4.1:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
engines: {node: '>= 8'}
micromatch@4.0.8:
resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==}
engines: {node: '>=8.6'}
picomatch@2.3.1:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'}
queue-microtask@1.2.3:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
reusify@1.1.0:
resolution: {integrity: sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==}
engines: {iojs: '>=1.0.0', node: '>=0.10.0'}
run-parallel@1.2.0:
resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==}
to-regex-range@5.0.1:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'}
undici-types@6.21.0:
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
snapshots:
'@kevisual/types@0.0.10': {}
'@nodelib/fs.scandir@2.1.5':
dependencies:
'@nodelib/fs.stat': 2.0.5
run-parallel: 1.2.0
'@nodelib/fs.stat@2.0.5': {}
'@nodelib/fs.walk@1.2.8':
dependencies:
'@nodelib/fs.scandir': 2.1.5
fastq: 1.19.1
'@types/node@22.15.17':
dependencies:
undici-types: 6.21.0
braces@3.0.3:
dependencies:
fill-range: 7.1.1
dayjs@1.11.13: {}
fast-glob@3.3.3:
dependencies:
'@nodelib/fs.stat': 2.0.5
'@nodelib/fs.walk': 1.2.8
glob-parent: 5.1.2
merge2: 1.4.1
micromatch: 4.0.8
fastq@1.19.1:
dependencies:
reusify: 1.1.0
fill-range@7.1.1:
dependencies:
to-regex-range: 5.0.1
glob-parent@5.1.2:
dependencies:
is-glob: 4.0.3
is-extglob@2.1.1: {}
is-glob@4.0.3:
dependencies:
is-extglob: 2.1.1
is-number@7.0.0: {}
meilisearch@0.50.0: {}
merge2@1.4.1: {}
micromatch@4.0.8:
dependencies:
braces: 3.0.3
picomatch: 2.3.1
picomatch@2.3.1: {}
queue-microtask@1.2.3: {}
reusify@1.1.0: {}
run-parallel@1.2.0:
dependencies:
queue-microtask: 1.2.3
to-regex-range@5.0.1:
dependencies:
is-number: 7.0.0
undici-types@6.21.0: {}

13
src/data/download.ts Normal file
View File

@ -0,0 +1,13 @@
const link = 'https://milli-benchmarks.fra1.digitaloceanspaces.com/bench/datasets/movies.json';
import fs from 'node:fs';
import path from 'node:path';
const movieFilePath = path.join(process.cwd(),'dist', 'movies.json');
const download = async () => {
const response = await fetch(link);
const data = await response.json();
fs.writeFileSync(movieFilePath, JSON.stringify(data));
return data;
};
await download();

1
src/get-stat-json.ts Normal file
View File

@ -0,0 +1 @@
import FastGlob from 'fast-glob';

68
src/index.ts Normal file
View File

@ -0,0 +1,68 @@
import { MeiliSearch } from 'meilisearch';
// {
// name: null,
// description: "Movies",
// key: "bd853c831279b8eaa0799f512e07d0aa703405790c780446c26718e2be1e814f",
// uid: "fbb9b3d0-1d88-4386-9b84-d959a533fcc7",
// actions: [ "documents.get", "documents.add", "search" ],
// indexes: [ "movies" ],
// expiresAt: "2026-01-01T00:00:00Z",
// createdAt: "2025-05-10T15:27:31.073736Z",
// updatedAt: "2025-05-10T15:27:31.073736Z",
// }
const client = new MeiliSearch({
host: 'http://localhost:7700',
// apiKey: 'aSampleMasterKey',
apiKey: 'bd853c831279b8eaa0799f512e07d0aa703405790c780446c26718e2be1e814f'
});
const moviesIndex = client.index('movies');
// await moviesIndex.deleteAllDocuments()
// const searhcRes = await moviesIndex.search('American ninja "Julian makes a lucrative living as an escort to older women in the Los Angeles area"');
const searhcRes = await moviesIndex.search('"https://image.tmdb.org/t/p/w500/zrsOgLFiFXYzleX9p3tp8eNUruk.jpg"',{
showRankingScore: true
});
console.log(searhcRes);
// moviesIndex.getSettings().then((settings) => {
// console.log(settings);
// });
// moviesIndex.searchSimilarDocuments({
// id: '1',
// embedder: 'apple',
// });
// moviesIndex.updateEmbedders({
// siliconflow: {
// source: 'ollama',
// apiKey: 'SILICONFLOW_API_KEY',
// url: 'https://api.siliconflow.cn/v1/embeddings',
// model: 'BAAI/bge-m3',
// },
// });
// moviesIndex.getEmbedders().then((embedders) => {
// console.log(embedders);
// });
// client
// .getKeys()
// .then((keys) => {
// console.log(keys);
// })
// .catch((err) => {});
// client.getKey('movies').then((key) => {
// console.log(key);
// });
// client
// .createKey({
// description: 'Movies',
// actions: ['documents.get', 'documents.add', 'search'],
// indexes: ['movies'],
// expiresAt: new Date('2026-01-01T00:00:00Z'),
// })
// .then((key) => {
// console.log(key);
// });
// client.deleteKey('57d828fa84d48786c6370034c02d92dafa712f5823ac1b35ef5afc3a1ea4cadc')

14
src/movies/add.ts Normal file
View File

@ -0,0 +1,14 @@
import { MeiliSearch } from 'meilisearch';
import fs from 'node:fs';
import path from 'node:path';
const movieFile = fs.readFileSync(path.join(process.cwd(), 'dist','movies.json'), 'utf-8');
const movies = JSON.parse(movieFile);
const client = new MeiliSearch({
host: 'http://localhost:7700',
apiKey: 'aSampleMasterKey',
});
client
.index('movies')
.addDocuments(movies)
.then((res) => console.log(res));

18
tsconfig.json Normal file
View File

@ -0,0 +1,18 @@
{
"extends": "@kevisual/types/json/backend.json",
"compilerOptions": {
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types",
"./node_modules/@kevisual"
],
"paths": {
"@/*": [
"src/*"
]
},
},
"include": [
"src/**/*",
],
}