| Line 5... |
Line 5... |
| 5 |
xstr = lambda s: s or ""
|
5 |
xstr = lambda s: s or ""
|
| 6 |
database = Database()
|
6 |
database = Database()
|
| 7 |
ac = database.autocomplete()
|
7 |
ac = database.autocomplete()
|
| 8 |
|
8 |
|
| 9 |
class Suggestion():
|
9 |
class Suggestion():
|
| 10 |
def __init__(self, category_id, subCategoryId, suggestion, word):
|
10 |
def __init__(self, category_id, subCategoryId, suggestion, word, category_name):
|
| 11 |
self.category_id = category_id
|
11 |
self.category_id = category_id
|
| 12 |
self.subCategoryId = subCategoryId
|
12 |
self.subCategoryId = subCategoryId
|
| 13 |
self.suggestion = suggestion
|
13 |
self.suggestion = suggestion
|
| 14 |
self.word = word
|
14 |
self.word = word
|
| - |
|
15 |
self.category_name = category_name
|
| 15 |
|
16 |
|
| 16 |
|
17 |
|
| 17 |
def filterSuggestions(categorySuggestion):
|
18 |
def filterSuggestions(categorySuggestion):
|
| 18 |
returnObj = []
|
19 |
returnObj = []
|
| 19 |
for cat in ('Mobiles','Tablets'):
|
20 |
for cat in ('Mobiles','Tablets'):
|
| Line 40... |
Line 41... |
| 40 |
if len(results) > 10:
|
41 |
if len(results) > 10:
|
| 41 |
"""Lets group data"""
|
42 |
"""Lets group data"""
|
| 42 |
for i in results:
|
43 |
for i in results:
|
| 43 |
if i.get('subCategoryId'):
|
44 |
if i.get('subCategoryId'):
|
| 44 |
if not categorySuggestion.has_key(i.get('subCategoryId')):
|
45 |
if not categorySuggestion.has_key(i.get('subCategoryId')):
|
| 45 |
suggestion_obj_primary = Suggestion(i.get('category_id'),i.get('subCategoryId'),search_text+" in "+SUB_CATEGORY_MAP.get(i.get('subCategoryId')), search_text)
|
46 |
suggestion_obj_primary = Suggestion(i.get('category_id'),i.get('subCategoryId'),search_text, search_text, SUB_CATEGORY_MAP.get(i.get('subCategoryId')))
|
| 46 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'))
|
47 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'), None)
|
| 47 |
categorySuggestion[i.get('subCategoryId')] = [suggestion_obj_primary,suggestion_obj]
|
48 |
categorySuggestion[i.get('subCategoryId')] = [suggestion_obj_primary,suggestion_obj]
|
| 48 |
else:
|
49 |
else:
|
| 49 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'))
|
50 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'), None)
|
| 50 |
categorySuggestion.get(i.get('subCategoryId')).append(suggestion_obj)
|
51 |
categorySuggestion.get(i.get('subCategoryId')).append(suggestion_obj)
|
| 51 |
else:
|
52 |
else:
|
| 52 |
if not categorySuggestion.has_key(i.get('category_id')):
|
53 |
if not categorySuggestion.has_key(i.get('category_id')):
|
| 53 |
suggestion_obj_primary = Suggestion(i.get('category_id'),i.get('subCategoryId'),search_text+" in "+CATEGORY_MAP.get(i.get('category_id')), search_text)
|
54 |
suggestion_obj_primary = Suggestion(i.get('category_id'),i.get('subCategoryId'),search_text, search_text, CATEGORY_MAP.get(i.get('category_id')), None)
|
| 54 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'))
|
55 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'), None)
|
| 55 |
categorySuggestion[i.get('category_id')] = [suggestion_obj_primary, suggestion_obj]
|
56 |
categorySuggestion[i.get('category_id')] = [suggestion_obj_primary, suggestion_obj]
|
| 56 |
else:
|
57 |
else:
|
| 57 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'))
|
58 |
suggestion_obj = Suggestion(i.get('category_id'),i.get('subCategoryId'),i.get('title'), i.get('title'))
|
| 58 |
categorySuggestion.get(i.get('category_id')).append(suggestion_obj)
|
59 |
categorySuggestion.get(i.get('category_id')).append(suggestion_obj)
|
| 59 |
|
60 |
|
| 60 |
returnObj = filterSuggestions(categorySuggestion)
|
61 |
returnObj = filterSuggestions(categorySuggestion)
|
| 61 |
|
62 |
|
| 62 |
else:
|
63 |
else:
|
| 63 |
for i in results:
|
64 |
for i in results:
|
| 64 |
returnObj.append({'suggestion':i.get('title'),'category_id':i.get('category_id'),'subCategoryId':i.get('subCategoryId'),'word':i.get('title')})
|
65 |
returnObj.append({'suggestion':i.get('title'),'category_id':i.get('category_id'),'subCategoryId':i.get('subCategoryId'),'word':i.get('title'),'category_name':None})
|
| 65 |
|
66 |
|
| 66 |
return returnObj
|
67 |
return returnObj
|
| 67 |
|
68 |
|
| 68 |
|
69 |
|
| 69 |
def main():
|
70 |
def main():
|