Search code examples
javascriptjsonpostgresqlloopbackjs

Loopback search on all fields


I am using loopback as a backend now I wish to be able to search across all fields in the table

For instance, take the following table fields:

id, name, title, created, updated

Now say I want to search across the table using the following string "nomad"

However, I am unsure how to structure the query

I have attempted:

{"where": {"keywords": {"inq": ["nomad"]}}}

However, this just returns all results

So how do I do this? :)

If it matters my database is a postgresql


Solution

  • Loopback is not where you need to look at. It's just a framework with universal ORM / ODM to connect to your DB and expose is with a query language over rest. You probably need in your case to add a text index in your postgresql database. By indexing all your desired properties into a text index, you'll be able to perform search in your DB.

    Here is the documentation. https://www.postgresql.org/docs/9.5/static/textsearch.html

    You can still achieve your goal using loopback ORM with something like

    {"where": {"prop1": {"regex": "nomad"}, "prop2": {"regex": "nomad"}}}

    but your DB will die in few queries ...