admin管理员组

文章数量:1391975

I'm trying to create a search function in javascript using parse where a field contains a string. I've already search through the documents of parse but I can't find something similar to what I want. I want to query something like this:

query.like("contents", "%string%"); // example only this code does not exist.

Can any one know what method in parse I need?

In iOS I find this method whereKey:containsString: but I think containsString is not available in javascript.

I'm trying to create a search function in javascript using parse. where a field contains a string. I've already search through the documents of parse. but I can't find something similar to what I want. I want to query something like this:

query.like("contents", "%string%"); // example only this code does not exist.

Can any one know what method in parse I need?

In iOS I find this method whereKey:containsString: but I think containsString is not available in javascript.

Share Improve this question edited Jan 21, 2014 at 8:56 khatzie asked Jan 21, 2014 at 8:50 khatziekhatzie 2,5694 gold badges24 silver badges37 bronze badges 2
  • Do you mean something like indexOf, but with wildcard? – Trojan Commented Jan 21, 2014 at 8:53
  • no I'm referring to parse query. – khatzie Commented Jan 21, 2014 at 8:54
Add a ment  | 

1 Answer 1

Reset to default 6

There is a way to do this, but the documentation warns that it may timeout on larger data sets. The solution is to add a constraint the query using a regular expression. Use the query constraint matches(key, regex).

Assuming there is a class named "Post" and it has a string attribute named "contents", then:

var query = new Parse.Query(Post);
query.matches("contents", ".*string.*");
query.find()

To AND multiple conditions, add more query matches constraints:

var query = new Parse.Query(Post);
query.matches("contents", ".*string.*");
query.matches("otherAttribute", ".*otherString.*");
query.find()

Using the Parse. JavaScript SDK, it is possible to use a logical OR:

var redQuery = new Parse.Query("Post");
redQuery.equalTo("color", "red");

var blueQuery= new Parse.Query("Post");
blueQuery.equalTo("color", "blue");

var mainQuery = Parse.Query.or(redQuery, blueQuery);

本文标签: Parsecom search with wild character using javascriptStack Overflow