@stacksjs/search-engine 0.64.6 → 0.65.0
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/meilisearch.d.ts +0 -0
- package/dist/drivers/opensearch.d.ts +0 -0
- package/dist/helpers.d.ts +6 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +35 -37
- package/dist/index.js.map +14 -14
- package/dist/types.d.ts +91 -0
- package/package.json +9 -15
- package/src/helpers.ts +3 -116
- package/src/index.ts +29 -26
- package/src/types.ts +115 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Hits, SearchResponse } from "meilisearch";
|
|
2
|
+
export interface SearchEngineStore {
|
|
3
|
+
/**
|
|
4
|
+
* The search engine index.
|
|
5
|
+
*/
|
|
6
|
+
index: string;
|
|
7
|
+
/**
|
|
8
|
+
* The search engine host.
|
|
9
|
+
* @default 'http://127.0.0.1:7700'
|
|
10
|
+
*/
|
|
11
|
+
source?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The search engine password/API key.
|
|
14
|
+
*/
|
|
15
|
+
password?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The search query.
|
|
18
|
+
* @default 20
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @default: ''
|
|
21
|
+
*/
|
|
22
|
+
query?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The number of results to return.
|
|
25
|
+
* @default 20
|
|
26
|
+
* @type {number}
|
|
27
|
+
*/
|
|
28
|
+
perPage?: number;
|
|
29
|
+
/**
|
|
30
|
+
* The current page number
|
|
31
|
+
* @default 1
|
|
32
|
+
* @type {number}
|
|
33
|
+
*/
|
|
34
|
+
currentPage?: number;
|
|
35
|
+
/**
|
|
36
|
+
* The results object returned from the search engine.
|
|
37
|
+
*/
|
|
38
|
+
results?: SearchResponse<Record<string, any>>;
|
|
39
|
+
/**
|
|
40
|
+
* The hits object returned from the search engine.
|
|
41
|
+
*/
|
|
42
|
+
hits?: Hits<Record<string, any>>;
|
|
43
|
+
/**
|
|
44
|
+
* The search Filter Name
|
|
45
|
+
*/
|
|
46
|
+
filterName?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The search filters
|
|
49
|
+
*/
|
|
50
|
+
filters?: object;
|
|
51
|
+
/**
|
|
52
|
+
* The next page value
|
|
53
|
+
*/
|
|
54
|
+
goToNextPage?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Set to go to a specific page
|
|
57
|
+
*/
|
|
58
|
+
goToPage?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Set to go to the previous page
|
|
61
|
+
*/
|
|
62
|
+
goToPrevPage?: number;
|
|
63
|
+
/**
|
|
64
|
+
* The last page number value
|
|
65
|
+
*/
|
|
66
|
+
lastPageNumber?: number;
|
|
67
|
+
/**
|
|
68
|
+
* The searched term to use for the search
|
|
69
|
+
*/
|
|
70
|
+
search?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The search params filters to use for the search
|
|
73
|
+
*/
|
|
74
|
+
searchFilters?: object;
|
|
75
|
+
/**
|
|
76
|
+
* The search params to use for the search
|
|
77
|
+
*/
|
|
78
|
+
searchParams?: object;
|
|
79
|
+
/**
|
|
80
|
+
* Total hits value to use for the search
|
|
81
|
+
*/
|
|
82
|
+
setTotalHits?: number;
|
|
83
|
+
/**
|
|
84
|
+
* The sort value to use for the search
|
|
85
|
+
*/
|
|
86
|
+
sort?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The sorts value to use for the search
|
|
89
|
+
*/
|
|
90
|
+
sorts?: object;
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/search-engine",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.65.0",
|
|
5
5
|
"description": "The Stacks search engine integrations.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
|
+
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
9
10
|
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/search-engine#readme",
|
|
@@ -40,25 +41,18 @@
|
|
|
40
41
|
},
|
|
41
42
|
"module": "dist/index.js",
|
|
42
43
|
"types": "dist/index.d.ts",
|
|
43
|
-
"
|
|
44
|
-
"Chris Breuer <chris@stacksjs.org>"
|
|
45
|
-
],
|
|
46
|
-
"files": [
|
|
47
|
-
"README.md",
|
|
48
|
-
"dist",
|
|
49
|
-
"src"
|
|
50
|
-
],
|
|
44
|
+
"files": ["README.md", "dist", "src"],
|
|
51
45
|
"scripts": {
|
|
52
|
-
"build": "bun
|
|
53
|
-
"typecheck": "bun
|
|
46
|
+
"build": "bun build.ts",
|
|
47
|
+
"typecheck": "bun tsc --noEmit",
|
|
54
48
|
"prepublishOnly": "bun run build"
|
|
55
49
|
},
|
|
56
50
|
"dependencies": {
|
|
57
|
-
"@opensearch-project/opensearch": "^2.
|
|
58
|
-
"meilisearch": "^0.
|
|
51
|
+
"@opensearch-project/opensearch": "^2.12.0",
|
|
52
|
+
"meilisearch": "^0.44.1"
|
|
59
53
|
},
|
|
60
54
|
"devDependencies": {
|
|
61
|
-
"@stacksjs/config": "
|
|
62
|
-
"@stacksjs/development": "
|
|
55
|
+
"@stacksjs/config": "0.64.6",
|
|
56
|
+
"@stacksjs/development": "0.64.6"
|
|
63
57
|
}
|
|
64
58
|
}
|
package/src/helpers.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is used to define the types/interfaces used in the project.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { SearchEngineStore } from './types'
|
|
6
6
|
|
|
7
7
|
// import { isString } from '@stacksjs/validation'
|
|
8
8
|
|
|
@@ -10,124 +10,11 @@ export function isString(val: unknown): val is string {
|
|
|
10
10
|
return typeof val === 'string'
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// this interface is primarily used to persist data to localStorage, in a unified way
|
|
14
|
-
export interface SearchEngineStore {
|
|
15
|
-
/**
|
|
16
|
-
* The search engine index.
|
|
17
|
-
*/
|
|
18
|
-
index: string
|
|
19
|
-
/**
|
|
20
|
-
* The search engine host.
|
|
21
|
-
* @default 'http://127.0.0.1:7700'
|
|
22
|
-
*/
|
|
23
|
-
source?: string
|
|
24
|
-
/**
|
|
25
|
-
* The search engine password/API key.
|
|
26
|
-
*/
|
|
27
|
-
password?: string
|
|
28
|
-
/**
|
|
29
|
-
* The search query.
|
|
30
|
-
* @default 20
|
|
31
|
-
* @type {string}
|
|
32
|
-
* @default: ''
|
|
33
|
-
*/
|
|
34
|
-
query?: string
|
|
35
|
-
/**
|
|
36
|
-
* The number of results to return.
|
|
37
|
-
* @default 20
|
|
38
|
-
* @type {number}
|
|
39
|
-
*/
|
|
40
|
-
perPage?: number
|
|
41
|
-
/**
|
|
42
|
-
* The current page number
|
|
43
|
-
* @default 1
|
|
44
|
-
* @type {number}
|
|
45
|
-
*/
|
|
46
|
-
currentPage?: number
|
|
47
|
-
/**
|
|
48
|
-
* The results object returned from the search engine.
|
|
49
|
-
*/
|
|
50
|
-
results?: SearchResponse<Record<string, any>> // optional: the Meilisearch search response (defaults: {})
|
|
51
|
-
/**
|
|
52
|
-
* The hits object returned from the search engine.
|
|
53
|
-
*/
|
|
54
|
-
hits?: Hits<Record<string, any>>
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* The search Filter Name
|
|
58
|
-
*/
|
|
59
|
-
filterName?: string
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* The search filters
|
|
63
|
-
*/
|
|
64
|
-
filters?: object
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The next page value
|
|
68
|
-
*/
|
|
69
|
-
goToNextPage?: number
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Set to go to a specific page
|
|
73
|
-
*/
|
|
74
|
-
goToPage?: number
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Set to go to the previous page
|
|
78
|
-
*/
|
|
79
|
-
goToPrevPage?: number
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The last page number value
|
|
83
|
-
*/
|
|
84
|
-
lastPageNumber?: number
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* The searched term to use for the search
|
|
88
|
-
*/
|
|
89
|
-
search?: string
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* The search params filters to use for the search
|
|
93
|
-
*/
|
|
94
|
-
searchFilters?: object
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* The search params to use for the search
|
|
98
|
-
*/
|
|
99
|
-
searchParams?: object
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Total hits value to use for the search
|
|
103
|
-
*/
|
|
104
|
-
setTotalHits?: number
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* The sort value to use for the search
|
|
108
|
-
*/
|
|
109
|
-
sort?: string
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* The sorts value to use for the search
|
|
113
|
-
*/
|
|
114
|
-
sorts?: object
|
|
115
|
-
|
|
116
|
-
// table related config
|
|
117
|
-
// actionable?: string | boolean // optional: determines whether the table displays any "action items" (defaults: true)
|
|
118
|
-
// actions?: string | string[] // optional: the specific type of actions to be displayed/utilized in the table (defaults: 'Edit, Delete')
|
|
119
|
-
// columns: string[] // used as table heads/column titles
|
|
120
|
-
// selectable?: string | boolean // optional: determines whether the table displays the checkboxes (defaults: true)
|
|
121
|
-
// selectedRows?: number[] | string[] // optional: holds the selected rows (defaults: [])
|
|
122
|
-
// selectedAll?: boolean // optional: determines whether all the rows are selected (defaults: false)
|
|
123
|
-
// stickyHeader?: string | boolean // optional: determines whether the table displays the sticky header (defaults: false)
|
|
124
|
-
// stickyFooter?: string | boolean // optional: determines whether the table displays the sticky footer (defaults: false)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
13
|
export function determineState(): SearchEngineStore {
|
|
128
14
|
const ls = localStorage.getItem('search-engine')
|
|
129
15
|
|
|
130
|
-
if (isString(ls))
|
|
16
|
+
if (isString(ls))
|
|
17
|
+
return JSON.parse(ls) as SearchEngineStore
|
|
131
18
|
|
|
132
19
|
return {
|
|
133
20
|
// default state
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UiEngine } from '@stacksjs/ui'
|
|
2
2
|
import { useStorage } from '@stacksjs/utils'
|
|
3
|
-
import { computed, ref } from 'vue'
|
|
3
|
+
import { computed, type ComputedRef, type Ref, ref } from 'vue'
|
|
4
4
|
|
|
5
5
|
// import { client as meilisearch } from './drivers/meilisearch'
|
|
6
6
|
import { determineState } from './helpers'
|
|
@@ -12,49 +12,52 @@ const totalHits = table.results?.estimatedTotalHits ?? 1
|
|
|
12
12
|
|
|
13
13
|
// state
|
|
14
14
|
const pages: UiEngine.Ref<number[]> = ref([])
|
|
15
|
-
export const totalPages = ref(0)
|
|
16
|
-
export const currentPage = computed(() => table.currentPage)
|
|
17
|
-
export const filterName = computed(() => table.filterName)
|
|
15
|
+
export const totalPages: Ref = ref(0)
|
|
16
|
+
export const currentPage: ComputedRef = computed(() => table.currentPage)
|
|
17
|
+
export const filterName: ComputedRef = computed(() => table.filterName)
|
|
18
18
|
|
|
19
|
-
export const filters = computed(() => table.filters)
|
|
20
|
-
export const goToNextPage = computed(() => table.goToNextPage)
|
|
21
|
-
export const goToPage = computed(() => table.goToPage)
|
|
22
|
-
export const goToPrevPage = computed(() => table.goToPrevPage)
|
|
23
|
-
export const hits = computed(() => table.hits)
|
|
24
|
-
export const index = computed(() => table.index)
|
|
25
|
-
export const lastPageNumber = computed(() => table.lastPageNumber)
|
|
26
|
-
export const perPage = computed(() => table.perPage)
|
|
27
|
-
export const query = computed(() => table.query)
|
|
28
|
-
export const results = computed(() => table.results)
|
|
29
|
-
export const searchFilters = computed(() => table.searchFilters)
|
|
30
|
-
export const searchParams = computed(() => table.searchParams)
|
|
31
|
-
export const setTotalHits = computed(() => table.setTotalHits)
|
|
32
|
-
export const sort = computed(() => table.sort)
|
|
33
|
-
export const sorts = computed(() => table.sorts)
|
|
19
|
+
export const filters: ComputedRef = computed(() => table.filters)
|
|
20
|
+
export const goToNextPage: ComputedRef = computed(() => table.goToNextPage)
|
|
21
|
+
export const goToPage: ComputedRef = computed(() => table.goToPage)
|
|
22
|
+
export const goToPrevPage: ComputedRef = computed(() => table.goToPrevPage)
|
|
23
|
+
export const hits: ComputedRef = computed(() => table.hits)
|
|
24
|
+
export const index: ComputedRef<string> = computed(() => table.index)
|
|
25
|
+
export const lastPageNumber: ComputedRef<number> = computed(() => table.lastPageNumber || 1)
|
|
26
|
+
export const perPage: ComputedRef<number> = computed(() => table.perPage || 10)
|
|
27
|
+
export const query: ComputedRef<string | undefined> = computed(() => table.query)
|
|
28
|
+
export const results: ComputedRef = computed(() => table.results)
|
|
29
|
+
export const searchFilters: ComputedRef = computed(() => table.searchFilters)
|
|
30
|
+
export const searchParams: ComputedRef = computed(() => table.searchParams)
|
|
31
|
+
export const setTotalHits: ComputedRef = computed(() => table.setTotalHits)
|
|
32
|
+
export const sort: ComputedRef = computed(() => table.sort)
|
|
33
|
+
export const sorts: ComputedRef = computed(() => table.sorts)
|
|
34
34
|
|
|
35
|
-
export function client() {
|
|
35
|
+
export function client(): string {
|
|
36
36
|
// if (searchEngine.driver === 'meilisearch')
|
|
37
37
|
// return meilisearch
|
|
38
38
|
return 'wip-search-me'
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function useSearchEngine() {
|
|
41
|
+
export function useSearchEngine(): string {
|
|
42
42
|
return client()
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export function calculatePagination() {
|
|
46
|
-
if (table.perPage)
|
|
45
|
+
export function calculatePagination(): void {
|
|
46
|
+
if (table.perPage)
|
|
47
|
+
totalPages.value = Math.ceil(totalHits / table.perPage)
|
|
47
48
|
|
|
48
|
-
const hitPages =
|
|
49
|
+
const hitPages = Array.from({ length: totalPages.value }, (_, i) => i + 1)
|
|
49
50
|
const offset = 2
|
|
50
51
|
const currentPage = table.currentPage ?? 1
|
|
51
52
|
const lastPage = hitPages[hitPages.length - 1]
|
|
52
53
|
|
|
53
54
|
let from = currentPage - offset
|
|
54
|
-
if (from < 1)
|
|
55
|
+
if (from < 1)
|
|
56
|
+
from = 1
|
|
55
57
|
|
|
56
58
|
let to = from + offset * 2
|
|
57
|
-
if (to >= (lastPage as number))
|
|
59
|
+
if (to >= (lastPage as number))
|
|
60
|
+
to = lastPage as number
|
|
58
61
|
|
|
59
62
|
const allPages = []
|
|
60
63
|
for (let page = from; page <= to; page++) allPages.push(page)
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { Hits, SearchResponse } from 'meilisearch'
|
|
2
|
+
|
|
3
|
+
// this interface is primarily used to persist data to localStorage, in a unified way
|
|
4
|
+
export interface SearchEngineStore {
|
|
5
|
+
/**
|
|
6
|
+
* The search engine index.
|
|
7
|
+
*/
|
|
8
|
+
index: string
|
|
9
|
+
/**
|
|
10
|
+
* The search engine host.
|
|
11
|
+
* @default 'http://127.0.0.1:7700'
|
|
12
|
+
*/
|
|
13
|
+
source?: string
|
|
14
|
+
/**
|
|
15
|
+
* The search engine password/API key.
|
|
16
|
+
*/
|
|
17
|
+
password?: string
|
|
18
|
+
/**
|
|
19
|
+
* The search query.
|
|
20
|
+
* @default 20
|
|
21
|
+
* @type {string}
|
|
22
|
+
* @default: ''
|
|
23
|
+
*/
|
|
24
|
+
query?: string
|
|
25
|
+
/**
|
|
26
|
+
* The number of results to return.
|
|
27
|
+
* @default 20
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
30
|
+
perPage?: number
|
|
31
|
+
/**
|
|
32
|
+
* The current page number
|
|
33
|
+
* @default 1
|
|
34
|
+
* @type {number}
|
|
35
|
+
*/
|
|
36
|
+
currentPage?: number
|
|
37
|
+
/**
|
|
38
|
+
* The results object returned from the search engine.
|
|
39
|
+
*/
|
|
40
|
+
results?: SearchResponse<Record<string, any>> // optional: the Meilisearch search response (defaults: {})
|
|
41
|
+
/**
|
|
42
|
+
* The hits object returned from the search engine.
|
|
43
|
+
*/
|
|
44
|
+
hits?: Hits<Record<string, any>>
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The search Filter Name
|
|
48
|
+
*/
|
|
49
|
+
filterName?: string
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The search filters
|
|
53
|
+
*/
|
|
54
|
+
filters?: object
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The next page value
|
|
58
|
+
*/
|
|
59
|
+
goToNextPage?: number
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Set to go to a specific page
|
|
63
|
+
*/
|
|
64
|
+
goToPage?: number
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set to go to the previous page
|
|
68
|
+
*/
|
|
69
|
+
goToPrevPage?: number
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The last page number value
|
|
73
|
+
*/
|
|
74
|
+
lastPageNumber?: number
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The searched term to use for the search
|
|
78
|
+
*/
|
|
79
|
+
search?: string
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The search params filters to use for the search
|
|
83
|
+
*/
|
|
84
|
+
searchFilters?: object
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The search params to use for the search
|
|
88
|
+
*/
|
|
89
|
+
searchParams?: object
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Total hits value to use for the search
|
|
93
|
+
*/
|
|
94
|
+
setTotalHits?: number
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The sort value to use for the search
|
|
98
|
+
*/
|
|
99
|
+
sort?: string
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The sorts value to use for the search
|
|
103
|
+
*/
|
|
104
|
+
sorts?: object
|
|
105
|
+
|
|
106
|
+
// table related config
|
|
107
|
+
// actionable?: string | boolean // optional: determines whether the table displays any "action items" (defaults: true)
|
|
108
|
+
// actions?: string | string[] // optional: the specific type of actions to be displayed/utilized in the table (defaults: 'Edit, Delete')
|
|
109
|
+
// columns: string[] // used as table heads/column titles
|
|
110
|
+
// selectable?: string | boolean // optional: determines whether the table displays the checkboxes (defaults: true)
|
|
111
|
+
// selectedRows?: number[] | string[] // optional: holds the selected rows (defaults: [])
|
|
112
|
+
// selectedAll?: boolean // optional: determines whether all the rows are selected (defaults: false)
|
|
113
|
+
// stickyHeader?: string | boolean // optional: determines whether the table displays the sticky header (defaults: false)
|
|
114
|
+
// stickyFooter?: string | boolean // optional: determines whether the table displays the sticky footer (defaults: false)
|
|
115
|
+
}
|