@stacksjs/search-engine 0.53.1 → 0.56.23
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/dist/index.d.ts +33 -22
- package/dist/index.mjs +56 -25
- package/package.json +9 -8
- package/dist/drivers/meilisearch.d.ts +0 -9
- package/dist/drivers/meilisearch.mjs +0 -23
- package/dist/helpers.d.ts +0 -95
- package/dist/helpers.mjs +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import * as _stacksjs_types from '@stacksjs/types';
|
|
2
|
+
import { UiEngine } from '@stacksjs/ui';
|
|
3
|
+
import { MeiliSearch } from 'meilisearch';
|
|
4
|
+
|
|
5
|
+
interface SearchEngineOptions {
|
|
6
|
+
host: string;
|
|
7
|
+
apiKey: string;
|
|
8
|
+
}
|
|
9
|
+
declare function client$1(options?: SearchEngineOptions): MeiliSearch;
|
|
10
|
+
|
|
11
|
+
declare const totalPages: UiEngine.Ref<number>;
|
|
12
|
+
declare const currentPage: UiEngine.ComputedRef<number | undefined>;
|
|
13
|
+
declare const filterName: UiEngine.ComputedRef<string | undefined>;
|
|
14
|
+
declare const filters: UiEngine.ComputedRef<object | undefined>;
|
|
15
|
+
declare const goToNextPage: UiEngine.ComputedRef<number | undefined>;
|
|
16
|
+
declare const goToPage: UiEngine.ComputedRef<number | undefined>;
|
|
17
|
+
declare const goToPrevPage: UiEngine.ComputedRef<number | undefined>;
|
|
18
|
+
declare const hits: UiEngine.ComputedRef<_stacksjs_types.Hits<Record<string, any>> | undefined>;
|
|
19
|
+
declare const index: UiEngine.ComputedRef<string>;
|
|
20
|
+
declare const lastPageNumber: UiEngine.ComputedRef<number | undefined>;
|
|
21
|
+
declare const perPage: UiEngine.ComputedRef<number | undefined>;
|
|
22
|
+
declare const query: UiEngine.ComputedRef<string | undefined>;
|
|
23
|
+
declare const results: UiEngine.ComputedRef<_stacksjs_types.SearchResponse<Record<string, any>> | undefined>;
|
|
24
|
+
declare const searchFilters: UiEngine.ComputedRef<object | undefined>;
|
|
25
|
+
declare const searchParams: UiEngine.ComputedRef<object | undefined>;
|
|
26
|
+
declare const setTotalHits: UiEngine.ComputedRef<number | undefined>;
|
|
27
|
+
declare const sort: UiEngine.ComputedRef<string | undefined>;
|
|
28
|
+
declare const sorts: UiEngine.ComputedRef<object | undefined>;
|
|
29
|
+
declare function client(): typeof client$1 | undefined;
|
|
30
|
+
declare function useSearchEngine(): typeof client$1 | undefined;
|
|
31
|
+
declare function calculatePagination(): void;
|
|
32
|
+
|
|
33
|
+
export { calculatePagination, client, currentPage, filterName, filters, goToNextPage, goToPage, goToPrevPage, hits, index, lastPageNumber, perPage, query, results, searchFilters, searchParams, setTotalHits, sort, sorts, totalPages, useSearchEngine };
|
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,64 @@
|
|
|
1
|
-
import { searchEngine } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { searchEngine } from '@stacksjs/config';
|
|
2
|
+
import { log } from '@stacksjs/cli';
|
|
3
|
+
import { MeiliSearch } from 'meilisearch';
|
|
4
|
+
|
|
5
|
+
function client$1(options) {
|
|
6
|
+
let host = searchEngine.meilisearch?.host;
|
|
7
|
+
let apiKey = searchEngine.meilisearch?.apiKey;
|
|
8
|
+
if (options?.host)
|
|
9
|
+
host = options.host;
|
|
10
|
+
if (options?.apiKey)
|
|
11
|
+
apiKey = options.apiKey;
|
|
12
|
+
if (!host) {
|
|
13
|
+
log.error("Please specify a search engine host.");
|
|
14
|
+
process.exit();
|
|
15
|
+
}
|
|
16
|
+
return new MeiliSearch({ host, apiKey });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function determineState() {
|
|
20
|
+
const ls = localStorage.getItem("search-engine");
|
|
21
|
+
if (isString(ls))
|
|
22
|
+
return JSON.parse(ls);
|
|
23
|
+
return {
|
|
24
|
+
// default state
|
|
25
|
+
source: "http://127.0.0.1:7700",
|
|
26
|
+
index: "",
|
|
27
|
+
perPage: 20,
|
|
28
|
+
currentPage: 1,
|
|
29
|
+
query: ""
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
4
33
|
const table = useStorage("table", determineState()).value;
|
|
5
34
|
const totalHits = table.results?.estimatedTotalHits ?? 1;
|
|
6
35
|
const pages = ref([]);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
const totalPages = ref(0);
|
|
37
|
+
const currentPage = computed(() => table.currentPage);
|
|
38
|
+
const filterName = computed(() => table.filterName);
|
|
39
|
+
const filters = computed(() => table.filters);
|
|
40
|
+
const goToNextPage = computed(() => table.goToNextPage);
|
|
41
|
+
const goToPage = computed(() => table.goToPage);
|
|
42
|
+
const goToPrevPage = computed(() => table.goToPrevPage);
|
|
43
|
+
const hits = computed(() => table.hits);
|
|
44
|
+
const index = computed(() => table.index);
|
|
45
|
+
const lastPageNumber = computed(() => table.lastPageNumber);
|
|
46
|
+
const perPage = computed(() => table.perPage);
|
|
47
|
+
const query = computed(() => table.query);
|
|
48
|
+
const results = computed(() => table.results);
|
|
49
|
+
const searchFilters = computed(() => table.searchFilters);
|
|
50
|
+
const searchParams = computed(() => table.searchParams);
|
|
51
|
+
const setTotalHits = computed(() => table.setTotalHits);
|
|
52
|
+
const sort = computed(() => table.sort);
|
|
53
|
+
const sorts = computed(() => table.sorts);
|
|
54
|
+
function client() {
|
|
26
55
|
if (searchEngine.driver === "meilisearch")
|
|
27
|
-
return
|
|
56
|
+
return client$1;
|
|
28
57
|
}
|
|
29
|
-
|
|
58
|
+
function useSearchEngine() {
|
|
30
59
|
return client();
|
|
31
60
|
}
|
|
32
|
-
|
|
61
|
+
function calculatePagination() {
|
|
33
62
|
if (table.perPage)
|
|
34
63
|
totalPages.value = Math.ceil(totalHits / table.perPage);
|
|
35
64
|
const hitPages = [...Array(totalPages.value).keys()].map((i) => i + 1);
|
|
@@ -47,3 +76,5 @@ export function calculatePagination() {
|
|
|
47
76
|
allPages.push(page);
|
|
48
77
|
pages.value = allPages;
|
|
49
78
|
}
|
|
79
|
+
|
|
80
|
+
export { calculatePagination, client, currentPage, filterName, filters, goToNextPage, goToPage, goToPrevPage, hits, index, lastPageNumber, perPage, query, results, searchFilters, searchParams, setTotalHits, sort, sorts, totalPages, useSearchEngine };
|
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@8.5
|
|
4
|
+
"version": "0.56.23",
|
|
5
|
+
"packageManager": "pnpm@8.6.5",
|
|
6
6
|
"description": "The Stacks search engine integrations.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"import": "./dist/index.mjs"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
+
"main": "dist/index.mjs",
|
|
38
39
|
"module": "dist/index.mjs",
|
|
39
40
|
"types": "dist/index.d.ts",
|
|
40
41
|
"contributors": [
|
|
@@ -45,16 +46,16 @@
|
|
|
45
46
|
"README.md"
|
|
46
47
|
],
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"meilisearch": "^0.
|
|
49
|
+
"meilisearch": "^0.33.0"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@stacksjs/cli": "0.
|
|
52
|
-
"@stacksjs/config": "0.
|
|
53
|
-
"@stacksjs/ui": "0.
|
|
52
|
+
"@stacksjs/cli": "0.56.23",
|
|
53
|
+
"@stacksjs/config": "0.56.23",
|
|
54
|
+
"@stacksjs/ui": "0.56.23"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@stacksjs/
|
|
57
|
-
"@stacksjs/
|
|
57
|
+
"@stacksjs/types": "0.56.23",
|
|
58
|
+
"@stacksjs/development": "0.56.23"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"build": "unbuild",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MeiliSearch } from 'meilisearch';
|
|
2
|
-
import type { SearchResponse } from 'meilisearch';
|
|
3
|
-
interface SearchEngineOptions {
|
|
4
|
-
host: string;
|
|
5
|
-
apiKey: string;
|
|
6
|
-
}
|
|
7
|
-
declare function client(options?: SearchEngineOptions): MeiliSearch;
|
|
8
|
-
declare function search(index: string, params: any): Promise<SearchResponse<Record<string, any>>>;
|
|
9
|
-
export { client, search, };
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/helpers.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
* The search Filter Name
|
|
48
|
-
*/
|
|
49
|
-
filterName?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The search filters
|
|
52
|
-
*/
|
|
53
|
-
filters?: object;
|
|
54
|
-
/**
|
|
55
|
-
* The next page value
|
|
56
|
-
*/
|
|
57
|
-
goToNextPage?: number;
|
|
58
|
-
/**
|
|
59
|
-
* Set to go to a specific page
|
|
60
|
-
*/
|
|
61
|
-
goToPage?: number;
|
|
62
|
-
/**
|
|
63
|
-
* Set to go to the previous page
|
|
64
|
-
*/
|
|
65
|
-
goToPrevPage?: number;
|
|
66
|
-
/**
|
|
67
|
-
* The last page number value
|
|
68
|
-
*/
|
|
69
|
-
lastPageNumber?: number;
|
|
70
|
-
/**
|
|
71
|
-
* The searched term to use for the search
|
|
72
|
-
*/
|
|
73
|
-
search?: string;
|
|
74
|
-
/**
|
|
75
|
-
* The search params filters to use for the search
|
|
76
|
-
*/
|
|
77
|
-
searchFilters?: object;
|
|
78
|
-
/**
|
|
79
|
-
* The search params to use for the search
|
|
80
|
-
*/
|
|
81
|
-
searchParams?: object;
|
|
82
|
-
/**
|
|
83
|
-
* Total hits value to use for the search
|
|
84
|
-
*/
|
|
85
|
-
setTotalHits?: number;
|
|
86
|
-
/**
|
|
87
|
-
* The sort value to use for the search
|
|
88
|
-
*/
|
|
89
|
-
sort?: string;
|
|
90
|
-
/**
|
|
91
|
-
* The sorts value to use for the search
|
|
92
|
-
*/
|
|
93
|
-
sorts?: object;
|
|
94
|
-
}
|
|
95
|
-
export declare function determineState(): SearchEngineStore;
|
package/dist/helpers.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export function determineState() {
|
|
2
|
-
const ls = localStorage.getItem("search-engine");
|
|
3
|
-
if (isString(ls))
|
|
4
|
-
return JSON.parse(ls);
|
|
5
|
-
return {
|
|
6
|
-
// default state
|
|
7
|
-
source: "http://127.0.0.1:7700",
|
|
8
|
-
index: "",
|
|
9
|
-
perPage: 20,
|
|
10
|
-
currentPage: 1,
|
|
11
|
-
query: ""
|
|
12
|
-
};
|
|
13
|
-
}
|