Commit 2c8788b8 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Index documents by uid.

parent 62709864
Pipeline #98926 failed with stage
in 1 minute and 15 seconds
......@@ -8,6 +8,7 @@ use organes::Organe;
use scrutins;
use std::collections::HashMap;
use std::mem;
use textes_legislatifs::Document;
pub struct Context {
pub acteur_by_uid: HashMap<String, *const Acteur>,
......@@ -15,6 +16,7 @@ pub struct Context {
pub agendas_wrappers: Vec<agendas::AgendaJsonWrapper>,
pub amendement_by_uid: HashMap<String, *const Amendement>,
pub amendements_wrappers: Vec<amendements::AmendementsJsonWrapper>,
pub document_by_uid: HashMap<String, *const Document>,
pub dossier_parlementaire_by_segment: HashMap<String, *const DossierParlementaire>,
pub dossier_parlementaire_by_signet_senat: HashMap<String, *const DossierParlementaire>,
pub dossier_parlementaire_by_uid: HashMap<String, *const DossierParlementaire>,
......@@ -40,6 +42,14 @@ impl Context {
})
}
pub fn get_document_at_uid(&self, uid: &str) -> Option<&Document> {
self.document_by_uid
.get(&uid.to_string())
.map(|document| unsafe {
mem::transmute::<*const Document, &Document>(*document)
})
}
pub fn get_dossier_parlementaire_at_segment(
&self,
segment: &str,
......
......@@ -272,6 +272,8 @@ pub fn load(
}
}
let mut document_by_uid: HashMap<String, *const Document> =
HashMap::new();
let mut dossier_parlementaire_by_segment: HashMap<String, *const DossierParlementaire> =
HashMap::new();
let mut dossier_parlementaire_by_signet_senat: HashMap<String, *const DossierParlementaire> =
......@@ -283,6 +285,13 @@ pub fn load(
Regex::new(r"^https?://www.senat.fr/dossier-legislatif/(.*).html$").unwrap();
}
for wrapper in &dossiers_legislatifs_wrappers {
for document in &wrapper.export.textes_legislatifs.documents {
document_by_uid.insert(
document.uid().to_string(),
document,
);
}
for dossier in &wrapper.export.dossiers_legislatifs.dossiers {
let dossier_parlementaire = &dossier.dossier_parlementaire;
let titre_dossier = dossier_parlementaire.titre_dossier();
......@@ -353,6 +362,7 @@ pub fn load(
agendas_wrappers,
amendement_by_uid,
amendements_wrappers,
document_by_uid,
dossier_parlementaire_by_segment,
dossier_parlementaire_by_signet_senat,
dossier_parlementaire_by_uid,
......
......@@ -200,7 +200,7 @@ pub enum Document {
TexteLoi(TexteLoi),
}
// impl Document {
impl Document {
// pub fn auteurs(&self) -> &AuteursLeg {
// match *self {
// Document::AccordInternational(AccordInternational { ref auteurs, .. })
......@@ -392,16 +392,16 @@ pub enum Document {
// }
// }
// pub fn uid(&self) -> &str {
// match *self {
// Document::AccordInternational(AccordInternational { ref uid, .. })
// | Document::AvisConseilEtat(AvisConseilEtat { ref uid, .. })
// | Document::DocumentEtudeImpact(DocumentEtudeImpact { ref uid, .. })
// | Document::RapportParlementaire(RapportParlementaire { ref uid, .. })
// | Document::TexteLoi(TexteLoi { ref uid, .. }) => &uid,
// }
// }
// }
pub fn uid(&self) -> &str {
match *self {
Document::AccordInternational(AccordInternational { ref uid, .. })
| Document::AvisConseilEtat(AvisConseilEtat { ref uid, .. })
| Document::DocumentEtudeImpact(DocumentEtudeImpact { ref uid, .. })
| Document::RapportParlementaire(RapportParlementaire { ref uid, .. })
| Document::TexteLoi(TexteLoi { ref uid, .. }) => &uid,
}
}
}
// Using graphql_union because instance_resolvers of graphql_interface does not work with Juniper 0.9.2.
// graphql_interface!(Document: () |&self| {
......
......@@ -332,6 +332,10 @@ graphql_object!(Query: Context |&self| {
Ok(deputes)
}
field document(&executor, uid: String) -> FieldResult<Option<&Document>> {
Ok(executor.context().get_document_at_uid(&uid))
}
field documents(&executor) -> FieldResult<Vec<&Document>> {
let mut documents: Vec<&Document> = Vec::new();
for wrapper in &executor.context().dossiers_legislatifs_wrappers {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment