@@ -116,32 +116,49 @@ class QueryBuilder<T extends ParseObject> {
116116 limiters['include' ] = concatenateArray (objectTypes);
117117 }
118118
119- /// Returns an object where the [String] column starts with [value]
120- void whereStartsWith (String column, String query,
121- {bool caseSensitive = false }) {
119+ /// Add a constraint for finding objects where the String value in [column]
120+ /// starts with [prefix]
121+ void whereStartsWith (
122+ String column,
123+ String prefix, {
124+ bool caseSensitive = false ,
125+ }) {
126+ prefix = Uri .encodeComponent (prefix);
127+
122128 if (caseSensitive) {
123129 queries.add (MapEntry <String , dynamic >(
124- _singleQuery, '"$column ":{"\$ regex": "^$query "}' ));
130+ _singleQuery, '"$column ":{"\$ regex": "^$prefix "}' ));
125131 } else {
126132 queries.add (MapEntry <String , dynamic >(
127- _singleQuery, '"$column ":{"\$ regex": "^$query ", "\$ options": "i"}' ));
133+ _singleQuery, '"$column ":{"\$ regex": "^$prefix ", "\$ options": "i"}' ));
128134 }
129135 }
130136
131- /// Returns an object where the [String] column ends with [value]
132- void whereEndsWith (String column, String query,
133- {bool caseSensitive = false }) {
137+ /// Add a constraint for finding objects where the String value in [column]
138+ /// ends with [prefix]
139+ void whereEndsWith (
140+ String column,
141+ String prefix, {
142+ bool caseSensitive = false ,
143+ }) {
144+ prefix = Uri .encodeComponent (prefix);
145+
134146 if (caseSensitive) {
135147 queries.add (MapEntry <String , dynamic >(
136- _singleQuery, '"$column ":{"\$ regex": "$query \$ "}' ));
148+ _singleQuery, '"$column ":{"\$ regex": "$prefix \$ "}' ));
137149 } else {
138- queries.add (MapEntry <String , dynamic >(
139- _singleQuery, '"$column ":{"\$ regex": "$query \$ ", "\$ options": "i"}' ));
150+ queries.add (MapEntry <String , dynamic >(_singleQuery,
151+ '"$column ":{"\$ regex": "$prefix \$ ", "\$ options": "i"}' ));
140152 }
141153 }
142154
143- /// Returns an object where the [String] column equals [value]
155+ /// Add a constraint to the query that requires a particular [column] 's value
156+ /// to be equal to the provided [value]
144157 void whereEqualTo (String column, dynamic value) {
158+ if (value is String ) {
159+ value = Uri .encodeComponent (value);
160+ }
161+
145162 queries.add (_buildQueryWithColumnValueAndOperator (
146163 MapEntry <String , dynamic >(column, value), _noOperatorNeeded));
147164 }
@@ -174,8 +191,13 @@ class QueryBuilder<T extends ParseObject> {
174191 MapEntry <String , dynamic >(column, value), '\$ gte' ));
175192 }
176193
177- /// Returns an object where the [String] column is not equal to value
194+ /// Add a constraint to the query that requires a particular [column] 's value
195+ /// to be not equal to the provided [value]
178196 void whereNotEqualTo (String column, dynamic value) {
197+ if (value is String ) {
198+ value = Uri .encodeComponent (value);
199+ }
200+
179201 queries.add (_buildQueryWithColumnValueAndOperator (
180202 MapEntry <String , dynamic >(column, value), '\$ ne' ));
181203 }
@@ -229,26 +251,38 @@ class QueryBuilder<T extends ParseObject> {
229251 MapEntry <String , dynamic >(column, value), '\$ regex' ));
230252 }
231253
232- /// Performs a search to see if [String] contains other string
233- void whereContains (String column, String value,
234- {bool caseSensitive = false }) {
254+ /// Add a constraint for finding String values that contain the provided
255+ /// [substring]
256+ void whereContains (
257+ String column,
258+ String substring, {
259+ bool caseSensitive = false ,
260+ }) {
261+ substring = Uri .encodeComponent (substring);
262+
235263 if (caseSensitive) {
236264 queries.add (MapEntry <String , dynamic >(
237- _singleQuery, '"$column ":{"\$ regex": "$value "}' ));
265+ _singleQuery, '"$column ":{"\$ regex": "$substring "}' ));
238266 } else {
239- queries.add (MapEntry <String , dynamic >(
240- _singleQuery, '"$column ":{"\$ regex": "$value ", "\$ options": "i"}' ));
267+ queries.add (MapEntry <String , dynamic >(_singleQuery,
268+ '"$column ":{"\$ regex": "$substring ", "\$ options": "i"}' ));
241269 }
242270 }
243271
244- /// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including whether they are case sensitive or not.
245- /// This search can also order by the score of the search
246- void whereContainsWholeWord (String column, String query,
247- {bool caseSensitive = false ,
248- bool orderByScore = true ,
249- bool diacriticSensitive = false }) {
272+ /// Powerful search for containing whole words. This search is much quicker
273+ /// than regex and can search for whole words including whether they are case
274+ /// sensitive or not. This search can also order by the score of the search
275+ void whereContainsWholeWord (
276+ String column,
277+ String searchTerm, {
278+ bool caseSensitive = false ,
279+ bool orderByScore = true ,
280+ bool diacriticSensitive = false ,
281+ }) {
282+ searchTerm = Uri .encodeComponent (searchTerm);
283+
250284 queries.add (MapEntry <String , dynamic >(_singleQuery,
251- '"$column ":{"\$ text":{"\$ search":{"\$ term": "$query ", "\$ caseSensitive": $caseSensitive , "\$ diacriticSensitive": $diacriticSensitive }}}' ));
285+ '"$column ":{"\$ text":{"\$ search":{"\$ term": "$searchTerm ", "\$ caseSensitive": $caseSensitive , "\$ diacriticSensitive": $diacriticSensitive }}}' ));
252286 if (orderByScore) {
253287 orderByAscending ('\$ score' );
254288 keysToReturn (['\$ score' ]);
0 commit comments