How to search data in all tables from my database? I need to create some sort of search like is on Github where after entering the phrase into the search engine, it looks for us both repositories, issues and users, I need to do something like this but with searching in entities like: User, Order and Projects,
I'm using TypeORM and simple search query looks like below:
const data = await this.conn
.getRepository(Order)
.createQueryBuilder('order')
.where('order.name = :name ', { name : name })
.leftJoin('order.author', 'author')
.orderBy('order.lastUpdate', 'DESC');
but how to search not only in Order entity but also in other tables like User and Projects? How the biggest company search engine works?
Big companies such as google base their technologies on AI now, using them as a system to organise Big Data (see more on that here). However, google originally used the Page Rank algorithm that would assign higher values to websites that had high referral rates from other sites (see here).
It sounds like what you would get the most from is the LIKE keyword (see the basics) in combination with the UNION keyword (info here).
You could probably get some good results with something like this in SQL (I dont know TypeORM):
SELECT * FROM table1 WHERE name LIKE '%searchterm%'
UNION
SELECT * FROM table2 WHERE name LIKE '%searchterm%';