Skip to content

Commit af10e53

Browse files
dplewisrogerhu
authored andcommitted
Support for Full Text Search (#772)
1 parent 60810e9 commit af10e53

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Parse/src/main/java/com/parse/ParseQuery.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,14 @@ public Builder<T> whereGeoIntersects(String key, ParseGeoPoint point) {
480480
return addCondition(key, "$geoIntersects", dictionary);
481481
}
482482

483+
public Builder<T> whereText(String key, String value) {
484+
Map<String, String> termDictionary = new HashMap<>();
485+
Map<String, Map<String, String>> searchDictionary = new HashMap<>();
486+
termDictionary.put("$term", value);
487+
searchDictionary.put("$search", termDictionary);
488+
return addCondition(key, "$text", searchDictionary);
489+
}
490+
483491
public Builder<T> addCondition(String key, String condition,
484492
Collection<? extends Object> value) {
485493
return addConditionInternal(key, condition, Collections.unmodifiableCollection(value));
@@ -1683,6 +1691,23 @@ public ParseQuery<T> whereContainsAll(String key, Collection<?> values) {
16831691
return this;
16841692
}
16851693

1694+
/**
1695+
* Adds a constraint for finding string values that contain a provided
1696+
* string using Full Text Search
1697+
*
1698+
* Requires Parse-Server@2.5.0
1699+
*
1700+
* @param key
1701+
* The key to be constrained.
1702+
* @param text
1703+
* String to be searched
1704+
* @return this, so you can chain this call.
1705+
*/
1706+
public ParseQuery<T> whereFullText(String key, String text) {
1707+
builder.whereText(key, text);
1708+
return this;
1709+
}
1710+
16861711
/**
16871712
* Add a constraint to the query that requires a particular key's value match another
16881713
* {@code ParseQuery}.

Parse/src/test/java/com/parse/ParseQueryTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ public void testWhereContainedIn() throws Exception {
363363
verifyCondition(query, "key", "$in", values);
364364
}
365365

366+
@Test
367+
public void testWhereFullText() throws Exception {
368+
ParseQuery<ParseObject> query = new ParseQuery<>("Test");
369+
String text = "TestString";
370+
query.whereFullText("key", text);
371+
372+
// We generate a state to verify the content of the builder
373+
ParseQuery.State state = query.getBuilder().build();
374+
ParseQuery.QueryConstraints queryConstraints = state.constraints();
375+
ParseQuery.KeyConstraints keyConstraints = (ParseQuery.KeyConstraints) queryConstraints.get("key");
376+
Map searchDictionary = (Map) keyConstraints.get("$text");
377+
Map termDictionary = (Map) searchDictionary.get("$search");
378+
String value = (String) termDictionary.get("$term");
379+
assertEquals(value, text);
380+
}
381+
366382
@Test
367383
public void testWhereContainsAll() throws Exception {
368384
ParseQuery<ParseObject> query = new ParseQuery<>("Test");

0 commit comments

Comments
 (0)