@@ -116,32 +116,49 @@ class QueryBuilder<T extends ParseObject> {
116
116
limiters['include' ] = concatenateArray (objectTypes);
117
117
}
118
118
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
+
122
128
if (caseSensitive) {
123
129
queries.add (MapEntry <String , dynamic >(
124
- _singleQuery, '"$column ":{"\$ regex": "^$query "}' ));
130
+ _singleQuery, '"$column ":{"\$ regex": "^$prefix "}' ));
125
131
} else {
126
132
queries.add (MapEntry <String , dynamic >(
127
- _singleQuery, '"$column ":{"\$ regex": "^$query ", "\$ options": "i"}' ));
133
+ _singleQuery, '"$column ":{"\$ regex": "^$prefix ", "\$ options": "i"}' ));
128
134
}
129
135
}
130
136
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
+
134
146
if (caseSensitive) {
135
147
queries.add (MapEntry <String , dynamic >(
136
- _singleQuery, '"$column ":{"\$ regex": "$query \$ "}' ));
148
+ _singleQuery, '"$column ":{"\$ regex": "$prefix \$ "}' ));
137
149
} 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"}' ));
140
152
}
141
153
}
142
154
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]
144
157
void whereEqualTo (String column, dynamic value) {
158
+ if (value is String ) {
159
+ value = Uri .encodeComponent (value);
160
+ }
161
+
145
162
queries.add (_buildQueryWithColumnValueAndOperator (
146
163
MapEntry <String , dynamic >(column, value), _noOperatorNeeded));
147
164
}
@@ -174,8 +191,13 @@ class QueryBuilder<T extends ParseObject> {
174
191
MapEntry <String , dynamic >(column, value), '\$ gte' ));
175
192
}
176
193
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]
178
196
void whereNotEqualTo (String column, dynamic value) {
197
+ if (value is String ) {
198
+ value = Uri .encodeComponent (value);
199
+ }
200
+
179
201
queries.add (_buildQueryWithColumnValueAndOperator (
180
202
MapEntry <String , dynamic >(column, value), '\$ ne' ));
181
203
}
@@ -229,26 +251,38 @@ class QueryBuilder<T extends ParseObject> {
229
251
MapEntry <String , dynamic >(column, value), '\$ regex' ));
230
252
}
231
253
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
+
235
263
if (caseSensitive) {
236
264
queries.add (MapEntry <String , dynamic >(
237
- _singleQuery, '"$column ":{"\$ regex": "$value "}' ));
265
+ _singleQuery, '"$column ":{"\$ regex": "$substring "}' ));
238
266
} 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"}' ));
241
269
}
242
270
}
243
271
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
+
250
284
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 }}}' ));
252
286
if (orderByScore) {
253
287
orderByAscending ('\$ score' );
254
288
keysToReturn (['\$ score' ]);
0 commit comments