@stacksjs/search-engine 0.42.2 → 0.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -10
- package/dist/drivers/meilisearch.d.ts +8 -0
- package/dist/drivers/meilisearch.mjs +23 -0
- package/dist/helpers.d.ts +47 -0
- package/dist/helpers.mjs +12 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +38 -2
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
# Stacks Search Engine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Stacks Search Engine is a unified driver system to easily interact with search engines.
|
|
4
4
|
|
|
5
5
|
## ☘️ Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- 🔎 Advanced searching
|
|
8
|
+
- 🎯 Filtering support
|
|
9
|
+
- 📚 Pagination support
|
|
10
|
+
- ⬇️ Sorting support
|
|
11
|
+
- 🚘 Driver based
|
|
12
|
+
- ⚡️ Meilisearch support
|
|
13
|
+
- 💀 Headless functions & components
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
## TODO
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
- [ ] Driver: Algolia
|
|
18
|
+
- [ ] Driver: TypeSense
|
|
12
19
|
|
|
13
20
|
## 🤖 Usage
|
|
14
21
|
|
|
15
|
-
wip
|
|
16
|
-
|
|
17
22
|
```bash
|
|
18
23
|
pnpm i -D @stacksjs/search-engine
|
|
19
24
|
```
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
You may now use:
|
|
22
27
|
|
|
23
|
-
```
|
|
24
|
-
import {
|
|
28
|
+
```ts
|
|
29
|
+
import { useSearchEngine } from '@stacksjs/search-engine'
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
const client = useSearchEngine()
|
|
32
|
+
const index = client.index(name)
|
|
33
|
+
const results = client.search('Hello World')
|
|
27
34
|
```
|
|
28
35
|
|
|
29
36
|
Learn more in the docs.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MeiliSearch } from 'meilisearch';
|
|
2
|
+
interface SearchEngineOptions {
|
|
3
|
+
host: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
}
|
|
6
|
+
declare function client(options?: SearchEngineOptions): MeiliSearch;
|
|
7
|
+
declare function search(index: string, params: any): Promise<import("meilisearch").SearchResponse<Record<string, any>>>;
|
|
8
|
+
export { client, search, };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { log } from "@stacksjs/cli";
|
|
2
|
+
import { searchEngine } from "@stacksjs/config";
|
|
3
|
+
import { MeiliSearch } from "meilisearch";
|
|
4
|
+
function client(options) {
|
|
5
|
+
let host = searchEngine.meilisearch?.host;
|
|
6
|
+
let apiKey = searchEngine.meilisearch?.apiKey;
|
|
7
|
+
if (options?.host)
|
|
8
|
+
host = options.host;
|
|
9
|
+
if (options?.apiKey)
|
|
10
|
+
apiKey = options.apiKey;
|
|
11
|
+
if (!host) {
|
|
12
|
+
log.error("Please specify a search engine host.");
|
|
13
|
+
process.exit();
|
|
14
|
+
}
|
|
15
|
+
return new MeiliSearch({ host, apiKey });
|
|
16
|
+
}
|
|
17
|
+
async function search(index, params) {
|
|
18
|
+
return await client().index(index).search(params.query, { limit: params.perPage, offset: params.page * params.perPage });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
client,
|
|
22
|
+
search
|
|
23
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is used to define the types/interfaces used in the project.
|
|
3
|
+
*/
|
|
4
|
+
import type { Hits, SearchResponse } from 'meilisearch';
|
|
5
|
+
export interface SearchEngineStore {
|
|
6
|
+
/**
|
|
7
|
+
* The search engine index.
|
|
8
|
+
*/
|
|
9
|
+
index: string;
|
|
10
|
+
/**
|
|
11
|
+
* The search engine host.
|
|
12
|
+
* @default 'http://127.0.0.1:7700'
|
|
13
|
+
*/
|
|
14
|
+
source?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The search engine password/API key.
|
|
17
|
+
*/
|
|
18
|
+
password?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The search query.
|
|
21
|
+
* @default 20
|
|
22
|
+
* @type {string}
|
|
23
|
+
* @default: ''
|
|
24
|
+
*/
|
|
25
|
+
query?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The number of results to return.
|
|
28
|
+
* @default 20
|
|
29
|
+
* @type {number}
|
|
30
|
+
*/
|
|
31
|
+
perPage?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The current page number
|
|
34
|
+
* @default 1
|
|
35
|
+
* @type {number}
|
|
36
|
+
*/
|
|
37
|
+
currentPage?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The results object returned from the search engine.
|
|
40
|
+
*/
|
|
41
|
+
results?: SearchResponse<Record<string, any>>;
|
|
42
|
+
/**
|
|
43
|
+
* The hits object returned from the search engine.
|
|
44
|
+
*/
|
|
45
|
+
hits?: Hits<Record<string, any>>;
|
|
46
|
+
}
|
|
47
|
+
export declare function determineState(): SearchEngineStore;
|
package/dist/helpers.mjs
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { client as meilisearch, search } from './drivers/meilisearch';
|
|
2
|
+
export declare function client(): typeof meilisearch | undefined;
|
|
3
|
+
export declare function useSearchEngine(): typeof meilisearch | undefined;
|
|
4
|
+
export declare function calculatePagination(): void;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
useSearchEngine: typeof useSearchEngine;
|
|
7
|
+
client: typeof client;
|
|
8
|
+
search: typeof search;
|
|
9
|
+
calculatePagination: typeof calculatePagination;
|
|
10
|
+
currentPage: any;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
+
import { searchEngine } from "@stacksjs/config";
|
|
2
|
+
import { client as meilisearch, search } from "./drivers/meilisearch.mjs";
|
|
3
|
+
import { determineState } from "./helpers.mjs";
|
|
4
|
+
const table = useStorage("table", determineState()).value;
|
|
5
|
+
const totalHits = table.results?.estimatedTotalHits ?? 1;
|
|
6
|
+
const pages = ref([]);
|
|
7
|
+
const totalPages = ref(0);
|
|
8
|
+
const currentPage = computed(() => table.currentPage);
|
|
9
|
+
export function client() {
|
|
10
|
+
if (searchEngine.driver === "meilisearch")
|
|
11
|
+
return meilisearch;
|
|
12
|
+
}
|
|
1
13
|
export function useSearchEngine() {
|
|
2
|
-
|
|
3
|
-
|
|
14
|
+
return client();
|
|
15
|
+
}
|
|
16
|
+
export function calculatePagination() {
|
|
17
|
+
if (table.perPage)
|
|
18
|
+
totalPages.value = Math.ceil(totalHits / table.perPage);
|
|
19
|
+
const hitPages = [...Array(totalPages.value).keys()].map((i) => i + 1);
|
|
20
|
+
const offset = 2;
|
|
21
|
+
const currentPage2 = table.currentPage ?? 1;
|
|
22
|
+
const lastPage = hitPages[hitPages.length - 1];
|
|
23
|
+
let from = currentPage2 - offset;
|
|
24
|
+
if (from < 1)
|
|
25
|
+
from = 1;
|
|
26
|
+
let to = from + offset * 2;
|
|
27
|
+
if (to >= lastPage)
|
|
28
|
+
to = lastPage;
|
|
29
|
+
const allPages = [];
|
|
30
|
+
for (let page = from; page <= to; page++)
|
|
31
|
+
allPages.push(page);
|
|
32
|
+
pages.value = allPages;
|
|
4
33
|
}
|
|
34
|
+
export default {
|
|
35
|
+
useSearchEngine,
|
|
36
|
+
client,
|
|
37
|
+
search,
|
|
38
|
+
calculatePagination,
|
|
39
|
+
currentPage
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/search-engine",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@7.17.
|
|
4
|
+
"version": "0.43.1",
|
|
5
|
+
"packageManager": "pnpm@7.17.1",
|
|
6
6
|
"description": "The Stacks search engine integrations.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -41,18 +41,19 @@
|
|
|
41
41
|
],
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=v18.12.1",
|
|
44
|
-
"pnpm": ">=7.17.
|
|
44
|
+
"pnpm": ">=7.17.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@vueuse/core": "^9.6.0",
|
|
48
|
-
"meilisearch": "^0.
|
|
48
|
+
"meilisearch": "^0.30.0",
|
|
49
49
|
"vue": "^3.2.45",
|
|
50
|
-
"@stacksjs/
|
|
50
|
+
"@stacksjs/cli": "0.43.1",
|
|
51
|
+
"@stacksjs/config": "0.43.1"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"mkdist": "^1.0.0",
|
|
54
55
|
"typescript": "^4.9.3",
|
|
55
|
-
"@stacksjs/testing": "0.
|
|
56
|
+
"@stacksjs/testing": "0.43.1"
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"build": "mkdist -d",
|