v3 : socle Rust (moteur pur, accès trustinWallet, serveur) ; maquette Nuxt rangée dans maquette/
- crates/ld-engine : formule inertielle (parité avec la maquette, garde C), coquille / changement de fond, assistant d'édition à règles, composition d'un document sous vote permanent (adoptions, aperçus, rivales). - crates/trustin-access : qui voit, qui ouvre, qui gère les accès. - crates/ld-server : API axum + SQLite, connexion Ğ1 (client OAuth2 de connect.monnaie-libre.fr), invitations, entrée en vigueur automatique, signalements de contradiction, traductions éditoriales, publication git, taille de la toile lue sur la chaîne. - seeds/acte-engagement-certification.json : 33 articles, fr + en + es ; en vigueur : préambule, E1, E2 (seed a minima). - maquette/ : frontend, backend et docker v2 déplacés tels quels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* The ONE search index — Cmd+K AND Q0 « déjà décidé ? » (same index, by
|
||||
* doctrine): clauses (code + title), decisions (title), mandates (title).
|
||||
* Case- and accent-insensitive. Pure selector over the collective store.
|
||||
*
|
||||
* EXPLICIT imports (no Nuxt auto-imports) — testable under plain vitest.
|
||||
*/
|
||||
|
||||
import type { Id } from '../types/domain'
|
||||
import { STATUS_LABELS } from '../lexicon'
|
||||
import { useCollectiveStore } from '../stores/collective'
|
||||
|
||||
export interface SearchHit {
|
||||
kind: 'clause' | 'decision' | 'mandate'
|
||||
id: Id
|
||||
label: string
|
||||
sublabel: string
|
||||
}
|
||||
|
||||
const MAX_HITS = 20
|
||||
|
||||
/** Case/accent-insensitive folding (same folding as the stores). */
|
||||
function fold(text: string): string {
|
||||
return text.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase()
|
||||
}
|
||||
|
||||
export function useSearch() {
|
||||
const col = useCollectiveStore()
|
||||
|
||||
/** Search the unique index. Empty (or blank) query ⇒ no hit. */
|
||||
const search = (query: string): SearchHit[] => {
|
||||
const needle = fold(query.trim())
|
||||
if (needle.length === 0) return []
|
||||
const hits: SearchHit[] = []
|
||||
|
||||
for (const clause of col.clauses) {
|
||||
if (hits.length >= MAX_HITS) break
|
||||
if (fold(clause.code).includes(needle) || fold(clause.title).includes(needle)) {
|
||||
const doc = col.docs.find(d => d.id === clause.docId)
|
||||
hits.push({
|
||||
kind: 'clause',
|
||||
id: clause.id,
|
||||
label: `${clause.code} — ${clause.title}`,
|
||||
sublabel: doc?.title ?? '',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (const decision of col.decisions) {
|
||||
if (hits.length >= MAX_HITS) break
|
||||
if (fold(decision.title).includes(needle)) {
|
||||
hits.push({
|
||||
kind: 'decision',
|
||||
id: decision.id,
|
||||
label: decision.title,
|
||||
sublabel: STATUS_LABELS[decision.status],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (const mandate of col.mandates) {
|
||||
if (hits.length >= MAX_HITS) break
|
||||
if (fold(mandate.title).includes(needle)) {
|
||||
const holder = col.people.find(p => p.id === mandate.holderId)
|
||||
hits.push({
|
||||
kind: 'mandate',
|
||||
id: mandate.id,
|
||||
label: mandate.title,
|
||||
sublabel: holder?.displayName ?? '',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return hits
|
||||
}
|
||||
|
||||
return { search }
|
||||
}
|
||||
Reference in New Issue
Block a user