diff --git a/app/components/searchPanel/SearchPanel.vue b/app/components/searchPanel/SearchPanel.vue index 0439436..046c857 100644 --- a/app/components/searchPanel/SearchPanel.vue +++ b/app/components/searchPanel/SearchPanel.vue @@ -140,6 +140,7 @@ const colors = computed(() => { // ---- State ---------------------------------------------------------------- const exactSearch = ref(false) +const sortMode = ref<'relevance' | 'date'>('relevance') const groupedHits = ref([]) const total = ref(0) @@ -254,6 +255,8 @@ async function runSearch(q: string, page = 1, append = false) { const typePage = isInfinite ? (append ? currentPage.value + 1 : 1) : page try { + const shouldSortByDate = sortMode.value === 'date' && q.trim() + const multi = await documentsApi.multiSearch({ multiSearchParameters: {}, multiSearchSearchesParameter: { @@ -262,6 +265,7 @@ async function runSearch(q: string, page = 1, append = false) { q: exactSearch.value && q ? `"${q}"` : q || '*', queryBy: QUERY_BY, filterBy: filterBy.value, + ...(shouldSortByDate ? { sortBy: `$${props.mainCollection}(timestamp:desc)` } : {}), perPage: settings.pageSize, page: typePage, highlightFullFields: QUERY_BY, @@ -428,6 +432,15 @@ watch(exactSearch, () => { if (query.value.trim()) runSearch(query.value, 1, false) }) +watch(sortMode, () => { + if (query.value.trim()) { + groupedHits.value = [] + total.value = 0 + currentPage.value = 1 + runSearch(query.value, 1, false) + } +}) + // ---- Selección y carga del detalle ---------------------------------------- const selectedDocId = ref(null) @@ -607,6 +620,18 @@ function metaLocation(meta: DocMeta | undefined): string { >{{ t('search.phrase') }} +
+ +