简体   繁体   中英

how to search string in whole string in loopback query

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

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){
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM