hjianganthony commited on
Commit
03a395a
·
1 Parent(s): d564690

Update src/utils.py

Browse files
Files changed (1) hide show
  1. src/utils.py +6 -3
src/utils.py CHANGED
@@ -194,7 +194,8 @@ def offer_finder_by_category(search_input: str, search_category_tuple: Tuple, ca
194
  - search_input: a string
195
  - search_category_tuple: a tuple of (upper_category, product_category)
196
  - category_dict: a dictionary of categories. Keys are upper categories and values are lists of product categories
197
- - offered_brands: a dataframe of offers (OFFER, BRAND, RETAILER) that are avaialble in our database
 
198
  - brand_belong_category_dict: a dictionary of brands and the categories they belong to
199
  - score: a string of either 'cosine' or 'jaccard'
200
  - threshold: a float between 0 and 1
@@ -292,7 +293,8 @@ def search_offers(search_input: str=example_search, offers: pd.DataFrame=df_offe
292
  # check category
293
  cat_check = find_category(search_input, category_dict)
294
  if cat_check is None:
295
- raise SearchFailedError('No brand/retailer/category is found. Please try again.')
 
296
  else:
297
  # we assume people just search one category at a time
298
  cat_tuple = cat_check # ('Alcohol', 'beer')
@@ -306,7 +308,8 @@ def search_offers(search_input: str=example_search, offers: pd.DataFrame=df_offe
306
  print('No offers matched retailer/category is found. Now trying to recommend based on category.')
307
  cat_check = find_category(search_input, category_dict)
308
  if cat_check is None:
309
- raise SearchFailedError('No brand/retailer/category is found. Please try again.')
 
310
  else:
311
  cat_tuple = cat_check
312
  search_results = offer_finder_by_category(search_input, cat_tuple, category_dict, offers, offered_brands, brand_belong_category_dict, score, score_threshold)
 
194
  - search_input: a string
195
  - search_category_tuple: a tuple of (upper_category, product_category)
196
  - category_dict: a dictionary of categories. Keys are upper categories and values are lists of product categories
197
+ - offers: a dataframe of offers (OFFER, BRAND, RETAILER) that are avaialble in our database
198
+ - offered_brands: a list of offers from offer.df
199
  - brand_belong_category_dict: a dictionary of brands and the categories they belong to
200
  - score: a string of either 'cosine' or 'jaccard'
201
  - threshold: a float between 0 and 1
 
293
  # check category
294
  cat_check = find_category(search_input, category_dict)
295
  if cat_check is None:
296
+ print('No brand/retailer/category is found. Please try again.')
297
+ return None
298
  else:
299
  # we assume people just search one category at a time
300
  cat_tuple = cat_check # ('Alcohol', 'beer')
 
308
  print('No offers matched retailer/category is found. Now trying to recommend based on category.')
309
  cat_check = find_category(search_input, category_dict)
310
  if cat_check is None:
311
+ print('No brand/retailer/category is found. Please try again.')
312
+ return None
313
  else:
314
  cat_tuple = cat_check
315
  search_results = offer_finder_by_category(search_input, cat_tuple, category_dict, offers, offered_brands, brand_belong_category_dict, score, score_threshold)