I am having some trouble getting the data I want from a Typeorm query.
Basically, we have a search bar for the users to search our database of products (medicines). I want to select all records from the database that include every word the user entered. (These words are split into an array of values.) It might not be a perfect match for the product name, so I'm thinking I should use LIKE?
We have English, Japanese, and Chinese results in the database. I want to search the English name (nameEn), Japanese name (nameJa), and Chinese name (nameZh) for any results that contain all the user's search queries.
I'm unsure how I can programmatically loop over the search queries as well as building the query for Typeorm at the same time.
Current code:
const medicines = await getRepository(Medicine)
.createQueryBuilder('medicine')
.where('medicine.nameEn like :query', { query: '%bufferin%' })
.andWhere(
new Brackets((qb) => {
qb.where('medicine.nameEn like :query1', {
query1: '%luna%',
}).orWhere('medicine.nameEn like :query2', { query2: 'EX' });
}),
)
.getMany();
This works for getting English products that match... but right now I've just hard coded in the query "bufferin luna EX". How would I do this if it was ['bufferin', 'luna', 'EX'], and also wanted to check nameJa and nameZh?
Thank you very much for your time.