etso icon indicating copy to clipboard operation
etso copied to clipboard

like support in Etso?

Open kpanic opened this issue 4 years ago • 6 comments

Hello! thanks for Etso!

I was wondering if it would make sense to implement https://hexdocs.pm/ecto/Ecto.Query.API.html#like/2 in Etso to have basic search capabilities.

A "trick" for prefix search could be something like

iex(55)> :ets.new(:test, [:named_table])
:test
iex(56)> :ets.insert(:test, {'key1', 'like'})
true
iex(57)> :ets.insert(:test, {'key2', 'like2'})
true
iex(58)> :ets.insert(:test, {'key3', 'will like'})
true
iex(59)> :ets.select(:test, [{{'key1' ++ :_, :_}, [], [:"$_"]}])
[{'key1', 'like'}]
iex(60)> :ets.select(:test, [{{'key2' ++ :_, :_}, [], [:"$_"]}])
[{'key2', 'like2'}]
iex(61)> :ets.select(:test, [{{'key' ++ :_, :_}, [], [:"$_"]}]) 
[{'key2', 'like2'}, {'key1', 'like'}, {'key3', 'will like'}]
iex(62)> :ets.select(:test, [{{:_, 'will' ++ :_}, [], [:"$_"]}])         
[{'key3', 'will like'}]
iex(63)> :ets.select(:test, [{{:_, 'like' ++ :_}, [], [:"$_"]}])
[{'key2', 'like2'}, {'key1', 'like'}]

that would satisfy "a_string%", however for "%like" might be trickier

kpanic avatar Aug 15 '21 18:08 kpanic

Agreed fully. This is viable.

I do wonder how we could accommodate UPDATE WHERE and DELETE WHERE etc. Currently we do not have support for transactions.

evadne avatar Aug 15 '21 18:08 evadne

Note https://elixirforum.com/t/how-to-partially-match-a-string-in-ets-match-specs/2533/3

evadne avatar May 20 '22 12:05 evadne

@evadne sorry for super slow reply. I have been busy. However, I just tried

:ets.select(:test, [{{[:_| 'ey2'], :_}, [], [:"$_"]}]) 
[{'key2', 'like2'}]

And it looks like that we could support:

  • LIKE '%string'
  • LIKE 'string%'
  • LIKE '%string%'

Do you want me to give it a shot in implementing it?

kpanic avatar Jun 19 '22 16:06 kpanic

@kpanic Fantastic news, please indeed try :)

evadne avatar Jun 19 '22 18:06 evadne

@kpanic Any joy?

evadne avatar Jun 27 '22 19:06 evadne

@evadne Nope for now. Please be patient. 🙏🏾 I had a look into etso code and thought about an approach, but still kinda busy and enjoying the heatwave also here 🚒 I might have time this weekend 🙏🏾

kpanic avatar Jun 27 '22 20:06 kpanic