示例#1
0
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
示例#2
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
示例#3
0
 def test_remove_common_words_empty_result(self):
     self.assertListEqual(remove_common_words("Hotel The"), [])
示例#4
0
 def test_remove_common_words_incorrect_result(self):
     self.assertNotEqual(remove_common_words("Hotel The Prime"), ['Prime'])