Skip to content

Added/fixed a filtering option "contains string" for String fields. #724

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

Merged
merged 2 commits into from
Jun 13, 2017

Conversation

ssamuli
Copy link
Contributor

@ssamuli ssamuli commented Jun 12, 2017

There are options "startsWith" and "endsWith" in the filter input for string fields, but "contains string" option is for some reason missing, so I made this change. In my opinion it is pretty important feature for people who use dashboard to browse their parse data.

It does filtering case insensitively for now. Could maybe add later a checkbox for selecting case sensitivity.

screen shot 2017-06-12 at 14 13 34

@natanrolnik
Copy link
Contributor

Thanks for your PR, @ssamuli. I left one small note.

@@ -60,6 +60,8 @@ function addConstraint(query, filter) {
query.greaterThan(filter.get('field'), filter.get('compareTo'));
break;
case 'containsString':
query.matches(filter.get('field'), filter.get('compareTo'), 'i');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation in Parse.query states only two parameters: key and regex. What's the 'i' string you pass here?

Copy link
Contributor Author

@ssamuli ssamuli Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its an undocumented "modifiers" parameter to "matches" function of ParseQuery, 'i' means case insensitive: https://github.com/parse-community/Parse-SDK-JS/blob/master/src/ParseQuery.js#L714

In retrospect, looking at the ParseQuery code, it seems to be possible to pass 'case insensitive' inside the second parameter (regex) too.

@ssamuli
Copy link
Contributor Author

ssamuli commented Jun 13, 2017

Is there something you'd like me to change or add to this feature to facilitate the merging process?

@natanrolnik
Copy link
Contributor

One last question I have before merging, as I was working on something very similar (allowing to filter if a pointer exists or not): before your changes, both containsString and containsNumber had the same query method on them, but it didn't matter because containsString wasn't activated in src/lib/Filters.js. Is my understanding correct?

@ssamuli
Copy link
Contributor Author

ssamuli commented Jun 13, 2017

You are correct, it was not activated in Filters.js.

Also the query was not correct because it fell through to case 'containsNumber', which does an equalTo query. This works for finding strings and numbers from arrays but not from inside other strings. For strings it would only find ones that are a 100% match.

Maybe to make things more clear and not change how the query behaves with arrays (although this seems to work with them too), I should add a new Constraint in Filters.js? stringContainsString or similar and make a new 'case' for that in queryFromFilters?

@ssamuli
Copy link
Contributor Author

ssamuli commented Jun 13, 2017

Should be better and safer like this. Didn't think of the array query much when I initially sent the PR.

Copy link
Contributor

@natanrolnik natanrolnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I think it's better!
Thanks, @ssamuli !

@natanrolnik natanrolnik merged commit 095be94 into parse-community:master Jun 13, 2017
@natanrolnik
Copy link
Contributor

natanrolnik commented Jun 13, 2017

Also, @ssamuli, I was trying recently to do something to fix #720 .
I played a little bit with it, and it was harder than what I imagined.

Initially, we could add at least an option to have exists and does not exist for objects - that's currently not available and works out of the box with the current query.exists(filter.get('field')); or query.doesNotExist(filter.get('field'));, just by adding Object to FieldConstraints.

What do you say? Could you help us with this?

@ssamuli ssamuli deleted the dev branch June 13, 2017 13:43
@ssamuli
Copy link
Contributor Author

ssamuli commented Jun 13, 2017

Thanks! Looks like that's something I can help with.

@natanrolnik
Copy link
Contributor

Bear in mind that you should use dot notation for this:
query.equalTo("column.numberProp", 42)

@ssamuli
Copy link
Contributor Author

ssamuli commented Jun 13, 2017

@natanrolnik OK, here it is: #727

@dplewis dplewis mentioned this pull request May 3, 2019
3 tasks
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

Successfully merging this pull request may close these issues.

2 participants