@stacksjs/search-engine 0.56.35 → 0.57.3
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/drivers/index.d.ts +1 -0
- package/dist/drivers/index.mjs +1 -0
- package/dist/drivers/meilisearch.d.ts +9 -0
- package/dist/drivers/meilisearch.mjs +23 -0
- package/dist/helpers.d.ts +95 -0
- package/dist/helpers.mjs +13 -0
- package/dist/index.d.ts +22 -33
- package/dist/index.mjs +25 -56
- package/package.json +7 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as meilisearch from './meilisearch';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as meilisearch from "./meilisearch.mjs";
|
|
@@ -0,0 +1,9 @@
|
|
|
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, };
|
|
@@ -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,95 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
declare const
|
|
12
|
-
declare const
|
|
13
|
-
declare const
|
|
14
|
-
declare const
|
|
15
|
-
declare const
|
|
16
|
-
declare const
|
|
17
|
-
declare const
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
20
|
-
declare
|
|
21
|
-
declare
|
|
22
|
-
declare
|
|
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 };
|
|
1
|
+
import { client as meilisearch } from './drivers/meilisearch';
|
|
2
|
+
export declare const totalPages: any;
|
|
3
|
+
export declare const currentPage: any;
|
|
4
|
+
export declare const filterName: any;
|
|
5
|
+
export declare const filters: any;
|
|
6
|
+
export declare const goToNextPage: any;
|
|
7
|
+
export declare const goToPage: any;
|
|
8
|
+
export declare const goToPrevPage: any;
|
|
9
|
+
export declare const hits: any;
|
|
10
|
+
export declare const index: any;
|
|
11
|
+
export declare const lastPageNumber: any;
|
|
12
|
+
export declare const perPage: any;
|
|
13
|
+
export declare const query: any;
|
|
14
|
+
export declare const results: any;
|
|
15
|
+
export declare const searchFilters: any;
|
|
16
|
+
export declare const searchParams: any;
|
|
17
|
+
export declare const setTotalHits: any;
|
|
18
|
+
export declare const sort: any;
|
|
19
|
+
export declare const sorts: any;
|
|
20
|
+
export declare function client(): typeof meilisearch | undefined;
|
|
21
|
+
export declare function useSearchEngine(): typeof meilisearch | undefined;
|
|
22
|
+
export declare function calculatePagination(): void;
|
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,35 @@
|
|
|
1
|
-
import { searchEngine } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
1
|
+
import { searchEngine } from "@stacksjs/config";
|
|
2
|
+
import { client as meilisearch } from "./drivers/meilisearch.mjs";
|
|
3
|
+
import { determineState } from "./helpers.mjs";
|
|
33
4
|
const table = useStorage("table", determineState()).value;
|
|
34
5
|
const totalHits = table.results?.estimatedTotalHits ?? 1;
|
|
35
6
|
const pages = ref([]);
|
|
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() {
|
|
7
|
+
export const totalPages = ref(0);
|
|
8
|
+
export const currentPage = computed(() => table.currentPage);
|
|
9
|
+
export const filterName = computed(() => table.filterName);
|
|
10
|
+
export const filters = computed(() => table.filters);
|
|
11
|
+
export const goToNextPage = computed(() => table.goToNextPage);
|
|
12
|
+
export const goToPage = computed(() => table.goToPage);
|
|
13
|
+
export const goToPrevPage = computed(() => table.goToPrevPage);
|
|
14
|
+
export const hits = computed(() => table.hits);
|
|
15
|
+
export const index = computed(() => table.index);
|
|
16
|
+
export const lastPageNumber = computed(() => table.lastPageNumber);
|
|
17
|
+
export const perPage = computed(() => table.perPage);
|
|
18
|
+
export const query = computed(() => table.query);
|
|
19
|
+
export const results = computed(() => table.results);
|
|
20
|
+
export const searchFilters = computed(() => table.searchFilters);
|
|
21
|
+
export const searchParams = computed(() => table.searchParams);
|
|
22
|
+
export const setTotalHits = computed(() => table.setTotalHits);
|
|
23
|
+
export const sort = computed(() => table.sort);
|
|
24
|
+
export const sorts = computed(() => table.sorts);
|
|
25
|
+
export function client() {
|
|
55
26
|
if (searchEngine.driver === "meilisearch")
|
|
56
|
-
return
|
|
27
|
+
return meilisearch;
|
|
57
28
|
}
|
|
58
|
-
function useSearchEngine() {
|
|
29
|
+
export function useSearchEngine() {
|
|
59
30
|
return client();
|
|
60
31
|
}
|
|
61
|
-
function calculatePagination() {
|
|
32
|
+
export function calculatePagination() {
|
|
62
33
|
if (table.perPage)
|
|
63
34
|
totalPages.value = Math.ceil(totalHits / table.perPage);
|
|
64
35
|
const hitPages = [...Array(totalPages.value).keys()].map((i) => i + 1);
|
|
@@ -76,5 +47,3 @@ function calculatePagination() {
|
|
|
76
47
|
allPages.push(page);
|
|
77
48
|
pages.value = allPages;
|
|
78
49
|
}
|
|
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.6.
|
|
4
|
+
"version": "0.57.3",
|
|
5
|
+
"packageManager": "pnpm@8.6.6",
|
|
6
6
|
"description": "The Stacks search engine integrations.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"meilisearch": "^0.33.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@stacksjs/cli": "0.
|
|
52
|
-
"@stacksjs/config": "0.
|
|
53
|
-
"@stacksjs/ui": "0.
|
|
51
|
+
"@stacksjs/cli": "0.57.3",
|
|
52
|
+
"@stacksjs/config": "0.57.3",
|
|
53
|
+
"@stacksjs/ui": "0.57.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@stacksjs/development": "0.
|
|
57
|
-
"@stacksjs/types": "0.
|
|
56
|
+
"@stacksjs/development": "0.57.3",
|
|
57
|
+
"@stacksjs/types": "0.57.3"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build": "unbuild",
|