Skip to content

Support for Full Text Search #772

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 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Parse/src/main/java/com/parse/ParseQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,14 @@ public Builder<T> whereGeoIntersects(String key, ParseGeoPoint point) {
return addCondition(key, "$geoIntersects", dictionary);
}

public Builder<T> whereText(String key, String value) {
Map<String, String> termDictionary = new HashMap<>();
Map<String, Map<String, String>> searchDictionary = new HashMap<>();
termDictionary.put("$term", value);
searchDictionary.put("$search", termDictionary);
return addCondition(key, "$text", searchDictionary);
}

public Builder<T> addCondition(String key, String condition,
Collection<? extends Object> value) {
return addConditionInternal(key, condition, Collections.unmodifiableCollection(value));
Expand Down Expand Up @@ -1683,6 +1691,23 @@ public ParseQuery<T> whereContainsAll(String key, Collection<?> values) {
return this;
}

/**
* Adds a constraint for finding string values that contain a provided
* string using Full Text Search
*
* Requires Parse-Server@2.5.0
*
* @param key
* The key to be constrained.
* @param text
* String to be searched
* @return this, so you can chain this call.
*/
public ParseQuery<T> whereFullText(String key, String text) {
builder.whereText(key, text);
return this;
}

/**
* Add a constraint to the query that requires a particular key's value match another
* {@code ParseQuery}.
Expand Down
16 changes: 16 additions & 0 deletions Parse/src/test/java/com/parse/ParseQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ public void testWhereContainedIn() throws Exception {
verifyCondition(query, "key", "$in", values);
}

@Test
public void testWhereFullText() throws Exception {
ParseQuery<ParseObject> query = new ParseQuery<>("Test");
String text = "TestString";
query.whereFullText("key", text);

// We generate a state to verify the content of the builder
ParseQuery.State state = query.getBuilder().build();
ParseQuery.QueryConstraints queryConstraints = state.constraints();
ParseQuery.KeyConstraints keyConstraints = (ParseQuery.KeyConstraints) queryConstraints.get("key");
Map searchDictionary = (Map) keyConstraints.get("$text");
Map termDictionary = (Map) searchDictionary.get("$search");
String value = (String) termDictionary.get("$term");
assertEquals(value, text);
}

@Test
public void testWhereContainsAll() throws Exception {
ParseQuery<ParseObject> query = new ParseQuery<>("Test");
Expand Down