| 
				
			 | 
			
			
				@@ -113,14 +113,15 @@ def index(): 
			 | 
		
	
		
			
			| 
				113
			 | 
			
				113
			 | 
			
			
				         return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json') 
			 | 
		
	
		
			
			| 
				114
			 | 
			
				114
			 | 
			
			
				     elif request_data.get('format') == 'csv': 
			 | 
		
	
		
			
			| 
				115
			 | 
			
				115
			 | 
			
			
				         csv = UnicodeWriter(cStringIO.StringIO()) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+        keys = ('title', 'url', 'content', 'host', 'engine', 'score') 
			 | 
		
	
		
			
			| 
				116
			 | 
			
				117
			 | 
			
			
				         if len(results): 
			 | 
		
	
		
			
			| 
				117
			 | 
			
				
			 | 
			
			
				-            keys = results[0].keys() 
			 | 
		
	
		
			
			| 
				118
			 | 
			
				118
			 | 
			
			
				             csv.writerow(keys) 
			 | 
		
	
		
			
			| 
				119
			 | 
			
				119
			 | 
			
			
				             for row in results: 
			 | 
		
	
		
			
			| 
				120
			 | 
			
				
			 | 
			
			
				-                csv.writerow([row[key] for key in keys]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				120
			 | 
			
			
				+                row['host'] = row['parsed_url'].netloc 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+                csv.writerow([row.get(key, '') for key in keys]) 
			 | 
		
	
		
			
			| 
				121
			 | 
			
				122
			 | 
			
			
				         csv.stream.seek(0) 
			 | 
		
	
		
			
			| 
				122
			 | 
			
				123
			 | 
			
			
				         response = Response(csv.stream.read(), mimetype='application/csv') 
			 | 
		
	
		
			
			| 
				123
			 | 
			
				
			 | 
			
			
				-        response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format(query)) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+        response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format('_'.join(query.split()))) 
			 | 
		
	
		
			
			| 
				124
			 | 
			
				125
			 | 
			
			
				         return response 
			 | 
		
	
		
			
			| 
				125
			 | 
			
				126
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				126
			 | 
			
				127
			 | 
			
			
				     template = render('results.html' 
			 |