Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query for search string inside field [Solution] #100

Open
oleg-demkovych opened this issue Feb 17, 2017 · 1 comment
Open

Query for search string inside field [Solution] #100

oleg-demkovych opened this issue Feb 17, 2017 · 1 comment

Comments

@oleg-demkovych
Copy link

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 oleg-demkovych changed the title Query for search string inside field Query for search string inside field [Solution] Feb 17, 2017
@devnixs
Copy link
Owner

devnixs commented Feb 17, 2017

Thanks! That may help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants