@stacksjs/search-engine 0.65.0 → 0.67.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.
@@ -1 +0,0 @@
1
- export * as meilisearch from './meilisearch'
@@ -1,124 +0,0 @@
1
- // import process from 'node:process'
2
- // import { searchEngine } from '@stacksjs/config'
3
- // import { log } from '@stacksjs/logging'
4
- // import type { MeilisearchOptions, SearchEngineDriver } from '@stacksjs/types'
5
- // import { ExitCode } from '@stacksjs/types'
6
- // import type { DocumentOptions, EnqueuedTask, Index, IndexOptions, IndexesResults, SearchResponse } from 'meilisearch'
7
- // import { Meilisearch } from 'meilisearch'
8
- //
9
- // function client(options?: MeilisearchOptions) {
10
- // let host = searchEngine.meilisearch?.host
11
- // let apiKey = searchEngine.meilisearch?.apiKey
12
- //
13
- // if (options?.host)
14
- // host = options.host
15
- //
16
- // if (options?.apiKey)
17
- // apiKey = options.apiKey
18
- //
19
- // if (!host) {
20
- // log.error('Please specify a search engine host.')
21
- // process.exit(ExitCode.FatalError)
22
- // }
23
- //
24
- // return new MeiliSearch({ host, apiKey })
25
- // }
26
- //
27
- // async function search(index: string, params: any): Promise<SearchResponse<Record<string, any>>> {
28
- // const offsetVal = ((params.page * params.perPage) - 20) || 0
29
- // const filter = convertToFilter(params.filter)
30
- // const sort = convertToMeilisearchSorting(params.sort)
31
- //
32
- // return await client()
33
- // .index(index)
34
- // .search(params.query, { limit: params.perPage, filter, sort, offset: offsetVal })
35
- // }
36
- //
37
- // async function addDocument(indexName: string, params: any): Promise<EnqueuedTask> {
38
- // return await client().index(indexName).addDocuments([params])
39
- // }
40
- //
41
- // async function addDocuments(indexName: string, params: any[]): Promise<EnqueuedTask> {
42
- // return await client().index(indexName).addDocuments(params)
43
- // }
44
- //
45
- // async function createIndex(name: string, options?: IndexOptions): Promise<EnqueuedTask> {
46
- // return await client().createIndex(name, options)
47
- // }
48
- //
49
- // async function updateIndex(indexName: string, params: IndexOptions): Promise<EnqueuedTask> {
50
- // return await client().updateIndex(indexName, params)
51
- // }
52
- //
53
- // async function updateDocument(indexName: string, params: DocumentOptions): Promise<EnqueuedTask> {
54
- // return await client().index(indexName).updateDocuments([params])
55
- // }
56
- //
57
- // async function updateDocuments(indexName: string, params: DocumentOptions[]): Promise<EnqueuedTask> {
58
- // return await client().index(indexName).updateDocuments(params)
59
- // }
60
- //
61
- // async function deleteDocument(indexName: string, id: number): Promise<EnqueuedTask> {
62
- // return await client().index(indexName).deleteDocument(id)
63
- // }
64
- //
65
- // async function deleteDocuments(indexName: string, filters: string | string[]): Promise<EnqueuedTask> {
66
- // return await client().index(indexName).deleteDocuments({ filter: filters })
67
- // }
68
- //
69
- // async function getDocument(indexName: string, id: number, fields: any): Promise<EnqueuedTask> {
70
- // return await client().index(indexName).getDocument(id, fields)
71
- // }
72
- //
73
- // async function deleteIndex(indexName: string): Promise<EnqueuedTask> {
74
- // return await client().deleteIndex(indexName)
75
- // }
76
- //
77
- // async function listAllIndexes(): Promise<IndexesResults<Index[]>> {
78
- // return await client().getIndexes()
79
- // }
80
- //
81
- // function convertToFilter(jsonData: any): string[] {
82
- // const filters: string[] = []
83
- //
84
- // for (const key in jsonData) {
85
- // if (Object.prototype.hasOwnProperty.call(jsonData, key)) {
86
- // const value = jsonData[key]
87
- // const filter = `${key}='${value}'`
88
- // filters.push(filter)
89
- // }
90
- // }
91
- //
92
- // return filters
93
- // }
94
- //
95
- // function convertToMeilisearchSorting(jsonData: any): string[] {
96
- // const filters: string[] = []
97
- //
98
- // for (const key in jsonData) {
99
- // if (Object.prototype.hasOwnProperty.call(jsonData, key)) {
100
- // const value = jsonData[key]
101
- // const filter = `${key}='${value}'`
102
- // filters.push(filter)
103
- // }
104
- // }
105
- //
106
- // return filters
107
- // }
108
- //
109
- // export default {
110
- // client,
111
- // search,
112
- // createIndex,
113
- // deleteIndex,
114
- // updateIndex,
115
- // listAllIndexes,
116
- // addDocument,
117
- // addDocuments,
118
- // updateDocument,
119
- // listAllIndices: listAllIndexes,
120
- // updateDocuments,
121
- // deleteDocument,
122
- // deleteDocuments,
123
- // getDocument,
124
- // } satisfies SearchEngineDriver
@@ -1,59 +0,0 @@
1
- // import { searchEngine } from '@stacksjs/config'
2
- // import type { ApiResponse } from '@opensearch-project/opensearch'
3
- // import { Client } from '@opensearch-project/opensearch'
4
- // import type { SearchEngineDriver } from '@stacksjs/types'
5
- //
6
- // const host = searchEngine.openSearch?.host
7
- // const protocol = searchEngine.openSearch?.protocol
8
- // const port = searchEngine.openSearch?.port
9
- // const auth = searchEngine.openSearch?.auth
10
- //
11
- // const client = new Client({
12
- // node: `${protocol}://${auth}@${host}:${port}`,
13
- // })
14
- //
15
- // async function search(index: string, params?: any) {
16
- // const response = await client.search({
17
- // index,
18
- // body: params.query,
19
- // })
20
- //
21
- // return response
22
- // }
23
- //
24
- // async function createIndex(indexName: string, settings?: any): Promise<ApiResponse<any, any>> {
25
- // return await client.indices.create({ index: indexName, body: settings })
26
- // }
27
- // // async function updateIndex(indexName: string, settings?: any): Promise<ApiResponse<any, any>> {
28
- // // return await client.indices.update({ index: indexName, body: settings })
29
- // // }
30
- //
31
- // async function deleteIndex(indexName: string): Promise<ApiResponse<any, any>> {
32
- // return await client.indices.delete({ index: indexName })
33
- // }
34
- //
35
- // async function addDocument(indexName: string, document: any): Promise<ApiResponse<any, any>> {
36
- // return await client.index({
37
- // id: document.id,
38
- // index: indexName,
39
- // body: document,
40
- // refresh: true,
41
- // })
42
- // }
43
- //
44
- // async function deleteDocument(indexName: string, document: any): Promise<ApiResponse<any, any>> {
45
- // return await client.delete({
46
- // id: document.id,
47
- // index: indexName,
48
- // })
49
- // }
50
- //
51
- // export default {
52
- // client,
53
- // search,
54
- // createIndex,
55
- // deleteIndex,
56
- // addDocument,
57
- // deleteDocument,
58
- // // ...other methods
59
- // } satisfies SearchEngineDriver
package/src/helpers.ts DELETED
@@ -1,27 +0,0 @@
1
- /**
2
- * This file is used to define the types/interfaces used in the project.
3
- */
4
-
5
- import type { SearchEngineStore } from './types'
6
-
7
- // import { isString } from '@stacksjs/validation'
8
-
9
- export function isString(val: unknown): val is string {
10
- return typeof val === 'string'
11
- }
12
-
13
- export function determineState(): SearchEngineStore {
14
- const ls = localStorage.getItem('search-engine')
15
-
16
- if (isString(ls))
17
- return JSON.parse(ls) as SearchEngineStore
18
-
19
- return {
20
- // default state
21
- source: 'http://127.0.0.1:7700',
22
- index: '',
23
- perPage: 20,
24
- currentPage: 1,
25
- query: '',
26
- }
27
- }
package/src/index.ts DELETED
@@ -1,69 +0,0 @@
1
- import type { UiEngine } from '@stacksjs/ui'
2
- import { useStorage } from '@stacksjs/utils'
3
- import { computed, type ComputedRef, type Ref, ref } from 'vue'
4
-
5
- // import { client as meilisearch } from './drivers/meilisearch'
6
- import { determineState } from './helpers'
7
-
8
- // import type { Ref } from '@stacksjs/types'
9
-
10
- const table = useStorage('table', determineState()).value
11
- const totalHits = table.results?.estimatedTotalHits ?? 1
12
-
13
- // state
14
- const pages: UiEngine.Ref<number[]> = ref([])
15
- export const totalPages: Ref = ref(0)
16
- export const currentPage: ComputedRef = computed(() => table.currentPage)
17
- export const filterName: ComputedRef = computed(() => table.filterName)
18
-
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
-
35
- export function client(): string {
36
- // if (searchEngine.driver === 'meilisearch')
37
- // return meilisearch
38
- return 'wip-search-me'
39
- }
40
-
41
- export function useSearchEngine(): string {
42
- return client()
43
- }
44
-
45
- export function calculatePagination(): void {
46
- if (table.perPage)
47
- totalPages.value = Math.ceil(totalHits / table.perPage)
48
-
49
- const hitPages = Array.from({ length: totalPages.value }, (_, i) => i + 1)
50
- const offset = 2
51
- const currentPage = table.currentPage ?? 1
52
- const lastPage = hitPages[hitPages.length - 1]
53
-
54
- let from = currentPage - offset
55
- if (from < 1)
56
- from = 1
57
-
58
- let to = from + offset * 2
59
- if (to >= (lastPage as number))
60
- to = lastPage as number
61
-
62
- const allPages = []
63
- for (let page = from; page <= to; page++) allPages.push(page)
64
-
65
- pages.value = allPages
66
- }
67
-
68
- // it needs these exports
69
- // currentPage, filterName, filters, goToNextPage, goToPage, goToPrevPage, hits, index, lastPageNumber, perPage, query, results, search, searchFilters, searchParams, setTotalHits, sort, sorts, totalPages
package/src/types.ts DELETED
@@ -1,115 +0,0 @@
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
- }