lud

lud

Search engine without external database

Hello,

I have a small project I will work on with a guy who is not a developer. He wants to be able to work on this tool by himself so I will kickstart the project and give him a dev environment. He will work on the client/javascript part.

I will write a tiny backend with Phoenix, and one important aspect of the project is to be able to type a search string in an input field and get a selection of matching object. For example if I type "table blu" I will get those matched names : "Small Blue turntables", "Big table", "Blurry thing", etc. If it is too complicated to implement it is ok to have to type *table to get "Small Blue turntables".

The search actually returns item IDs, not names.

That would be easy with PostgreSQL, here is the problem :

  • Connectivity may be limited sometimes so we want everything to work on a single laptop (no external tool like firebase).
  • His laptop is shared with its family, I would like to avoid installing Postgres or Docker.
  • The items table have a name field, but also another field for the name in French. Mybe that would be in another table if we want to add more languages. “table” is the same word in both languages so when I type a string, I have to search each word in both languages.
  • This setup is only for developing the app, if we make it public, I will have installed Postgres.
  • There will be around 10K items, definitely no more than 20K. When searching for an item, we will search within one of approx. 10 categories, so over 2000 items on average.

I know this sounds like making things complicated for no reason but I believe there is one way to make it run fast.

I was about to load everything in ETS or Mnesia, building a table per category and just walk over the table with a regex, but before I would like to know if someone here had a smart idea, because it will take time to build.
Also there are no table writes, item tables are static, maybe I could extract all unique words form all names, list all items for each of those words, and define static lookup functions with a macro. But regexes are not supported in guards so that would be limited to full and exact words.

Thanks for reading !

Marked As Solved

lucaong

lucaong

This sounds like a great use-case for MiniSearch, a client-side full-text search engine written in JavaScript, small enough to run in the browser and with zero dependencies (disclaimer: I am the author of the library).

MiniSearch is routinely used for searching amongst tens of thousands of small items (e.g. all products in the catalog of a supplier), and the data can be indexed upon each page load (it usually takes sub-second, and can be done asynchronously).

Here’s a demo on a database of ~5000 songs.

Also Liked

lud

lud

It does not sound weird at all, it is actually nice. Data will be small since the browser will be fed with only id id/name/name_fr subset of the data, as there is no need to download the full items database.

And so instead of loading my data in tables I just have to build static lookup modules with macros.

Thank you !

lud

lud

I generally go with Svelte but that will be good guidelines :smiley:

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement