how to search string in whole string in loopback query

Viewed 505

I want search whole string when I type any word, it's matched only first Character not matched whole string and middle character of string.

query.and.push({ or: [{ name: { like: '^' + data.searchTextNEM + '.*', options: 'i' } }, { email: { like: '^' + data.searchTextNEM + '.*', options: 'i' } },{ phone: { like: '^' + data.searchTextNEM + '.*', options: 'i' } }]});

Users.find({where: query, limit: data.limit,skip: data.skip },function(err,res){})

Like I have two string 1.mark and 2.denim if I type 'm' my response should be mark and denim but getting response only mark

2 Answers

You may have try this:-

name: { ilike: '%' + data.searchTextNEM + '%' }

It will also match with case insensitive text.

or:

you may have pass the options in like filter:-

?filter={"where":{"title":{"like":"someth.*","options":"i"}}}

I think your regex is incorrect. If you insert 'm' your regex becomes ^m.* which means "starts with m and then has any number of any characters". I think you want .*m.* which means "has any number of any character, then an m, then any number of any character":

query.and.push({ or: [{ name: { like: '.*' + data.searchTextNEM + '.*', options: 'i' } }, { email: { like: '.*' + data.searchTextNEM + '.*', options: 'i' } },{ phone: { like: '.*' + data.searchTextNEM + '.*', options: 'i' } }]});
 Users.find({where: query, limit: data.limit,skip: data.skip },function(err,res){
})
Related