heywhy / ex_elasticlunr

Elasticlunr is a small, full-text search library for use in the Elixir environment. It indexes JSON documents and provides a friendly search interface to retrieve documents.
https://hexdocs.pm/elasticlunr
MIT License
189 stars 9 forks source link

Livebook issues #13

Closed fceruti closed 2 years ago

fceruti commented 2 years ago

When running the last statement under the section Nested document attributes, the following error appears:

search_query = IO.gets("Search users")
Index.search(users_index, search_query)
** (FunctionClauseError) no function clause matching in Elasticlunr.Index.search/3

The following arguments were given to Elasticlunr.Index.search/3:

    # 1
    %Elasticlunr.Index{documents_size: 4, fields: %{"address" => (...) , ref: "id", store_documents: true, store_positions: true}

    # 2
    {:error, :enotsup}

    # 3
    nil

Attempted function clauses (showing 6 out of 6):

    def search(%Elasticlunr.Index{}, -nil-, _opts)
    def search(%Elasticlunr.Index{ref: ref} = index, query, nil) when -is_binary(query)-
    def search(%Elasticlunr.Index{ref: ref} = index, query, -%{"fields" => fields}-) when -is_binary(query)-
    def search(%Elasticlunr.Index{} = index, -%{"query" => _} = query-, _opts)
    def search(%Elasticlunr.Index{} = index, query, nil) when -is_map(query)-
    def search(%Elasticlunr.Index{} = index, -%{} = query-, options)

    (elasticlunr 0.6.4) lib/elasticlunr/core/index.ex:182: Elasticlunr.Index.search/3

I think this is connect to a warning LiveBook gave me about not using Kino.input.

When I modify the code like below, everything works fine:

search_query = "find something"
Index.search(users_index, search_query)

Software Versions: Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit] [dtrace] Elixir 1.13.0 (compiled with Erlang/OTP 24) Livebook 0.4.1

heywhy commented 2 years ago

I think I remember someone else reporting similar issue. I will have to update my livebook version and update the affected code in the document.

heywhy commented 2 years ago

@fceruti Thank you for reporting this. It is now resolved, you should use the updated document. And confirm if it works on your end.

fceruti commented 2 years ago

@heywhy I just checked the whole livebook, and everything is working great!