def build_from_name(city_name):
    return {
        'match':{
            'name':{
                'query':city_name,
                'operator':'and',
                'fuzziness':'AUTO'
                }
            }
        }
    
def build_from_guide(guide, regions=None, weather=None, months=None, ignore_cid=None, ignore_name=None):
    must = [{
            'match':{
                'guide':{
                    'query':guide,
                    'cutoff_frequency':0.005
                    }
                }
            }
        ]
    should = []
    must_not = []
    if regions:
        if isinstance(regions, (unicode,str)):
            regions = [regions]
        must.append({
            'match':{
                'regions':{
                    'query':regions,
                    'operator':'or'
                    }
                }
            })
    if weather:
        should += [{'term':{'weather.{}'.format(k):v}} for k,v in weather.items()]
    if months:
        should.append({'terms':{'months_ideal':months}})
    if ignore_cid:
        must_not.append({'term':{'cid':ignore_cid}})
    if ignore_name:
        must_not.append(build_from_name(ignore_name))
        
    query = {'bool':{'must':must}}
    if should:
        query['bool']['should'] = should
    if must_not:
        query['bool']['must_not'] = must_not
    return query
    
@@ -896,82 +896,581 @@
     
-should += %5B%7B'term':%7B'weather.%7B%7D'.format(k):v%7D%7D for k,v in weather.items()%5D
+if 'celsius' in weather.get('temperature',%7B%7D):%0A            should.append(%7B'range':%7B'weather.temperature.celsius':%7B%0A                'gte':weather%5B'temperature'%5D%5B'celsius'%5D - 3,%0A                'lte':weather%5B'temperature'%5D%5B'celsius'%5D + 3%0A                %7D%7D%7D)%0A        if 'humidity' in weather:%0A            should.append(%7B'range':%7B'weather.humidity':%7B%0A                'gte':weather%5B'humidity'%5D - 0.1,%0A                'lte':weather%5B'humidity'%5D + 0.1%0A                %7D%7D%7D)%0A        if 'pattern' in weather:%0A            should.append(%7B'term':%7B'weather.pattern':weather%5B'pattern'%5D%7D%7D)
 %0A   

update weather query based on new nomadlist api