from django.conf import settings
import uuid
import ldt.indexation

__BOOLEAN_DICT = {
    'false':False,
    'true':True,
    '0':False,
    '1':True,
    't': True,
    'f':False
}

def boolean_convert(bool):
    if bool is None:
        return False
    if bool is True or bool is False:
        return bool
    key = str(bool).lower()
    return __BOOLEAN_DICT.get(key, False)


def generate_uuid():
    return unicode(uuid.uuid1())


#def normalize_tags(list):
#    nlist=[]
#    for tag in list:
#        tag = tag.lower()
#        nlist.append(tag)
#    taglist = dict().fromkeys(nlist).keys()    
#    
#    return taglist


class TextSearch(object):

    def query(self, field, query):
        return ldt.indexation.get_result_text(field, query)

    def query_all(self, query):        
        return self.query("all", query)
    

