Repository: frappe/erpnext
Pull request: fix: no module named 'redisearch'
This PR aims to fix the module not found error while installing ERPNext.
Objectives:

- [x] Rename `erpnext/e_commerce/redisearch.py`
- [x] Rename its references

Closes #28730

Problem statement:
Error: No module named 'redisearch' while installing ERPNext.
**Issue:**
Ran `bench get-app erpnext` and then `bench install-app erpnext`
Cannot install ERPNext.
```
Installing erpnext...
Updating DocTypes for erpnext       : [=================== ] 99%
An error occurred while installing erpnext:
Module import failed for Website Item (erpnext.e_commerce.doctype.website_item.website_item 
Error: No module named 'redisearch')
```

Ran `bench setup requirements` and tried again but to no avail.
Tried installing redisearch via pip(and pip3) in the venv but no effect.
```
frappe@ubuntu:~/frappe-bench$ ./env/bin/pip install redisearch
Requirement already satisfied: redisearch in ./env/lib/python3.7/site-packages (2.0.0)
Requirement already satisfied: redis>=2.10 in ./env/lib/python3.7/site-packages (from redisearch) (3.5.3)
Requirement already satisfied: hiredis>=0.2.0 in ./env/lib/python3.7/site-packages (from redisearch) (2.0.0)
Requirement already satisfied: six>=1.10.0 in ./env/lib/python3.7/site-packages (from redisearch) (1.15.0)
Requirement already satisfied: rmtest>=0.2 in ./env/lib/python3.7/site-packages (from redisearch) (0.7.0)
```

Error log when I try to run the file:
```
frappe@ubuntu:~/frappe-bench$ ./env/bin/python ./apps/erpnext/erpnext/e_commerce/redisearch.py
Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/e_commerce/redisearch.py", line 6, in <module>
    from redisearch import AutoCompleter, Client, IndexDefinition, Suggestion, TagField, TextField
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/e_commerce/redisearch.py", line 6, in <module>
    from redisearch import AutoCompleter, Client, IndexDefinition, Suggestion, TagField, TextField
ImportError: cannot import name 'AutoCompleter' from 'redisearch' 
(/home/frappe/frappe-bench/apps/erpnext/erpnext/e_commerce/redisearch.py)
```
At the same time, from inside venv, I can import those without any issues.
```
(env) frappe@ubuntu:~/frappe-bench$ python3
Python 3.7.5 (default, Feb 23 2021, 13:22:40) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import redisearch
>>> from redisearch import AutoCompleter, Client, IndexDefinition, Suggestion, TagField, TextField
>>> exit()
```

**Solution:**
I suspect naming issues. The file is also named redisearch and the package is also named redisearch.

As suspected, the issue was with the name. I renamed the file to `rsearch.py` and tried.
```
frappe@ubuntu:~/frappe-bench$ source env/bin/activate
(env) frappe@ubuntu:~/frappe-bench$ python3 ./apps/erpnext/erpnext/e_commerce/rsearch.py
(env) frappe@ubuntu:~/frappe-bench$ 
```

Runs without any issues.
Please look into this @marination @NagariaHussain @ankush

Hints from issue discussion:
Very similar to https://github.com/frappe/frappe/pull/14093 

Probably just need to rename the file and fix all the references. 

@rtdany10 interested in fixing this? :grinning: 
> @rtdany10 interested in fixing this? grinning

Haha, I was planning to send a fix right away, but [github doesn't tell me where all this file/module is referenced](https://github.com/frappe/erpnext/search?q=redisearch) and I have no idea where all this file is imported or used. I shall open a PR and try rename wherever I find it, but might need help from you guys. :)
github is only showing results from `develop` branch. Since this affects v13 only you'll have to search it locally :P 

I think the usage of it is quite limited. Just used in e-commerce search. 
> github is only showing results from `develop` branch. Since this affects v13 only you'll have to search it locally :P
> 
> I think the usage of it is quite limited. Just used in e-commerce search.

In that case, you can unassign @aaronmenezes  
I shall send a PR shortly :smile:

Commit message: fix: rename ref in product_search.py

Patch to review:
diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
index 1b0480bbf0de..4c4836e14c0b 100644
--- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
+++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
@@ -6,7 +6,7 @@
 from frappe.model.document import Document
 from frappe.utils import comma_and, flt, unique
 
-from erpnext.e_commerce.redisearch import (
+from erpnext.e_commerce.rsearch import (
 	create_website_items_index,
 	get_indexable_web_fields,
 	is_search_module_loaded,
diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py
index b4d06b3542fe..85d9333d3764 100644
--- a/erpnext/e_commerce/doctype/website_item/website_item.py
+++ b/erpnext/e_commerce/doctype/website_item/website_item.py
@@ -11,7 +11,7 @@
 from frappe.website.website_generator import WebsiteGenerator
 
 from erpnext.e_commerce.doctype.item_review.item_review import get_item_reviews
-from erpnext.e_commerce.redisearch import (
+from erpnext.e_commerce.rsearch import (
 	delete_item_from_index,
 	insert_item_to_index,
 	update_index_for_item,
diff --git a/erpnext/e_commerce/redisearch.py b/erpnext/e_commerce/rsearch.py
similarity index 100%
rename from erpnext/e_commerce/redisearch.py
rename to erpnext/e_commerce/rsearch.py
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index 99ad648e5308..0229dc6545ce 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -5,7 +5,7 @@
 from frappe.utils import cint, cstr
 from redisearch import AutoCompleter, Client, Query
 
-from erpnext.e_commerce.redisearch import (
+from erpnext.e_commerce.rsearch import (
 	WEBSITE_ITEM_CATEGORY_AUTOCOMPLETE,
 	WEBSITE_ITEM_INDEX,
 	WEBSITE_ITEM_NAME_AUTOCOMPLETE,


Code review comments:
diff_hunk: @@ -6,7 +6,7 @@
 from frappe.model.document import Document
 from frappe.utils import comma_and, flt, unique
 
-from erpnext.e_commerce.redisearch import (
+from erpnext.e_commerce.rsearch import (
path: erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py
text: @user1:
'redisearch_utils' or would be a better name for this IMO. 

It will make it clearer without opening the file what this file exactly contains. 

@user2:
agree with @user1 it's also consistent with other util files 👍 

@author:
Agreed, have done that :smile: