Ajout du tiret dans la définition d'un mot
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / scripts / sphinx.conf.py.in
CommitLineData
5212238e
EMS
1#!/usr/bin/python
2# coding: utf-8
3#
4# Ce script compose dynamiquement une configuration pour Sphinx. Il suffit
5# que le fichier soit exécutable pour que Sphinx exécute le script plutôt
6# que de le lire comme un fichier statique.
7#
8# Le manuel de sphinx se trouve au http://sphinxsearch.com/docs/manual-0.9.9.html
9
10import glob
11import os
12import sys
13
14sys.path[0:0] = [
15 "%(directory)s",
16 "%(directory)s/auf_savoirs_en_partage",
17 ]
18os.environ['DJANGO_SETTINGS_MODULE'] = 'production'
19for d in glob.glob("%(directory)s/eggs/*"):
20 sys.path[0:0] = [d,]
21for d in glob.glob("%(directory)s/parts/*"):
22 sys.path[0:0] = [d,]
23
24from django.conf import settings
25
26SQL_HOST = settings.DATABASE_HOST
27SQL_USER = settings.DATABASE_USER
28SQL_PASS = settings.DATABASE_PASSWORD
29SQL_DB = settings.DATABASE_NAME
4134daa0 30DATA_DIR = '/var/lib/sphinxsearch/data'
5212238e
EMS
31
32def multiline(s):
33 """Place un marqueur de continuation avant chaque saut de ligne."""
34 return s.replace("\n", "\\\n")
35
acd5cd8f
EMS
36def emit_source(name, sql_query, sql_query_info=None, sql_attr_multi=None, sql_attr_uint=None,
37 sql_attr_str2ordinal=None):
5212238e
EMS
38 print '''
39source %%(name)s
40{
41 type = mysql
42 sql_host = %%(sql_host)s
43 sql_user = %%(sql_user)s
44 sql_pass = %%(sql_pass)s
45 sql_db = %%(sql_db)s
46 sql_query_pre = SET NAMES utf8
47 sql_query_pre = SET SESSION query_cache_type=OFF
48 sql_query = %%(sql_query)s
49''' %% dict(name=name, sql_host=SQL_HOST, sql_user=SQL_USER,
50 sql_pass=SQL_PASS, sql_db=SQL_DB, sql_query=multiline(sql_query))
51
52 if sql_query_info:
53 print ' sql_query_info = ' + sql_query_info
54
55 if sql_attr_multi:
56 for attr in sql_attr_multi:
57 print ' sql_attr_multi = uint %%s from field' %% attr
58
59 if sql_attr_uint:
60 for attr in sql_attr_uint:
61 print ' sql_attr_uint = ' + attr
62
acd5cd8f
EMS
63 if sql_attr_str2ordinal:
64 for attr in sql_attr_str2ordinal:
65 print ' sql_attr_str2ordinal = ' + attr
66
5212238e
EMS
67 print '}'
68
69def emit_index(name):
70 print '''
71index %%(name)s
72{
73 morphology = libstemmer_fr
74 charset_type = utf-8
0e90c1a7 75 charset_table = 0..9, A..Z->a..z, _, a..z, U+2D, \\
5212238e
EMS
76 U+C0->a, U+C2->a, U+E0->a, U+E2->a, \\
77 U+C7->c, U+E7->c, \\
78 U+C8->e, U+C9->e, U+CA->e, U+E8->e, U+E9->e, U+EA->e, U+EB->e, \\
79 U+CE->i, U+EE->i, U+EF->i, \\
80 U+D4->o, U+F4->o, \\
81 U+F9->u, U+FB->u, U+FC->u
82 source = %%(name)s
83 path = %%(path)s
42a890cf 84 stopwords = %(directory)s/auf_savoirs_en_partage/stopwords.txt
5212238e
EMS
85}''' %% dict(name=name, path=os.path.join(DATA_DIR, name))
86
4134daa0 87emit_source('savoirsenpartage_ressources',
5212238e
EMS
88 '''SELECT r.id AS id,
89 r.title AS title,
90 r.description AS description,
91 r.creator AS creator,
92 r.contributor AS contributor,
93 r.subject AS subject,
94 r.publisher AS publisher,
230671ff 95 TO_DAYS(r.modified) AS modified,
5212238e
EMS
96 GROUP_CONCAT(DISTINCT d.nom_discipline) AS disciplines,
97 GROUP_CONCAT(DISTINCT d.id_discipline) AS discipline_ids,
98 GROUP_CONCAT(DISTINCT p.nom) AS pays,
99 GROUP_CONCAT(DISTINCT reg.nom) AS regions,
100 GROUP_CONCAT(DISTINCT reg.id) AS region_ids
101 FROM savoirs_record r
102 LEFT JOIN savoirs_record_disciplines rd ON rd.record_id = r.id
103 LEFT JOIN discipline d ON d.id_discipline = rd.discipline_id
104 LEFT JOIN savoirs_record_pays rp ON rp.record_id = r.id
105 LEFT JOIN ref_pays p ON p.id = rp.pays_id
106 LEFT JOIN savoirs_record_regions rr ON rr.record_id = r.id
107 LEFT JOIN ref_region reg ON reg.id = rr.region_id OR reg.id = p.region
108 LEFT JOIN savoirs_record_listsets rl ON rl.record_id = r.id
109 LEFT JOIN savoirs_listset l ON l.spec = rl.listset_id
110 WHERE r.validated AND (l.spec IS NULL OR l.validated)
111 GROUP BY r.id''',
112 sql_query_info='SELECT * from savoirs_record WHERE id=$id',
230671ff
EMS
113 sql_attr_multi=['discipline_ids', 'region_ids'],
114 sql_attr_uint=['modified']
5212238e
EMS
115 )
116
4134daa0 117emit_source('savoirsenpartage_actualites',
5212238e
EMS
118 '''SELECT a.id_actualite AS id,
119 a.titre_actualite AS titre,
120 a.texte_actualite AS texte,
121 TO_DAYS(a.date_actualite) AS date,
011804bb 122 CASE s.type WHEN 'actu' THEN 1 WHEN 'appels' THEN 2 END AS type,
5212238e
EMS
123 GROUP_CONCAT(DISTINCT r.nom) AS regions,
124 GROUP_CONCAT(DISTINCT d.nom_discipline) AS disciplines
125 FROM actualite a
011804bb 126 INNER JOIN savoirs_sourceactualite s ON s.id = a.source_id
5212238e
EMS
127 LEFT JOIN actualite_regions ar ON ar.actualite_id = a.id_actualite
128 LEFT JOIN ref_region r ON r.id = ar.region_id
129 LEFT JOIN actualite_disciplines ad ON ad.actualite_id = a.id_actualite
130 LEFT JOIN discipline d ON d.id_discipline = ad.discipline_id
131 WHERE a.visible_actualite
132 GROUP BY a.id_actualite''',
133 sql_query_info='SELECT * from actualite WHERE id_actualite=$id',
011804bb 134 sql_attr_uint=['date', 'type'],
5212238e
EMS
135 )
136
4134daa0 137emit_source('savoirsenpartage_evenements',
5212238e
EMS
138 '''SELECT e.id AS id,
139 e.titre AS titre,
140 e.mots_cles AS mots_cles,
141 e.type AS type,
fe254ccc
EMS
142 e.adresse AS adresse,
143 e.ville AS ville,
5212238e 144 e.description AS description,
fe254ccc
EMS
145 CONCAT_WS(e.prenom, e.nom, e.courriel, e.contact) AS contact,
146 p.nom AS pays,
5212238e 147 CONCAT_WS(',', d.nom_discipline, d2.nom_discipline) AS disciplines,
fe254ccc 148 CONCAT_WS(',', pr.nom, GROUP_CONCAT(DISTINCT r.nom)) AS regions,
a83b8efb
EMS
149 TO_DAYS(DATE(e.debut)) AS debut,
150 TO_DAYS(DATE(e.date_modification)) AS date_modification
5212238e
EMS
151 FROM savoirs_evenement e
152 LEFT JOIN discipline d ON d.id_discipline = e.discipline_id
153 LEFT JOIN discipline d2 ON d2.id_discipline = e.discipline_secondaire_id
154 LEFT JOIN savoirs_evenement_regions er ON er.evenement_id = e.id
155 LEFT JOIN ref_region r ON r.id = er.region_id
fe254ccc
EMS
156 LEFT JOIN ref_pays p ON p.code = e.pays_id
157 LEFT JOIN ref_region pr ON pr.id = p.region
5212238e
EMS
158 WHERE e.approuve
159 GROUP BY e.id''',
160 sql_query_info='SELECT * from savoirs_evenement WHERE id=$id',
a83b8efb 161 sql_attr_uint=['debut', 'date_modification'])
5212238e 162
4134daa0 163emit_source('savoirsenpartage_chercheurs',
edbcaa99 164 '''SELECT c.personne_ptr_id AS id,
5212238e
EMS
165 p.nom AS nom,
166 p.prenom AS prenom,
acd5cd8f 167 CONCAT(p.nom, ' ', p.prenom) AS nom_complet,
5212238e
EMS
168 c.theme_recherche AS theme_recherche,
169 c.groupe_recherche AS groupe_recherche,
170 c.mots_cles AS mots_cles,
edbcaa99
EMS
171 c.membre_instance_auf AS membre_instance_auf,
172 c.expert_oif AS expert_oif,
173 c.membre_association_francophone AS membre_association_francophone,
174 c.membre_reseau_institutionnel AS membre_reseau_institutionnel,
5212238e 175 IFNULL(et.nom, etablissement_autre_nom) AS etablissement,
acd5cd8f 176 IFNULL(et.nom, etablissement_autre_nom) AS etablissement_attr,
5212238e 177 pays.nom AS pays,
acd5cd8f 178 pays.nom AS pays_attr,
5212238e
EMS
179 pays.id AS pays_id,
180 r.nom AS region,
181 r.id AS region_id,
182 GROUP_CONCAT(DISTINCT d.nom_discipline) AS disciplines,
d8514fce 183 GROUP_CONCAT(DISTINCT IFNULL(pub.titre, pub.publication_affichage)) AS publications,
5212238e
EMS
184 t.titre AS these,
185 GROUP_CONCAT(DISTINCT g.nom) AS groupes,
186 GROUP_CONCAT(DISTINCT ex.nom) AS expertises,
187 GROUP_CONCAT(DISTINCT g.id) AS groupe_ids,
188 TO_DAYS(c.date_modification) AS date_modification,
d8514fce
EMS
189 CASE pays.nord_sud WHEN 'Nord' THEN 1
190 WHEN 'Sud' THEN 2
191 END AS nord_sud,
5212238e
EMS
192 CASE statut WHEN 'enseignant' THEN 1
193 WHEN 'etudiant' THEN 2
194 WHEN 'independant' THEN 3
195 END AS statut,
c6efde25
OL
196 CASE p.genre WHEN 'm' THEN 1
197 WHEN 'f' THEN 2
198 END AS genre,
d9da735f 199 (ex.id IS NOT NULL) AS expert
5212238e 200 FROM chercheurs_chercheur c
edbcaa99 201 INNER JOIN chercheurs_personne p ON c.personne_ptr_id = p.id
5212238e 202 LEFT JOIN ref_etablissement et ON et.id = c.etablissement
acd5cd8f 203 LEFT JOIN ref_pays pays ON pays.code = IFNULL(et.pays, c.etablissement_autre_pays)
5212238e
EMS
204 LEFT JOIN ref_region r ON pays.region = r.id
205 LEFT JOIN discipline d ON d.id_discipline = c.discipline
edbcaa99
EMS
206 LEFT JOIN chercheurs_publication pub ON pub.chercheur_id = c.personne_ptr_id
207 LEFT JOIN chercheurs_these t ON t.chercheur_id = c.personne_ptr_id
208 LEFT JOIN chercheurs_chercheurgroupe cg ON cg.chercheur = c.personne_ptr_id
5212238e 209 LEFT JOIN chercheurs_groupe g ON g.id = cg.groupe
edbcaa99 210 LEFT JOIN chercheurs_expertise ex ON ex.chercheur_id = c.personne_ptr_id
695930dd 211 WHERE p.actif
edbcaa99 212 GROUP BY c.personne_ptr_id''',
5212238e
EMS
213 sql_query_info='SELECT * from chercheurs_chercheur WHERE id=$id',
214 sql_attr_multi=['groupe_ids'],
edbcaa99
EMS
215 sql_attr_uint=['pays_id', 'region_id', 'nord_sud',
216 'date_modification', 'statut', 'expert',
217 'membre_instance_auf', 'expert_oif',
218 'membre_association_francophone',
c6efde25
OL
219 'membre_reseau_institutionnel', 'genre', ],
220 sql_attr_str2ordinal=['nom_complet', 'etablissement_attr', 'pays_attr', ])
5212238e 221
4134daa0 222emit_source('savoirsenpartage_sites',
5212238e
EMS
223 '''SELECT s.id AS id,
224 s.titre AS titre,
225 s.description AS description,
226 s.editeur AS editeur,
227 s.auteur AS auteur,
228 s.mots_cles AS mots_cles,
229 GROUP_CONCAT(DISTINCT d.nom_discipline) AS disciplines,
230 GROUP_CONCAT(DISTINCT p.nom) AS pays,
231 GROUP_CONCAT(DISTINCT p.id) AS pays_ids,
a611bc4a
EMS
232 GROUP_CONCAT(DISTINCT r.nom) AS regions,
233 TO_DAYS(s.date_maj) AS date_maj
5212238e
EMS
234 FROM sitotheque_site s
235 LEFT JOIN sitotheque_site_discipline sd ON sd.site_id = s.id
236 LEFT JOIN discipline d ON d.id_discipline = sd.discipline_id
237 LEFT JOIN ref_pays p ON p.id = s.pays
238 LEFT JOIN ref_region r ON r.id = p.region
239 GROUP BY s.id''',
240 'SELECT * FROM sitotheque_site WHERE id=$id',
a611bc4a
EMS
241 sql_attr_multi=['pays_ids'],
242 sql_attr_uint=['date_maj']
243 )
5212238e 244
4134daa0
EMS
245emit_index('savoirsenpartage_actualites')
246emit_index('savoirsenpartage_ressources')
247emit_index('savoirsenpartage_evenements')
248emit_index('savoirsenpartage_chercheurs')
249emit_index('savoirsenpartage_sites')