Beispiel #1
0
def get_search_range_terms(start_search_term, end_search_term):
    '''
    
    :param start_search_term:
    :param end_search_term:
    '''
    try:
        start_index = DataStore().hotel_names.index(start_search_term)
        end_index = DataStore().hotel_names.index(start_search_term)
        return DataStore().hotel_names[start_index + 1:end_index - 1]
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #2
0
def search_hotels_from_name_indexer(search_term):
    '''
    
    :param search_term:
    '''
    result = []
    try:
        hotel_id_list = DataStore().hotel_name_indexed_data.get(search_term)
        for hotel_id in hotel_id_list:
            result.append(DataStore().data.get(hotel_id))
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #3
0
 def test_index_by_stars(self):
     self.assertEqual(len(DataStore().star_ranking_indexed_data), 0)
     hotel = Hotel()
     hotel.name = 'Park Estique'
     hotel.country = 'India'
     hotel.city = 'Mumbai'
     hotel.street = 'Bajirao Road'
     hotel.description = 'This is a very good hotel'
     hotel.telephone_number = 12345
     hotel.star_ranking = 4.0
     hotel.number_of_rooms = 10
     insert_value(hotel)
     index_by_city(hotel)
     self.assertEqual(len(DataStore().star_ranking_indexed_data), 1)
def index_by_city(hotel_details):
    '''
    
    :param hotel_details:
    '''
    try:
        if DataStore().city_indexed_data.get(hotel_details.city) is not None:
            DataStore().city_indexed_data[hotel_details.city].append(hotel_details.hotel_id)
        else:
            hotel_id_list = []
            hotel_id_list.append(hotel_details.hotel_id)
            DataStore().city_indexed_data[hotel_details.city] = hotel_id_list
    except Exception, ex:
        logger.exception(ex)
        raise ex
def insert_value(hotel_details):
    '''
    
    :param hotel_details:
    '''
    response = HttpResponse()
    try:
        hotel_details.hotel_id = len(DataStore().data) + 1
        run_indexer(hotel_details)
        DataStore().data[hotel_details.hotel_id] = hotel_details
        response.content = "Hotel Added Successfully"
    except Exception, ex:
        response.status_code = 500
        logger.exception(ex)
        raise ex
def index_by_stars(hotel_details):
    '''
    
    :param hotel_details:
    '''
    try:
        if DataStore().star_ranking_indexed_data.get(hotel_details.star_ranking) is not None:
            DataStore().star_ranking_indexed_data[hotel_details.star_ranking].append(hotel_details.hotel_id)
        else:
            hotel_id_list = []
            hotel_id_list.append(hotel_details.hotel_id)
            DataStore().star_ranking_indexed_data[hotel_details.star_ranking] = hotel_id_list
    except Exception, ex:
        logger.exception(ex)
        raise ex
def index_search_terms(word, hotel_details):
    '''
    
    :param word:
    :param hotel_details:
    '''
    try:    
        if DataStore().indexed_search_terms.get(word) is not None:
            DataStore().indexed_search_terms[word.lower()].append(hotel_details.hotel_id)
        else:
            hotel_names = SortedSet()
            hotel_names.add(word.lower())
            word_len = len(word)
            DataStore().indexed_search_terms[word.lower()[0:(word_len if word_len <= 1 else 2)]] = word
    except Exception, ex:
        logger.exception(ex)
        raise ex
def add_search_term(word):
    '''
    
    :param word:
    '''
    try:
        DataStore().search_terms.add(word)
    except Exception, ex:
        logger.exception(ex)
        raise ex
def index_by_hotel_name(hotel_details):
    '''
    
    :param hotel_details:
    '''
    try:
        hotel_name_words = remove_common_words(hotel_details.name)
        for word in hotel_name_words:
            index_search_terms(word, hotel_details)
            add_search_term(word)
            if DataStore().hotel_name_indexed_data.get(word) is not None:
                DataStore().hotel_name_indexed_data[word.lower()].append(hotel_details.hotel_id)
            else:
                hotel_id_list = []
                hotel_id_list.append(hotel_details.hotel_id)
                DataStore().hotel_name_indexed_data[word.lower()] = hotel_id_list
    except Exception, ex:
        logger.exception(ex)
        raise ex
def delete_value(hotel_id):
    '''
    
    :param hotel_id:
    '''
    response = HttpResponse()
    try:
        del DataStore().data[hotel_id]
    except Exception, ex:
        response.status_code = 500
        logger.exception(ex)
        raise ex
Beispiel #11
0
def search_hotel_by_id(hotel_id):
    '''
    
    :param hotel_id:
    '''
    try:
        result = []
        result.append(DataStore().data.get(int(hotel_id)))
        return result
    except Exception, ex:
        logger.exception(ex)
        raise ex
def update_value(hotel_id, hotel_details):
    '''
    
    :param hotel_id:
    :param hotel_details:
    '''
    response = HttpResponse()
    try:
        DataStore().data[hotel_details.hotel_id] = hotel_details
    except Exception, ex:
        response.status_code = 500
        logger.exception(ex)
        raise ex
Beispiel #13
0
def search_name_with_some_search_terms(search_terms):
    '''
    
    :param search_terms:
    '''
    result = []
    try:
        hotel_id_list = get_hotel_id_list(search_terms)
        for hotel_id in hotel_id_list:
            hotel_info = DataStore().data.get(hotel_id)
            result.append(hotel_info)
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #14
0
def get_seach_terms_by_distance(search_term, required_distance):
    '''
    
    :param search_term:
    :param required_distance:
    '''
    search_terms = []
    try:
        for term in DataStore().search_terms:
            if distance.nlevenshtein(search_term, term) <= required_distance:
                search_terms.append(term)
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #15
0
def get_hotel_id_list(search_terms):
    '''
    
    :param search_terms:
    '''
    try:
        hotel_id_list = []
        for search_term in search_terms:
            id_list = DataStore().hotel_name_indexed_data.get(search_term)
            if id_list is not None:
                hotel_id_list += id_list
        return list(set(hotel_id_list))
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #16
0
def search_by_regex(search_term):
    '''
    
    :param search_term:
    '''
    result = []
    try:
        regex = build_regex(search_term)
        search_terms = [
            item.group(0) for term in DataStore().search_terms
            for item in [regex.search(term)] if item
        ]
        if search_terms is not None and len(search_terms) > 0:
            result = search_name_with_some_search_terms(search_terms)
    except Exception, ex:
        logger.exception(ex)
        raise ex
Beispiel #17
0
def search_name_with_all_search_terms(search_terms):
    '''
    
    :param search_terms:
    '''
    result = []
    try:
        hotel_id_list = get_hotel_id_list(search_terms)
        for hotel_id in hotel_id_list:
            hotel_info = DataStore().data.get(hotel_id)
            terms_from_name = remove_common_words(hotel_info.name)
            all_terms_present = True
            for term in terms_from_name:
                if term not in search_terms:
                    all_terms_present = False
                    break
            if all_terms_present:
                result.append(hotel_info)
    except Exception, ex:
        logger.exception(ex)
        raise ex