I'm using parse backend for one of my apps. There are three tables and I want to be able to search text entered by the user in search view in the table columns.
private void getDataFromParse() {
ParseQuery<ParseObject> query = ParseQuery.getQuery(Message.NAME);
query.addDescendingOrder(Message.CREATED_AT);
**query.whereStartsWith(Message.MESSAGE, mTag);**
query.setLimit(20);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
mMessages = (List<Message>) (Object) objects;
setAdapter();
}
}
});
}
The problem is that parse search is case sensitive. I enter the table content in parse from their websites UI. One suggestion to solve this problem is here
http://blog.parse.com/learn/engineering/implementing-scalable-search-on-a-nosql-backend/
How do solve my problem ?
You can convert the text enterd by the user to upper case and make sure that all the data in parse are upper case too
Related
I am building a social network application using parse which have follow/unfollow feature.
I have two tables: Users and Follow table.
Users table have user related data and Follow table have two fields: followerId and followedId.
I have a list of searched users. So, corresponding to each user i just want to get from query that whether i am following him/her or not. So, how to run query inside a loop?
Any help will be deeply appreciated.
Thanks.
For get follower
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followedId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your follower user list
}else{
//error
}
For get following
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followerId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your following user list
}else{
//error
}
Then after call user list query in ParseUser table and get all the user.
Thanks
Hi I have the next problem:
I have 10 users registered in Parse,a user can have the role of Admin or Player.
I'm trying to get all the users first but when I tried, the query only return one (The current user).
How can I get all the users? And then how can I filter by Role?
I have the next code:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e==null){
Log.i("OK","no problem");
}else{
Log.i("NOT OK","problem");
}
}
});
Honestly, for something as simple as this, it would be better for you not to use relations and separate classes at all and instead to simply add a string field to the User Class called "role." So go to your User class on Parse, add a new column of type String called "role" and then query it as follows.
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("role", "admin");
userQuery.findInBackground(new FindCallback<ParseUser>() {
void done(List<ParseUser> results, ParseException e) {
// results has the list of users who are admins
}
});
You should check the ACL(readAccess) of each user. The user is without read access right. The other 9 user may not with public read, not specify the user's id, and the role is not equip access right.
As A.Vin's answer, if your user have more than 1 role, you can use array of strings.
I'm searching for a good way of querying usernames towards my app's user-database. So that people can't signup with the same username as someone else.
I'm using a username, password and an email for recover of password. So I want to check for username's basically.
I've understood this can be achieved with ParseQuery?
I would like an example if anyone can provide?
You can use a ParseQuery to query all usernames in the database like this.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
// objects is a list of all the User you have. Just get all the usernames,
//and check if there's already one equal to the one you want to insert.
} else {
//error handling
}
}
}
I am using this code for getting a row from the parse cloud but everytime I am fetching objects it is giving me empty list,Although there is a corresponding row available in the parse which I am trying to find and update.
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null && objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
else if(objects.size()==0){
Toast.makeText(getApplicationContext(), "No relation Found!"+e,Toast.LENGTH_LONG).show();
}
}
}
If the object is there I am updating it with new values with help of put method.But it is always giving me an empty list of Parse Objects.
I think you are trying to update the available objects.You can do it this way.
public void onClick(View v) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("StudentInfo");
query.whereEqualTo("rollnum",rollnum.getText().toString());
query.whereEqualTo("name",name.getText().toString());
query.whereEqualTo("city",city.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if(e == null ){
if(object.size()==0){
//here you can put object with help of put method if object is not there and when the object size is greater than 1 you remove the other objects except the objects.get(0).All other objects except one will be removed and only the zeroth object will be updated at the time user updates it
}
else if( objects.size() > 0){
obj=objects.get(0);
obj.put("rollnum",rollnum.getText()
.toString());
obj.put("name",name.getText().toString());
obj.put("city", city.getText().toString());
obj.saveInBackground();
}
}
else{
//exception in getting data
}
}
}
If you are getting a empty list of objects then that means there are no objects stored that match the criteria that you are querying against.
Make sure you understand your query. The way you are setting up your query, there has to be a ParseObject stored where the rollnum, name, and city are equal to those values you are testing against, and they must be exactly equal. If no objects match that criteria, then parse will return an empty list. Use the Logcat and Parse Dashboard to debug and find out what's wrong with your query.
I have a registered app on Parse with a signup/login system. Now I want to create an activity which grabs all the available users in the app and to display them one-by-one as a listview. Can someone tell me how can I do that?
Once you've setup your ListView's adapter you can call this whenever you need to update it's contents:
public void updateUsers() {
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> userObjects, ParseException error) {
if (userObjects != null) {
mUserAdapter.clear();
for (int i = 0; i < userObjects.size(); i++) {
mUserAdapter.add(userObjects.get(i));
}
}
}
});
}
That updates my adapter which is plugged into my ListView. If you have more than 100 users you want to return you'll need to up the limit as I hear that's the default (then you have to page the results, not sure how yet)
Side note: As far as I know you can't Subclass the ParseUser at the moment (you can, but you then can't use that as the object you're querying with using ParseUser.getQuery() (Which would normally be done by ParseUser.getQuery(MyCustomUserClass.class) if you were to query a customised object.