safwansamsudeen / frappe_search

MIT License
6 stars 2 forks source link

Inflexible configurations #2

Open netchampfaris opened 9 months ago

netchampfaris commented 9 months ago

The index path is hardcoded, must have been an oversight. I think index should be specific to a site and should go inside the site folder.

https://github.com/safwansamsudeen/frappe_search/blob/e25eaa5fc7b73b6f76e9d71fb39cd3b3586a6a34/frappe_search/frappe_search/doctype/search/search.py#L21

This is the error I got when I ran the command bench --site gameplan.frappe.test execute frappe_search.api.build_index

Traceback (most recent call last):
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/commands/utils.py", line 276, in execute
    ret = frappe.get_attr(method)(*args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe_search/frappe_search/api.py", line 19, in build_index
    return build_complete_index(auto_index)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe_search/frappe_search/frappe_search/doctype/search/search.py", line 244, in build_complete_index
    index = Index(schema, path=INDEX_PATH)
ValueError: Directory does not exist: '/Users/safwan/frappe-bench/apps/frappe_search/index'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.10/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 114, in <module>
    main()
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/Users/netchampfaris/Projects/frappe-bench/apps/frappe/frappe/commands/utils.py", line 279, in execute
    ret = eval(method + "(*args, **kwargs)", globals(), locals())  # nosemgrep
  File "<string>", line 1, in <module>
NameError: name 'frappe_search' is not defined

https://github.com/safwansamsudeen/frappe_search/blob/e25eaa5fc7b73b6f76e9d71fb39cd3b3586a6a34/frappe_search/api.py#L10-L13

There shouldn't be a case where boolean value is sent as string. Also group_by > groupby.


Finally the search API call also breaks with the following error:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1779, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe_search/frappe_search/api.py", line 14, in search
    return tantivy_search(query, target_number, groupby)
  File "apps/frappe_search/frappe_search/frappe_search/doctype/search/search.py", line 43, in tantivy_search
    query = index.parse_query(
TypeError: Index.parse_query() got an unexpected keyword argument 'fuzzy_fields'

Other:

safwansamsudeen commented 9 months ago

@netchampfaris I remember some API call with frappe.call sent it over as a string.

That is weird - search works for me. Are you sure you have the latest version? Fuzzy fields is only supported after tantivy-py#202 was merged.

You can now test this by creating the directory frappe-search-index in your site.