add most resent code

This commit is contained in:
Esteban 2026-06-04 18:42:56 -05:00
parent b356a0bea3
commit 07bddf5eb9
5 changed files with 44 additions and 3 deletions

View File

@ -140,6 +140,7 @@ const colors = computed(() => {
// ---- State ---------------------------------------------------------------- // ---- State ----------------------------------------------------------------
const exactSearch = ref(false) const exactSearch = ref(false)
const sortMode = ref<'relevance' | 'date'>('relevance')
const groupedHits = ref<SearchGroup[]>([]) const groupedHits = ref<SearchGroup[]>([])
const total = ref(0) 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 const typePage = isInfinite ? (append ? currentPage.value + 1 : 1) : page
try { try {
const shouldSortByDate = sortMode.value === 'date' && q.trim()
const multi = await documentsApi.multiSearch({ const multi = await documentsApi.multiSearch({
multiSearchParameters: {}, multiSearchParameters: {},
multiSearchSearchesParameter: { multiSearchSearchesParameter: {
@ -262,6 +265,7 @@ async function runSearch(q: string, page = 1, append = false) {
q: exactSearch.value && q ? `"${q}"` : q || '*', q: exactSearch.value && q ? `"${q}"` : q || '*',
queryBy: QUERY_BY, queryBy: QUERY_BY,
filterBy: filterBy.value, filterBy: filterBy.value,
...(shouldSortByDate ? { sortBy: `$${props.mainCollection}(timestamp:desc)` } : {}),
perPage: settings.pageSize, perPage: settings.pageSize,
page: typePage, page: typePage,
highlightFullFields: QUERY_BY, highlightFullFields: QUERY_BY,
@ -428,6 +432,15 @@ watch(exactSearch, () => {
if (query.value.trim()) runSearch(query.value, 1, false) 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 ---------------------------------------- // ---- Selección y carga del detalle ----------------------------------------
const selectedDocId = ref<string | null>(null) const selectedDocId = ref<string | null>(null)
@ -607,6 +620,18 @@ function metaLocation(meta: DocMeta | undefined): string {
>{{ t('search.phrase') }}</button> >{{ t('search.phrase') }}</button>
</div> </div>
</div> </div>
<div class="px-4 sm:px-6 py-3">
<USelect
v-if="query.trim()"
v-model="sortMode"
:items="[
{ label: t('search.sort.relevance'), value: 'relevance' },
{ label: t('search.sort.date'), value: 'date' }
]"
size="sm"
class="shrink-0 min-w-[130px]"
/>
</div>
<UAlert <UAlert
v-if="errorMsg" v-if="errorMsg"

View File

@ -13,6 +13,10 @@
"changelog": "What's New" "changelog": "What's New"
}, },
"search": { "search": {
"sort": {
"relevance": "Normal",
"date": "Most recent"
},
"word": "Word", "word": "Word",
"phrase": "Phrase", "phrase": "Phrase",
"placeholder": "Search for...", "placeholder": "Search for...",

View File

@ -55,6 +55,10 @@
"hits_per_page": "aciertos por página", "hits_per_page": "aciertos por página",
"hits_retrieved_in": "aciertos logrados en", "hits_retrieved_in": "aciertos logrados en",
"for": "Buscando", "for": "Buscando",
"sort": {
"relevance": "Normal",
"date": "Más recientes"
},
"word": "Palabra", "word": "Palabra",
"phrase": "Frase", "phrase": "Frase",
"words": "palabras", "words": "palabras",

View File

@ -13,6 +13,10 @@
"changelog": "Nouveautés" "changelog": "Nouveautés"
}, },
"search": { "search": {
"sort": {
"relevance": "Normal",
"date": "Plus récents"
},
"word": "Mot", "word": "Mot",
"phrase": "Phrase", "phrase": "Phrase",
"placeholder": "Rechercher des activités", "placeholder": "Rechercher des activités",

View File

@ -13,6 +13,10 @@
"changelog": "Novidades" "changelog": "Novidades"
}, },
"search": { "search": {
"sort": {
"relevance": "Normal",
"date": "Mais recentes"
},
"word": "Palavra", "word": "Palavra",
"phrase": "Frase", "phrase": "Frase",
"placeholder": "Digite para pesquisar...", "placeholder": "Digite para pesquisar...",