Skip to content

Commit 46ebcc9

Browse files
chore: wip
1 parent c7f6a77 commit 46ebcc9

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

storage/framework/core/actions/src/search/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import process from 'node:process'
22
import { log } from '@stacksjs/logging'
3-
import { createStripeProduct } from '@stacksjs/payments'
3+
import { importModelDocuments } from '@stacksjs/search-engine'
44

5-
const result = await createStripeProduct()
5+
const result = await importModelDocuments()
66

77
if (result?.isErr()) {
88
console.error(result.error)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getTableName } from '@stacksjs/orm'
2+
import { path } from '@stacksjs/path'
3+
import { useSearchEngine } from '@stacksjs/search-engine'
4+
import { globSync } from '@stacksjs/storage'
5+
6+
async function importModelDocuments() {
7+
const userModelFiles = globSync([path.userModelsPath('*.ts')], { absolute: true })
8+
const { addDocument } = useSearchEngine()
9+
10+
for (const userModel of userModelFiles) {
11+
const modelInstance = (await import(userModel)).default
12+
13+
const tableName = getTableName(modelInstance, userModel)
14+
15+
const documents = modelInstance.all()
16+
17+
for (const document of documents) {
18+
await addDocument(tableName, document)
19+
}
20+
}
21+
22+
23+
24+
}

storage/framework/core/search-engine/src/drivers/meilisearch.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ async function listAllIndexes(): Promise<IndexesResults<Index[]>> {
9797

9898
// return filters
9999
// }
100-
101-
export default {
100+
const meilisearch: SearchEngineDriver = {
102101
client,
103102
// search,
104103
createIndex,
@@ -113,4 +112,7 @@ export default {
113112
deleteDocument,
114113
deleteDocuments,
115114
getDocument,
116-
} satisfies SearchEngineDriver
115+
}
116+
117+
118+
export default meilisearch

storage/framework/core/search-engine/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import type { UiEngine } from '@stacksjs/ui'
22
import { useStorage } from '@stacksjs/utils'
33
import { computed, type ComputedRef, type Ref, ref } from 'vue'
44

5-
// import { client as meilisearch } from './drivers/meilisearch'
5+
import meilisearch from './drivers/meilisearch'
6+
67
import { determineState } from './helpers'
8+
import type { SearchEngineDriver } from '@stacksjs/types'
79

810
// import type { Ref } from '@stacksjs/types'
911

@@ -32,13 +34,11 @@ export const setTotalHits: ComputedRef = computed(() => table.setTotalHits)
3234
export const sort: ComputedRef = computed(() => table.sort)
3335
export const sorts: ComputedRef = computed(() => table.sorts)
3436

35-
function client(): string {
36-
// if (searchEngine.driver === 'meilisearch')
37-
// return meilisearch
38-
return 'wip-search-me'
37+
function client(): any {
38+
return meilisearch
3939
}
4040

41-
export function useSearchEngine(): string {
41+
export function useSearchEngine(): SearchEngineDriver {
4242
return client()
4343
}
4444

0 commit comments

Comments
 (0)