import ldt.indexation
import uuid

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

def boolean_convert(b):
    if b is None:
        return False
    if b is True or b is False:
        return b
    key = str(b).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)
    

