marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 1 | # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
marination | 97e3a85 | 2022-04-04 11:32:49 +0530 | [diff] [blame] | 4 | import json |
| 5 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 6 | import frappe |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 7 | from frappe import _ |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 8 | from frappe.utils.redis_wrapper import RedisWrapper |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 9 | from redis import ResponseError |
marination | 9fb61ef | 2022-02-01 00:39:14 +0530 | [diff] [blame] | 10 | from redisearch import AutoCompleter, Client, IndexDefinition, Suggestion, TagField, TextField |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 11 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 12 | WEBSITE_ITEM_INDEX = "website_items_index" |
| 13 | WEBSITE_ITEM_KEY_PREFIX = "website_item:" |
| 14 | WEBSITE_ITEM_NAME_AUTOCOMPLETE = "website_items_name_dict" |
| 15 | WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE = "website_items_category_dict" |
| 16 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 17 | |
marination | bbcbcf7 | 2021-09-02 14:07:59 +0530 | [diff] [blame] | 18 | def get_indexable_web_fields(): |
| 19 | "Return valid fields from Website Item that can be searched for." |
| 20 | web_item_meta = frappe.get_meta("Website Item", cached=True) |
| 21 | valid_fields = filter( |
| 22 | lambda df: df.fieldtype in ("Link", "Table MultiSelect", "Data", "Small Text", "Text Editor"), |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 23 | web_item_meta.fields, |
| 24 | ) |
marination | bbcbcf7 | 2021-09-02 14:07:59 +0530 | [diff] [blame] | 25 | |
| 26 | return [df.fieldname for df in valid_fields] |
| 27 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 28 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 29 | def is_redisearch_enabled(): |
| 30 | "Return True only if redisearch is loaded and enabled." |
| 31 | is_redisearch_enabled = frappe.db.get_single_value("E Commerce Settings", "is_redisearch_enabled") |
| 32 | return is_search_module_loaded() and is_redisearch_enabled |
| 33 | |
| 34 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 35 | def is_search_module_loaded(): |
Marica | d637f79 | 2021-09-18 14:23:44 +0530 | [diff] [blame] | 36 | try: |
| 37 | cache = frappe.cache() |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 38 | out = cache.execute_command("MODULE LIST") |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 39 | |
Marica | d637f79 | 2021-09-18 14:23:44 +0530 | [diff] [blame] | 40 | parsed_output = " ".join( |
| 41 | (" ".join([s.decode() for s in o if not isinstance(s, int)]) for o in out) |
| 42 | ) |
| 43 | return "search" in parsed_output |
| 44 | except Exception: |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 45 | return False # handling older redis versions |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 46 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 47 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 48 | def if_redisearch_enabled(function): |
| 49 | "Decorator to check if Redisearch is enabled." |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 50 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 51 | def wrapper(*args, **kwargs): |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 52 | if is_redisearch_enabled(): |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 53 | func = function(*args, **kwargs) |
| 54 | return func |
| 55 | return |
| 56 | |
| 57 | return wrapper |
| 58 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 59 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 60 | def make_key(key): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 61 | return "{0}|{1}".format(frappe.conf.db_name, key).encode("utf-8") |
| 62 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 63 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 64 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 65 | def create_website_items_index(): |
marination | bbcbcf7 | 2021-09-02 14:07:59 +0530 | [diff] [blame] | 66 | "Creates Index Definition." |
| 67 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 68 | # CREATE index |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 69 | client = Client(make_key(WEBSITE_ITEM_INDEX), conn=frappe.cache()) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 70 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 71 | try: |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 72 | client.drop_index() # drop if already exists |
| 73 | except ResponseError: |
| 74 | # will most likely raise a ResponseError if index does not exist |
| 75 | # ignore and create index |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 76 | pass |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 77 | except Exception: |
| 78 | raise_redisearch_error() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 79 | |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 80 | idx_def = IndexDefinition([make_key(WEBSITE_ITEM_KEY_PREFIX)]) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 81 | |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 82 | # Index fields mentioned in e-commerce settings |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 83 | idx_fields = frappe.db.get_single_value("E Commerce Settings", "search_index_fields") |
| 84 | idx_fields = idx_fields.split(",") if idx_fields else [] |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 85 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 86 | if "web_item_name" in idx_fields: |
| 87 | idx_fields.remove("web_item_name") |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 88 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 89 | idx_fields = list(map(to_search_field, idx_fields)) |
| 90 | |
| 91 | client.create_index( |
| 92 | [TextField("web_item_name", sortable=True)] + idx_fields, |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 93 | definition=idx_def, |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 94 | ) |
| 95 | |
| 96 | reindex_all_web_items() |
| 97 | define_autocomplete_dictionary() |
| 98 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 99 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 100 | def to_search_field(field): |
| 101 | if field == "tags": |
| 102 | return TagField("tags", separator=",") |
| 103 | |
| 104 | return TextField(field) |
| 105 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 106 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 107 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 108 | def insert_item_to_index(website_item_doc): |
| 109 | # Insert item to index |
| 110 | key = get_cache_key(website_item_doc.name) |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 111 | cache = frappe.cache() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 112 | web_item = create_web_item_map(website_item_doc) |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 113 | |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 114 | for field, value in web_item.items(): |
| 115 | super(RedisWrapper, cache).hset(make_key(key), field, value) |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 116 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 117 | insert_to_name_ac(website_item_doc.web_item_name, website_item_doc.name) |
| 118 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 119 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 120 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 121 | def insert_to_name_ac(web_name, doc_name): |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 122 | ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=frappe.cache()) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 123 | ac.add_suggestions(Suggestion(web_name, payload=doc_name)) |
| 124 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 125 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 126 | def create_web_item_map(website_item_doc): |
| 127 | fields_to_index = get_fields_indexed() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 128 | web_item = {} |
| 129 | |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 130 | for field in fields_to_index: |
| 131 | web_item[field] = website_item_doc.get(field) or "" |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 132 | |
| 133 | return web_item |
Hussain Nagaria | bd0d0ad | 2021-05-26 20:26:34 +0530 | [diff] [blame] | 134 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 135 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 136 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 137 | def update_index_for_item(website_item_doc): |
| 138 | # Reinsert to Cache |
| 139 | insert_item_to_index(website_item_doc) |
| 140 | define_autocomplete_dictionary() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 141 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 142 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 143 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 144 | def delete_item_from_index(website_item_doc): |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 145 | cache = frappe.cache() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 146 | key = get_cache_key(website_item_doc.name) |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 147 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 148 | try: |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 149 | cache.delete(key) |
marination | ea30ce4 | 2021-06-02 13:24:06 +0530 | [diff] [blame] | 150 | except Exception: |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 151 | raise_redisearch_error() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 152 | |
Hussain Nagaria | 34f3a66 | 2021-05-05 13:47:43 +0530 | [diff] [blame] | 153 | delete_from_ac_dict(website_item_doc) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 154 | return True |
| 155 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 156 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 157 | @if_redisearch_enabled |
Hussain Nagaria | 34f3a66 | 2021-05-05 13:47:43 +0530 | [diff] [blame] | 158 | def delete_from_ac_dict(website_item_doc): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 159 | """Removes this items's name from autocomplete dictionary""" |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 160 | cache = frappe.cache() |
| 161 | name_ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=cache) |
Hussain Nagaria | 34f3a66 | 2021-05-05 13:47:43 +0530 | [diff] [blame] | 162 | name_ac.delete(website_item_doc.web_item_name) |
| 163 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 164 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 165 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 166 | def define_autocomplete_dictionary(): |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 167 | """ |
| 168 | Defines/Redefines an autocomplete search dictionary for Website Item Name. |
| 169 | Also creats autocomplete dictionary for Published Item Groups. |
| 170 | """ |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 171 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 172 | cache = frappe.cache() |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 173 | item_ac = AutoCompleter(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE), conn=cache) |
| 174 | item_group_ac = AutoCompleter(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE), conn=cache) |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 175 | |
Hussain Nagaria | f342155 | 2021-04-26 11:15:20 +0530 | [diff] [blame] | 176 | # Delete both autocomplete dicts |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 177 | try: |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 178 | cache.delete(make_key(WEBSITE_ITEM_NAME_AUTOCOMPLETE)) |
| 179 | cache.delete(make_key(WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE)) |
marination | ea30ce4 | 2021-06-02 13:24:06 +0530 | [diff] [blame] | 180 | except Exception: |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 181 | raise_redisearch_error() |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 182 | |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 183 | create_items_autocomplete_dict(autocompleter=item_ac) |
| 184 | create_item_groups_autocomplete_dict(autocompleter=item_group_ac) |
| 185 | |
| 186 | |
| 187 | @if_redisearch_enabled |
| 188 | def create_items_autocomplete_dict(autocompleter): |
| 189 | "Add items as suggestions in Autocompleter." |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 190 | items = frappe.get_all( |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 191 | "Website Item", fields=["web_item_name", "item_group"], filters={"published": 1} |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 192 | ) |
| 193 | |
| 194 | for item in items: |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 195 | autocompleter.add_suggestions(Suggestion(item.web_item_name)) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 196 | |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 197 | |
| 198 | @if_redisearch_enabled |
| 199 | def create_item_groups_autocomplete_dict(autocompleter): |
| 200 | "Add item groups with weightage as suggestions in Autocompleter." |
| 201 | published_item_groups = frappe.get_all( |
| 202 | "Item Group", fields=["name", "route", "weightage"], filters={"show_in_website": 1} |
| 203 | ) |
| 204 | if not published_item_groups: |
| 205 | return |
| 206 | |
| 207 | for item_group in published_item_groups: |
marination | 3445682 | 2022-04-04 12:33:25 +0530 | [diff] [blame] | 208 | payload = json.dumps({"name": item_group.name, "route": item_group.route}) |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 209 | autocompleter.add_suggestions( |
| 210 | Suggestion( |
| 211 | string=item_group.name, |
marination | 7ef1ccb | 2022-04-04 12:04:35 +0530 | [diff] [blame] | 212 | score=frappe.utils.flt(item_group.weightage) or 1.0, |
marination | 07f1745 | 2022-04-01 18:47:01 +0530 | [diff] [blame] | 213 | payload=payload, # additional info that can be retrieved later |
| 214 | ) |
| 215 | ) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 216 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 217 | |
marination | 7e207c8 | 2022-03-31 16:29:18 +0530 | [diff] [blame] | 218 | @if_redisearch_enabled |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 219 | def reindex_all_web_items(): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 220 | items = frappe.get_all("Website Item", fields=get_fields_indexed(), filters={"published": True}) |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 221 | |
marination | b0d7e32 | 2021-06-01 12:44:49 +0530 | [diff] [blame] | 222 | cache = frappe.cache() |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 223 | for item in items: |
| 224 | web_item = create_web_item_map(item) |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 225 | key = make_key(get_cache_key(item.name)) |
| 226 | |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 227 | for field, value in web_item.items(): |
| 228 | super(RedisWrapper, cache).hset(key, field, value) |
Hussain Nagaria | ffc8616 | 2021-04-29 20:47:32 +0530 | [diff] [blame] | 229 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 230 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 231 | def get_cache_key(name): |
| 232 | name = frappe.scrub(name) |
| 233 | return f"{WEBSITE_ITEM_KEY_PREFIX}{name}" |
| 234 | |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 235 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 236 | def get_fields_indexed(): |
| 237 | fields_to_index = frappe.db.get_single_value("E Commerce Settings", "search_index_fields") |
| 238 | fields_to_index = fields_to_index.split(",") if fields_to_index else [] |
| 239 | |
| 240 | mandatory_fields = ["name", "web_item_name", "route", "thumbnail", "ranking"] |
Hussain Nagaria | 8e55c95 | 2021-04-26 07:01:06 +0530 | [diff] [blame] | 241 | fields_to_index = fields_to_index + mandatory_fields |
| 242 | |
| 243 | return fields_to_index |
marination | ea036e4 | 2022-04-04 11:07:53 +0530 | [diff] [blame] | 244 | |
| 245 | |
| 246 | def raise_redisearch_error(): |
| 247 | "Create an Error Log and raise error." |
| 248 | traceback = frappe.get_traceback() |
| 249 | log = frappe.log_error(traceback, frappe._("Redisearch Error")) |
| 250 | log_link = frappe.utils.get_link_to_form("Error Log", log.name) |
| 251 | |
| 252 | frappe.throw( |
| 253 | msg=_("Something went wrong. Check {0}").format(log_link), title=_("Redisearch Error") |
| 254 | ) |