comparison zopeSolr.py @ 9:896bea4f61a0

try to deal with timeout on connect.
author casties
date Wed, 19 Jun 2013 17:16:05 +0200
parents a8f16569d1a6
children f7fe88804cb8
comparison
equal deleted inserted replaced
8:a8f16569d1a6 9:896bea4f61a0
13 import urllib 13 import urllib
14 import re 14 import re
15 import xml.etree.ElementTree as ET 15 import xml.etree.ElementTree as ET
16 import json 16 import json
17 import random 17 import random
18 import logging
18 19
19 #Worte die nicht in der Termliste angezeigt werden sollen #TODO: make this configurable 20 #Worte die nicht in der Termliste angezeigt werden sollen #TODO: make this configurable
20 21
21 STOPLIST={'main_content':['forward','drucken','history','science','part','publications','projects', 22 STOPLIST={'main_content':['forward','drucken','history','science','part','publications','projects',
22 'project','new','geschichte','institute','related','boltzmannstraße','14195'], 23 'project','new','geschichte','institute','related','boltzmannstraße','14195'],
65 66
66 """hole zufaellige eintraege""" 67 """hole zufaellige eintraege"""
67 68
68 69
69 if not getattr(self,'_v_solr_',None): 70 if not getattr(self,'_v_solr_',None):
70 self.connect() 71 try:
72 self.connect()
73 except Exception, e:
74 logging.error("Error connecting to Solr: %s"%e)
75 return []
71 76
72 #http://localhost:8983/solr/mpiwgSources/select/?q=*:*&sort=random_12xs34%20desc&rows=1&facet=false 77 #http://localhost:8983/solr/mpiwgSources/select/?q=*:*&sort=random_12xs34%20desc&rows=1&facet=false
73 78
74 79
75 random.seed() 80 random.seed()
181 186
182 #for fl in storeFields: #initialisiere den hash 187 #for fl in storeFields: #initialisiere den hash
183 # fls[fl]={} 188 # fls[fl]={}
184 189
185 if not getattr(self,'_v_solr_',None): 190 if not getattr(self,'_v_solr_',None):
186 self.connect() 191 try:
187 192 self.connect()
188 193 except Exception, e:
194 logging.error("Error connecting to Solr: %s"%e)
195 return res
189 196
190 for x in range(begin,end,increment): 197 for x in range(begin,end,increment):
191 query={} 198 query={}
192 #query["%s__gt"%field]=x 199 #query["%s__gt"%field]=x
193 #TODO __gt scheint nicht zu funktionieren wird zu gte (???) 200 #TODO __gt scheint nicht zu funktionieren wird zu gte (???)
307 ranges[field.replace("_drg","__lte")]=splitted[1] 314 ranges[field.replace("_drg","__lte")]=splitted[1]
308 315
309 316
310 #teste verbindung zu solr 317 #teste verbindung zu solr
311 if not getattr(self,'_v_solr_',None): 318 if not getattr(self,'_v_solr_',None):
312 self.connect() 319 try:
313 320 self.connect()
314 321 except Exception, e:
322 logging.error("Error connecting to Solr: %s"%e)
323 return []
315 324
316 solrQuery = solrQuery.decode('utf-8') 325 solrQuery = solrQuery.decode('utf-8')
317 326
318 #teile die suche nach " " daraus wird dann eine AND suche 327 #teile die suche nach " " daraus wird dann eine AND suche
319 #TODO: sollte flexibler sein. insbesondere phrasen 328 #TODO: sollte flexibler sein. insbesondere phrasen