diff --git a/apps/desktop/src/components/meilisearch/MeilisearchDocumentsPage.vue b/apps/desktop/src/components/meilisearch/MeilisearchDocumentsPage.vue index a15366dd32..c12c8bc906 100644 --- a/apps/desktop/src/components/meilisearch/MeilisearchDocumentsPage.vue +++ b/apps/desktop/src/components/meilisearch/MeilisearchDocumentsPage.vue @@ -2,7 +2,7 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"; import type { Component } from "vue"; import { useI18n } from "vue-i18n"; -import { ArrowDown, ArrowUp, Braces, ChevronLeft, ChevronRight, Copy, Download, LayoutGrid, LoaderCircle, Pencil, Save, Search, Table2, Trash2 } from "@lucide/vue"; +import { ArrowDown, ArrowUp, Braces, ChevronDown, ChevronLeft, ChevronRight, Copy, Download, LayoutGrid, LoaderCircle, Pencil, Save, Search, Table2, Trash2, Upload } from "@lucide/vue"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; @@ -10,6 +10,7 @@ import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue"; import ErrorBanner from "@/components/ui/ErrorBanner.vue"; import QueryLoadingState from "@/components/common/QueryLoadingState.vue"; @@ -18,7 +19,7 @@ import RedisJsonEditor from "@/components/redis/RedisJsonEditor.vue"; import * as api from "@/lib/backend/api"; import { compactLocalTimestamp, sanitizeExportBaseName, saveTextFile } from "@/lib/export/saveTextFile"; import { parseDocumentStoreJsonDocument, serializeDocumentStoreId, stringifyDocumentStoreValue } from "@/lib/app/documentJsonValues"; -import { parseJsonPreservingLargeNumbers, safeJsonFormat } from "@/lib/common/safeJsonFormat"; +import { parseJsonPreservingLargeNumbers, safeJsonFormat, stringifyJsonPreservingLargeNumbers } from "@/lib/common/safeJsonFormat"; import { useToast } from "@/composables/useToast"; const props = defineProps<{ @@ -149,9 +150,15 @@ function renderMarkHtml(value: string): string { * user payload — no name-based stripping, so user fields named `_formatted` or * `_rankingScore` survive untouched. */ +const displayValueCache = new WeakMap>(); + function displayValue(hit: Hit): Record { + const cached = displayValueCache.get(hit); + if (cached) return cached; const formatted = hit?.formatted; - return formatted && typeof formatted === "object" ? { ...formatted } : { ...hit.document }; + const value = formatted && typeof formatted === "object" ? { ...formatted } : { ...hit.document }; + displayValueCache.set(hit, value); + return value; } /** Deep-remove `` search highlight tags to reconstruct the stored document. */ @@ -287,41 +294,96 @@ async function startEdit(hit: Hit) { /** Download every hit matching the current search as a JSON file of the stored documents. */ const exporting = ref(false); +const importing = ref(false); +const importFileInput = ref(null); const EXPORT_BATCH_SIZE = 1000; -async function exportResults() { - if (exporting.value || totalHits.value === 0) return; - if (q.value.trim() || hybridEnabled.value || rankingScoreThreshold.value > 0) { - toast(t("meilisearch.exportSearchUnsupported"), 5000); +type ExportScope = "filtered" | "all"; + +async function exportResults(scope: ExportScope) { + if (exporting.value) return; + if (scope === "filtered" && totalHits.value === 0) { + toast(t("grid.exportFailed", { message: t("meilisearch.empty") }), 5000); return; } exporting.value = true; try { + const useSearchPagination = scope === "filtered" && (q.value.trim() || hybridEnabled.value || rankingScoreThreshold.value > 0); + if (useSearchPagination && !indexSettingsLoaded.value) await loadIndexSettings(); + if (useSearchPagination && searchMaxTotalHits.value === null) { + throw new Error(t("meilisearch.exportSearchUnsupported")); + } const documents: Record[] = []; let batchOffset = 0; + let expectedTotal: number | undefined; while (true) { - const page = await api.meilisearchFetchDocuments(props.connectionId, props.index, { - filter: filter.value.trim() || null, - sort: sort.value.trim() || null, - limit: EXPORT_BATCH_SIZE, - offset: batchOffset, - }); - const batch = page.documents ?? []; + let batch: Record[]; + if (useSearchPagination) { + const page = await api.meilisearchSearchDocuments(props.connectionId, props.index, buildSearchParams(EXPORT_BATCH_SIZE, batchOffset)); + batch = (page.hits ?? []).map((hit) => hit.document); + expectedTotal = page.totalHits; + } else { + const page = await api.meilisearchFetchDocuments(props.connectionId, props.index, { + filter: scope === "filtered" ? filter.value.trim() || null : null, + sort: scope === "filtered" ? sort.value.trim() || null : null, + limit: EXPORT_BATCH_SIZE, + offset: batchOffset, + }); + batch = page.documents ?? []; + expectedTotal = page.total; + } documents.push(...batch); - if (batch.length < EXPORT_BATCH_SIZE) break; + if (batch.length === 0 || batch.length < EXPORT_BATCH_SIZE || (expectedTotal !== undefined && documents.length >= expectedTotal)) break; batchOffset += batch.length; } + const reachedSearchLimit = useSearchPagination && searchMaxTotalHits.value !== null && expectedTotal !== undefined && expectedTotal >= searchMaxTotalHits.value && documents.length >= searchMaxTotalHits.value; + if (useSearchPagination && expectedTotal !== undefined && (documents.length < expectedTotal || reachedSearchLimit)) { + toast(t("grid.exportFailed", { message: t("meilisearch.exportLimitReached", { count: documents.length, total: expectedTotal }) }), 5000); + return; + } + if (documents.length === 0) { + toast(t("grid.exportFailed", { message: t("meilisearch.empty") }), 5000); + return; + } const content = stringifyDocumentStoreValue(documents, "meilisearch", 2); const baseName = sanitizeExportBaseName(props.index) || "search-results"; - await saveTextFile(content, `${baseName}-${compactLocalTimestamp()}.json`, "JSON", "json"); + const saved = await saveTextFile(content, `${baseName}-${compactLocalTimestamp()}.json`, "JSON", "json"); + if (saved !== false) toast(t("grid.exported")); } catch (e: any) { - toast(e?.message || String(e), 5000); + toast(t("grid.exportFailed", { message: e?.message || String(e) }), 5000); } finally { exporting.value = false; } } +async function importDocuments(event: Event) { + const input = event.target as HTMLInputElement; + const file = input.files?.[0]; + input.value = ""; + if (!file) return; + importing.value = true; + try { + const parsed = parseJsonPreservingLargeNumbers(await file.text()); + const documents = Array.isArray(parsed) ? parsed : [parsed]; + if (!documents.length || documents.some((document) => !document || typeof document !== "object" || Array.isArray(document))) { + throw new Error(t("meilisearch.importInvalidJson")); + } + const batchSize = 100; + for (let offset = 0; offset < documents.length; offset += batchSize) { + const batch = documents.slice(offset, offset + batchSize).map((document) => stringifyJsonPreservingLargeNumbers(document)); + await api.documentSaveMeilisearchBatch(props.connectionId, props.index, [], [], batch); + } + toast(t("meilisearch.importSuccess", { count: documents.length })); + emit("refresh-stats"); + await runSearch(); + } catch (e: any) { + toast(t("meilisearch.importFailed", { message: e?.message || String(e) }), 5000); + } finally { + importing.value = false; + } +} + async function copyDocument(hit: Hit) { try { await navigator.clipboard.writeText(stringifyDocumentStoreValue(rawDocument(hit), "meilisearch", 2)); @@ -414,6 +476,8 @@ watch(autoRefresh, (enabled) => { /** Sortable attributes advertised by the index settings, for the sort picker. */ const sortableAttributes = ref([]); +const searchMaxTotalHits = ref(null); +const indexSettingsLoaded = ref(false); async function loadIndexSettings() { try { @@ -425,9 +489,14 @@ async function loadIndexSettings() { } const sortable = settings?.sortableAttributes; sortableAttributes.value = Array.isArray(sortable) ? sortable.filter((item): item is string => typeof item === "string") : []; + const maxTotalHits = settings?.pagination?.maxTotalHits; + searchMaxTotalHits.value = typeof maxTotalHits === "number" && Number.isFinite(maxTotalHits) ? maxTotalHits : null; } catch { // Settings discovery is best-effort; the sort/filter inputs stay free-form. sortableAttributes.value = []; + searchMaxTotalHits.value = null; + } finally { + indexSettingsLoaded.value = true; } } @@ -630,9 +699,25 @@ onBeforeUnmount(() => {
- + + + {{ t("meilisearch.exportFiltered") }} ({{ totalHits }}) + {{ t("meilisearch.exportAll") }} + + + + {{ resultSummary }}
diff --git a/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.export.spec.ts b/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.export.spec.ts index 3f24c0033d..fe6c264a6c 100644 --- a/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.export.spec.ts +++ b/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.export.spec.ts @@ -6,9 +6,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; const mocks = vi.hoisted(() => ({ searchDocuments: vi.fn(), fetchDocuments: vi.fn(), + saveMeilisearchBatch: vi.fn(), getIndexSettings: vi.fn(), saveTextFile: vi.fn(), toast: vi.fn(), + jsonTreeValues: [] as unknown[], })); function passthrough(tag: string): Component { @@ -27,6 +29,7 @@ vi.mock("@lucide/vue", () => ({ ArrowDown: passthrough("span"), ArrowUp: passthrough("span"), Braces: passthrough("span"), + ChevronDown: passthrough("span"), ChevronLeft: passthrough("span"), ChevronRight: passthrough("span"), Copy: passthrough("span"), @@ -38,6 +41,7 @@ vi.mock("@lucide/vue", () => ({ Search: passthrough("span"), Table2: passthrough("span"), Trash2: passthrough("span"), + Upload: passthrough("span"), })); vi.mock("@/components/ui/button", () => ({ Button: passthrough("button") })); vi.mock("@/components/ui/badge", () => ({ Badge: passthrough("span") })); @@ -57,10 +61,26 @@ vi.mock("@/components/ui/dialog", () => ({ DialogHeader: passthrough("div"), DialogTitle: passthrough("div"), })); +vi.mock("@/components/ui/dropdown-menu", () => ({ + DropdownMenu: passthrough("div"), + DropdownMenuContent: passthrough("div"), + DropdownMenuItem: passthrough("button"), + DropdownMenuTrigger: passthrough("div"), +})); vi.mock("@/components/editor/DangerConfirmDialog.vue", () => ({ default: passthrough("div") })); vi.mock("@/components/ui/ErrorBanner.vue", () => ({ default: passthrough("div") })); vi.mock("@/components/common/QueryLoadingState.vue", () => ({ default: passthrough("div") })); -vi.mock("@/components/common/JsonTree.vue", () => ({ default: passthrough("div") })); +vi.mock("@/components/common/JsonTree.vue", () => ({ + default: defineComponent({ + inheritAttrs: false, + setup(_, { attrs }) { + return () => { + mocks.jsonTreeValues.push(attrs.value); + return h("div", attrs); + }; + }, + }), +})); vi.mock("@/components/redis/RedisJsonEditor.vue", () => ({ default: passthrough("div") })); vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: mocks.toast }) })); vi.mock("@/lib/export/saveTextFile", () => ({ @@ -71,6 +91,7 @@ vi.mock("@/lib/export/saveTextFile", () => ({ vi.mock("@/lib/backend/api", () => ({ meilisearchSearchDocuments: mocks.searchDocuments, meilisearchFetchDocuments: mocks.fetchDocuments, + documentSaveMeilisearchBatch: mocks.saveMeilisearchBatch, meilisearchGetIndexSettings: mocks.getIndexSettings, })); @@ -90,9 +111,19 @@ afterEach(() => { app = undefined; root = undefined; vi.clearAllMocks(); + mocks.jsonTreeValues.length = 0; }); describe("MeilisearchDocumentsPage export", () => { + async function mountPage() { + root = document.createElement("div"); + document.body.append(root); + app = createApp(MeilisearchDocumentsPage, { connectionId: "c1", index: "movies" }); + app.mount(root); + await vi.waitFor(() => expect(mocks.searchDocuments).toHaveBeenCalledTimes(1)); + await nextTick(); + } + it("uses full-document pagination instead of capped displayed search hits", async () => { const batch = (size: number, from: number) => Array.from({ length: size }, (_, index) => ({ movie_id: from + index, title: `Movie ${from + index}`, internal_notes: `note ${from + index}` })); mocks.searchDocuments.mockResolvedValue({ @@ -106,19 +137,15 @@ describe("MeilisearchDocumentsPage export", () => { return Promise.resolve({ documents: [], total: 1300 }); }); - root = document.createElement("div"); - document.body.append(root); - app = createApp(MeilisearchDocumentsPage, { connectionId: "c1", index: "movies" }); - app.mount(root); - - await vi.waitFor(() => expect(mocks.searchDocuments).toHaveBeenCalledTimes(1)); - await nextTick(); + await mountPage(); const exportButton = Array.from(root.querySelectorAll("button")).find((button) => button.textContent?.includes("meilisearch.exportResults")); - expect(exportButton?.textContent).toContain("1000"); - exportButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })); + expect(exportButton).not.toBeUndefined(); + const filteredItem = Array.from(root.querySelectorAll("button")).find((button) => button.textContent?.includes("meilisearch.exportFiltered")); + filteredItem?.dispatchEvent(new Event("select", { bubbles: true })); await vi.waitFor(() => expect(mocks.saveTextFile).toHaveBeenCalledTimes(1)); + expect(mocks.toast).toHaveBeenCalledWith("grid.exported"); expect(mocks.searchDocuments).toHaveBeenCalledTimes(1); const offsets = mocks.fetchDocuments.mock.calls.map((call) => (call[2] as { offset: number }).offset); @@ -132,4 +159,77 @@ describe("MeilisearchDocumentsPage export", () => { expect(exported[0]).toEqual({ movie_id: 0, title: "Movie 0", internal_notes: "note 0" }); expect(exported[1299]).toEqual({ movie_id: 1299, title: "Movie 1299", internal_notes: "note 1299" }); }); + + it("keeps JSON tree values stable while export state changes", async () => { + mocks.searchDocuments.mockResolvedValue({ + hits: [{ id: 1, document: { movie_id: 1, details: { status: "ready" } } }], + totalHits: 1, + processingTimeMs: 1, + }); + mocks.fetchDocuments.mockResolvedValue({ documents: [{ movie_id: 1, details: { status: "ready" } }], total: 1 }); + + await mountPage(); + const beforeExport = mocks.jsonTreeValues.at(-1); + const filteredItem = Array.from(root!.querySelectorAll("button")).find((button) => button.textContent?.includes("meilisearch.exportFiltered")); + filteredItem?.dispatchEvent(new Event("select", { bubbles: true })); + + await vi.waitFor(() => expect(mocks.saveTextFile).toHaveBeenCalledTimes(1)); + expect(mocks.jsonTreeValues.some((value) => value === beforeExport)).toBe(true); + }); + + it("does not save an empty export file", async () => { + mocks.searchDocuments.mockResolvedValue({ + hits: [{ id: 1, document: { movie_id: 1 } }], + totalHits: 1, + processingTimeMs: 1, + }); + mocks.fetchDocuments.mockResolvedValue({ documents: [], total: 1 }); + + await mountPage(); + const filteredItem = Array.from(root!.querySelectorAll("button")).find((button) => button.textContent?.includes("meilisearch.exportFiltered")); + filteredItem?.dispatchEvent(new Event("select", { bubbles: true })); + + await vi.waitFor(() => expect(mocks.toast).toHaveBeenCalledWith("grid.exportFailed", 5000)); + expect(mocks.saveTextFile).not.toHaveBeenCalled(); + }); + + it("keeps all-document export available when the current filter has no hits", async () => { + mocks.searchDocuments.mockResolvedValue({ hits: [], totalHits: 0, processingTimeMs: 1 }); + mocks.fetchDocuments.mockResolvedValue({ documents: [{ movie_id: 1, title: "Movie 1" }], total: 1 }); + + await mountPage(); + const allItem = Array.from(root!.querySelectorAll("button")).find((button) => button.textContent?.includes("meilisearch.exportAll")); + expect(allItem).not.toBeUndefined(); + allItem?.dispatchEvent(new Event("select", { bubbles: true })); + + await vi.waitFor(() => expect(mocks.saveTextFile).toHaveBeenCalledTimes(1)); + expect(mocks.fetchDocuments.mock.calls[0]?.[2]).toMatchObject({ filter: null, sort: null, offset: 0 }); + }); + + it("imports JSON objects in write batches", async () => { + mocks.searchDocuments.mockResolvedValue({ hits: [], totalHits: 0, processingTimeMs: 1 }); + await mountPage(); + const fileInput = root!.querySelector('input[type="file"]'); + const file = new File([JSON.stringify([{ movie_id: 1 }, { movie_id: 2 }])], "movies.json", { type: "application/json" }); + Object.defineProperty(fileInput, "files", { value: [file] }); + fileInput?.dispatchEvent(new Event("change", { bubbles: true })); + + await vi.waitFor(() => expect(mocks.saveMeilisearchBatch).toHaveBeenCalledTimes(1)); + expect(mocks.saveMeilisearchBatch.mock.calls[0]?.[4]).toEqual([JSON.stringify({ movie_id: 1 }), JSON.stringify({ movie_id: 2 })]); + expect(mocks.toast).toHaveBeenCalledWith("meilisearch.importSuccess"); + }); + + it("imports decimal fields as raw JSON literals, not lossless number objects", async () => { + mocks.searchDocuments.mockResolvedValue({ hits: [], totalHits: 0, processingTimeMs: 1 }); + await mountPage(); + const fileInput = root!.querySelector('input[type="file"]'); + const file = new File([JSON.stringify([{ movie_id: 1, rating: 8.5 }])], "movies.json", { type: "application/json" }); + Object.defineProperty(fileInput, "files", { value: [file] }); + fileInput?.dispatchEvent(new Event("change", { bubbles: true })); + + await vi.waitFor(() => expect(mocks.saveMeilisearchBatch).toHaveBeenCalledTimes(1)); + const batch = mocks.saveMeilisearchBatch.mock.calls[0]?.[4] as string[]; + expect(batch).toEqual([JSON.stringify({ movie_id: 1, rating: 8.5 })]); + expect(JSON.parse(batch[0])).toEqual({ movie_id: 1, rating: 8.5 }); + }); }); diff --git a/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.identity.spec.ts b/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.identity.spec.ts index d324f7e82d..88e4004add 100644 --- a/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.identity.spec.ts +++ b/apps/desktop/src/components/meilisearch/__tests__/MeilisearchDocumentsPage.identity.spec.ts @@ -48,6 +48,7 @@ vi.mock("@lucide/vue", () => ({ ArrowDown: passthrough("span"), ArrowUp: passthrough("span"), Braces: passthrough("span"), + ChevronDown: passthrough("span"), ChevronLeft: passthrough("span"), ChevronRight: passthrough("span"), Copy: passthrough("span"), @@ -59,6 +60,7 @@ vi.mock("@lucide/vue", () => ({ Search: passthrough("span"), Table2: passthrough("span"), Trash2: passthrough("span"), + Upload: passthrough("span"), })); vi.mock("@/components/ui/button", () => ({ Button: passthrough("button") })); vi.mock("@/components/ui/badge", () => ({ Badge: passthrough("span") })); diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts index 470a48c419..1d466e6528 100644 --- a/apps/desktop/src/i18n/locales/az.ts +++ b/apps/desktop/src/i18n/locales/az.ts @@ -5593,6 +5593,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "Bal həddi", results: "Nəticələr", exportResults: "Nəticələri ixrac et", + exportFiltered: "Süzülmüş nəticələri ixrac et", + exportAll: "Bütün sənədləri ixrac et", + exportLimitReached: "Yalnız {count}/{total} nəticə əlçatandır; Meilisearch limiti tam ixraca mane olur.", + importResults: "JSON-u idxal et", + importSuccess: "{count} sənəd idxal edildi", + importFailed: "İdxal uğursuz oldu: {message}", + importInvalidJson: "JSON obyekt və ya obyektlər massivi olmalıdır", exportSearchUnsupported: "Meilisearch axtarış səhifələməsini məhdudlaşdırdığı üçün mətn, hibrid və ya bal həddinə görə axtarışlarda tam ixrac mümkün deyil. Süzgəcdən keçən bütün sənədləri ixrac etmək üçün həmin seçimləri təmizləyin.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts index 6679588d43..c0f52cdde4 100644 --- a/apps/desktop/src/i18n/locales/en.ts +++ b/apps/desktop/src/i18n/locales/en.ts @@ -5793,6 +5793,13 @@ export default { rankingScoreThreshold: "Score threshold", results: "Results", exportResults: "Export results", + exportFiltered: "Export filtered results", + exportAll: "Export all documents", + exportLimitReached: "Only {count} of {total} results are available; the Meilisearch limit prevents a complete export.", + importResults: "Import JSON", + importSuccess: "Imported {count} document(s)", + importFailed: "Import failed: {message}", + importInvalidJson: "JSON must contain an object or an array of objects", exportSearchUnsupported: "Full export is unavailable for text, hybrid, or score-threshold searches because Meilisearch caps search pagination. Clear those options to export every filtered document.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts index 08c69f712c..d650220754 100644 --- a/apps/desktop/src/i18n/locales/es.ts +++ b/apps/desktop/src/i18n/locales/es.ts @@ -5494,6 +5494,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "Umbral de puntuación", results: "Resultados", exportResults: "Exportar resultados", + exportFiltered: "Exportar resultados filtrados", + exportAll: "Exportar todos los documentos", + exportLimitReached: "Solo {count} de {total} resultados están disponibles; el límite de Meilisearch impide la exportación completa.", + importResults: "Importar JSON", + importSuccess: "Se importaron {count} documentos", + importFailed: "Error de importación: {message}", + importInvalidJson: "El JSON debe contener un objeto o una matriz de objetos", exportSearchUnsupported: "Meilisearch limita la paginación de búsquedas de texto, híbridas o con umbral de puntuación. Borre esas opciones para exportar todos los documentos filtrados.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts index a22a4224aa..82c52d9fb6 100644 --- a/apps/desktop/src/i18n/locales/it.ts +++ b/apps/desktop/src/i18n/locales/it.ts @@ -5491,6 +5491,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "Soglia del punteggio", results: "Risultati", exportResults: "Esporta risultati", + exportFiltered: "Esporta risultati filtrati", + exportAll: "Esporta tutti i documenti", + exportLimitReached: "Sono disponibili solo {count} risultati su {total}; il limite di Meilisearch impedisce l'esportazione completa.", + importResults: "Importa JSON", + importSuccess: "Importati {count} documenti", + importFailed: "Importazione non riuscita: {message}", + importInvalidJson: "Il JSON deve contenere un oggetto o un array di oggetti", exportSearchUnsupported: "Meilisearch limita la paginazione delle ricerche testuali, ibride o con soglia di punteggio. Rimuovi queste opzioni per esportare tutti i documenti filtrati.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts index 7bbbd41551..c0443833ba 100644 --- a/apps/desktop/src/i18n/locales/ja.ts +++ b/apps/desktop/src/i18n/locales/ja.ts @@ -5519,6 +5519,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "スコアしきい値", results: "検索結果", exportResults: "結果をエクスポート", + exportFiltered: "絞り込み結果をエクスポート", + exportAll: "すべてのドキュメントをエクスポート", + exportLimitReached: "{total} 件中 {count} 件のみ取得できました。Meilisearch の上限により完全なエクスポートはできません。", + importResults: "JSON をインポート", + importSuccess: "{count} 件のドキュメントをインポートしました", + importFailed: "インポートに失敗しました: {message}", + importInvalidJson: "JSON はオブジェクトまたはオブジェクトの配列である必要があります", exportSearchUnsupported: "Meilisearch はテキスト検索、ハイブリッド検索、スコアしきい値付き検索のページングを制限します。すべての絞り込み済みドキュメントを出力するには、これらの条件を解除してください。", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts index 4cc75f1a46..143d840699 100644 --- a/apps/desktop/src/i18n/locales/ko.ts +++ b/apps/desktop/src/i18n/locales/ko.ts @@ -5127,6 +5127,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "점수 임계값", results: "검색 결과", exportResults: "결과보내기", + exportFiltered: "필터링된 결과 내보내기", + exportAll: "모든 문서 내보내기", + exportLimitReached: "{total}개 중 {count}개의 결과만 사용할 수 있어 Meilisearch 제한으로 전체 내보내기를 완료할 수 없습니다.", + importResults: "JSON 가져오기", + importSuccess: "문서 {count}개를 가져왔습니다", + importFailed: "가져오기 실패: {message}", + importInvalidJson: "JSON은 객체 또는 객체 배열이어야 합니다", exportSearchUnsupported: "Meilisearch는 텍스트, 하이브리드 또는 점수 임계값 검색의 페이지 탐색을 제한합니다. 필터링된 모든 문서를 내보내려면 해당 옵션을 지우세요.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts index b90bc0caa2..e4a8ad317b 100644 --- a/apps/desktop/src/i18n/locales/pt-BR.ts +++ b/apps/desktop/src/i18n/locales/pt-BR.ts @@ -5493,6 +5493,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "Limite de pontuação", results: "Resultados", exportResults: "Exportar resultados", + exportFiltered: "Exportar resultados filtrados", + exportAll: "Exportar todos os documentos", + exportLimitReached: "Apenas {count} de {total} resultados estão disponíveis; o limite do Meilisearch impede a exportação completa.", + importResults: "Importar JSON", + importSuccess: "{count} documento(s) importado(s)", + importFailed: "Falha ao importar: {message}", + importInvalidJson: "O JSON deve conter um objeto ou uma matriz de objetos", exportSearchUnsupported: "O Meilisearch limita a paginação de buscas por texto, híbridas ou com limite de pontuação. Limpe essas opções para exportar todos os documentos filtrados.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts index f4e0c684b0..8f3ba843ca 100644 --- a/apps/desktop/src/i18n/locales/tr.ts +++ b/apps/desktop/src/i18n/locales/tr.ts @@ -5487,6 +5487,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "Puan eşiği", results: "Sonuçlar", exportResults: "Sonuçları dışa aktar", + exportFiltered: "Filtrelenmiş sonuçları dışa aktar", + exportAll: "Tüm belgeleri dışa aktar", + exportLimitReached: "{total} sonuçtan yalnızca {count} tanesi kullanılabilir; Meilisearch sınırı tam dışa aktarmayı engelliyor.", + importResults: "JSON içe aktar", + importSuccess: "{count} belge içe aktarıldı", + importFailed: "İçe aktarma başarısız: {message}", + importInvalidJson: "JSON bir nesne veya nesne dizisi içermelidir", exportSearchUnsupported: "Meilisearch arama sayfalamasını sınırladığı için metin, karma veya puan eşikli aramalarda tam dışa aktarma kullanılamaz. Filtrelenen tüm belgeleri dışa aktarmak için bu seçenekleri temizleyin.", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts index 278db4a70d..94f8db3040 100644 --- a/apps/desktop/src/i18n/locales/zh-CN.ts +++ b/apps/desktop/src/i18n/locales/zh-CN.ts @@ -5766,6 +5766,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "分数阈值", results: "搜索结果", exportResults: "导出结果", + exportFiltered: "导出筛选结果", + exportAll: "导出全部结果", + exportLimitReached: "只能获取 {count}/{total} 条结果,Meilisearch 限制导致无法完整导出。", + importResults: "导入 JSON", + importSuccess: "已导入 {count} 个文档", + importFailed: "导入失败:{message}", + importInvalidJson: "JSON 必须是对象或对象数组", exportSearchUnsupported: "Meilisearch 会限制文本、混合或分数阈值搜索的分页,无法保证完整导出。请清除这些选项后导出全部筛选文档。", }, dynamodb: { diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts index bd0817e35d..8c44bbbf00 100644 --- a/apps/desktop/src/i18n/locales/zh-TW.ts +++ b/apps/desktop/src/i18n/locales/zh-TW.ts @@ -4813,6 +4813,13 @@ export default withEnglishFallback({ rankingScoreThreshold: "分數閾值", results: "搜尋結果", exportResults: "匯出結果", + exportFiltered: "匯出篩選結果", + exportAll: "匯出全部文件", + exportLimitReached: "只能取得 {count}/{total} 筆結果;Meilisearch 限制導致無法完整匯出。", + importResults: "匯入 JSON", + importSuccess: "已匯入 {count} 份文件", + importFailed: "匯入失敗:{message}", + importInvalidJson: "JSON 必須是物件或物件陣列", exportSearchUnsupported: "Meilisearch 會限制文字、混合或分數閾值搜尋的分頁,無法保證完整匯出。請清除這些選項後匯出全部篩選文件。", }, dynamodb: { diff --git a/apps/desktop/src/lib/export/saveTextFile.ts b/apps/desktop/src/lib/export/saveTextFile.ts index 8d59bfca3e..a63c754524 100644 --- a/apps/desktop/src/lib/export/saveTextFile.ts +++ b/apps/desktop/src/lib/export/saveTextFile.ts @@ -1,7 +1,7 @@ import { isTauriRuntime } from "@/lib/backend/tauriRuntime"; import { appendDebugLog, getBrowserMemorySnapshot, isDebugLoggingEnabled } from "@/lib/backend/debugLog"; -export async function saveTextFile(content: string, defaultFileName: string, filterName: string, filterExt: string, diagnostics: { exportId?: string; operation?: string } = {}) { +export async function saveTextFile(content: string, defaultFileName: string, filterName: string, filterExt: string, diagnostics: { exportId?: string; operation?: string } = {}): Promise { const logSaveStage = (stage: string, details: Record = {}) => { if (!isDebugLoggingEnabled()) return; appendDebugLog("info", `[DBX][export:save:${stage}]`, { @@ -25,7 +25,7 @@ export async function saveTextFile(content: string, defaultFileName: string, fil logSaveStage("dialog-result", { selected: !!path }); if (path) await writeTextFile(path, content); if (path) logSaveStage("write-done"); - return; + return Boolean(path); } const blob = new Blob([content], { type: "text/plain;charset=utf-8" }); @@ -36,6 +36,7 @@ export async function saveTextFile(content: string, defaultFileName: string, fil a.click(); URL.revokeObjectURL(url); logSaveStage("browser-download-triggered"); + return true; } export function sanitizeExportBaseName(value: string): string { diff --git a/crates/dbx-drivers/src/db/meilisearch_driver.rs b/crates/dbx-drivers/src/db/meilisearch_driver.rs index ef52327eff..9e17e94f8f 100644 --- a/crates/dbx-drivers/src/db/meilisearch_driver.rs +++ b/crates/dbx-drivers/src/db/meilisearch_driver.rs @@ -296,7 +296,6 @@ fn meilisearch_fetch_body( let mut body = Map::new(); body.insert("offset".to_string(), Value::Number(offset.into())); body.insert("limit".to_string(), Value::Number(limit.into())); - body.insert("fields".to_string(), Value::Array(vec![Value::String("*".to_string())])); if let Some(filter) = meilisearch_filter_from_request(filter, primary_key)? { body.insert("filter".to_string(), filter); } @@ -936,6 +935,9 @@ fn meilisearch_search_body( } body.insert("offset".to_string(), Value::Number(offset.into())); body.insert("limit".to_string(), Value::Number(limit.into())); + // Search results are also used for filtered export. Request the complete + // stored document instead of the index's displayed-attributes subset. + body.insert("attributesToRetrieve".to_string(), Value::Array(vec![Value::String("*".to_string())])); if let Some(filter) = meilisearch_filter_from_request(filter, primary_key)? { body.insert("filter".to_string(), filter); } @@ -2403,7 +2405,10 @@ mod tests { super::meilisearch_fetch_body(0, 1000, Some(r#"genre = "sci-fi""#), Some("movie_id:asc"), Some("movie_id")) .unwrap(); - assert_eq!(body.get("fields"), Some(&json!(["*"]))); + // Omitting `fields` asks Meilisearch to return every stored field. + // A wildcard field is treated as a literal field name by some versions + // and produces `{}` documents in the export response. + assert!(!body.contains_key("fields")); assert_eq!(body.get("limit"), Some(&json!(1000))); assert_eq!(body.get("offset"), Some(&json!(0))); }