ODataAngularResources icon indicating copy to clipboard operation
ODataAngularResources copied to clipboard

Query for search string inside field [Solution]

Open oleg-demkovych opened this issue 8 years ago • 1 comments

Here is some solution to search inside field. I.e. we have:

"text": "some TEST here"

We want to get search by text TEST.

new $odata.Func('startswith','Text', 'TEST') will return empty, because test inside string (not on the start). Solution:

  1. Set our search field to lowercase: var lowerFilter = new $odata.Func('tolower', 'Text');

  2. Create new function to get index of out search text: var filterDataIndex = new $odata.Func('indexof', lowerFilter, 'TEST'.toLowerCase());

  3. Create new predicate, with filter param (ge 0): var resultFilter = new $odata.Predicate(filterDataIndex, '>=', 0);

  4. Create combination with predicates: var combination = $odata.Predicate.or([resultFilter]);

  5. Send query and get data: service.filter(combination).query(success)

oleg-demkovych avatar Feb 17 '17 11:02 oleg-demkovych

Thanks! That may help.

devnixs avatar Feb 17 '17 13:02 devnixs