like support in Etso?
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
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.
Note https://elixirforum.com/t/how-to-partially-match-a-string-in-ets-match-specs/2533/3
@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 Fantastic news, please indeed try :)
@kpanic Any joy?
@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 🙏🏾