I am using the parse cloud to store data .
in this case I have a table "MyUser" in this table I want to search user by name in case insensitive.
Search is working fine but the search operation is not case insensitive
I have to search case insensitive
here is my code.:-
ParseQuery<ParseObject> query = ParseQuery.getQuery("BetsUpUser");
query.whereContains("name", searchData);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objList,ParseException e) {
if (e == null) {
Log.d("score","####Retrieved " + objList.size()+ " scores");
} else {
Log.d("score", "###Error: " + e.getMessage());
}
}
});
Thanks in advance.
I Solve the problem of case insensitive string Parse Query
replace the line
query.whereContains("name", searchData);
with
query.whereMatches("name", "("+searchData+")", "i");
I also came across with this question and realized there are no much ways to do this simple thing. Another interesting approach from #ardrian by using JavaScript. For Java it will almost the same. He suggests to create one more field with lowercase version of the searchable one. It look like below:
ParseObject gameScore = new ParseObject("BetsUpUser");
gameScore.put("name", name);
gameScore.put("name_lowercase", name.toLowerCase());
gameScore.saveInBackground();
And while searching we transform input text to lower case. This way we still can use whereContains() method and it will not affect us much.
ParseQuery<ParseObject> query = ParseQuery.getQuery("BetsUpUser");
query.whereContains("name_lowercase", searchData.toLowerCase()); // the only one change
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objList,ParseException e) {
if (e == null) {
Log.d("ParseQuery", objList.get(0).get("name"));//name in actual case
} else {
Log.d("ParseQuery", e.getMessage());
}
}
});
See this post on the Parse Blog about implementing scalable search.
http://blog.parse.com/2013/03/19/implementing-scalable-search-on-a-nosql-backend/
Basically you can use an afterSave event to save a searchable field (i.e. lower-cased name) on the object.
Related
I am making a query in a class my problem is that I have some license plates, here in Colombia licenses plates are as it follows ABC 123. I need my query to only return to me, in this case, the ones that end with 2
This is what i did following the documentation...
private void queryForPlaca(String terminaEn){
ParseQuery<ParseObject> query = ParseQuery.getQuery("TestDrive");
query.whereFullText("Placa", terminaEn);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
for (ParseObject obj:objects
) {
listaDeVehiculos.add(obj);
}
ListaVehiculosPicoYPlacaAdapter adapter= new ListaVehiculosPicoYPlacaAdapter(getActivity(),listaDeVehiculos);
listadoTestDrive.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
});
}
terminaEn variable querys for the licenses places plates depending on the day selected in a calendar (in this case 2).
My problem is that not only my listaDeVehiculos is not returning any values and the other problem that I see is that it also returns values I don't need for example ABS 124, AXX 524, AEE 234 etc. How should i modify my query?.
You won't be able to do that using text search, since MongoDB text search feature only matches complete terms. You will have to do that using regular expressions. Try the following:
private void queryForPlaca(String terminaEn){
ParseQuery<ParseObject> query = ParseQuery.getQuery("TestDrive");
query.whereMatches("Placa", terminaEn + "$");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
for (ParseObject obj:objects) {
listaDeVehiculos.add(obj);
}
ListaVehiculosPicoYPlacaAdapter adapter= new ListaVehiculosPicoYPlacaAdapter(getActivity(),listaDeVehiculos);
listadoTestDrive.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
});
}
Please have in mind that regular expressions are very expensive to the database, so it's important for you to create the appropriate index. A { Placa: 1 } index in the TestDrive collection should help you a lot. For your reference, please take a look here:
https://docs.parseplatform.org/android/guide/#regular-expressions
Is it possible to retrieve all the data present in a specific class in the parse server in the form of a news feed similar to facebook using recyclerView?
in order to do it you need to do the following:
I recommend you to use Parse SDK for android. You can read the docs in here . This SDK will make your life easy with performing all CRUD operations in front of your parse server instance. So the thing that you need to do is to execute query on your class like the following (taken from parse server docs):
ParseQuery<ParseObject> query = ParseQuery.getQuery("<YOUR_CLASS_NAME>");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
From the code above you can see that we first create a query object on class and then use findInBackground in order to retrieve all objects.
Inside that findInBackground callback what you need to do is to iterate on all results and map them to your recyclerView adapter and finally refresh it and see the results
From the answer above you can see that's its pretty simple task if you use Parse Android SDK. As much as I know there is no out of the box solution that will create recyclerView from parse query results.
Ive got application on android which should work without internet and with parse database when internet is on.
Also I faced with problem of getting of pinned ParseObject which not saved in online database before.
So what I do:
ParseObject car = new ParseObject("cat");
cat.put("name","Pussy");
cat.pinInBackground();
So, now I want to get this cat by query with query.getInBackground but, I cant do it because I haven't objectId, which automatically generated only after saving in online database.
You can search for cats (objects) with given properties in the local datastore:
ParseQuery<ParseObject> query = ParseQuery.getQuery("cat");
query.fromLocalDatastore();
query.whereEqualTo("name", "Pussy");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> catList, ParseException e) {
if (e == null) {
Log.d("cat", "Retrieved " + catList.size() + " cats");
} else {
Log.d("cat", "Error: " + e.getMessage());
}
}
});
However, if name is the only property, you'll likely get a list of objects with more than one entry. Here, you may add other properties (e.g. an owner) to limit the number of possible matches.
I need help with Parse queries. I have three classes which have pointers in this relation. Activity class with column "video" pointing to Video class which has another column "videoOwner" pointing to the _User class. What I want to achieve is to query the Activity class for a video and get the associated owner's details from the _User class. I have tried this
ParseQuery<ParseObject> activityQuery = ParseQuery.getQuery("Activity");
activityQuery.setLimit(1000);
activityQuery.whereEqualTo("video", ParseObject.createWithoutData("Video", objectID));
activityQuery.whereEqualTo("type", "comment");
activityQuery.whereExists("video");
activityQuery.include("video");
activityQuery.include("video.videoOwner");
activityQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> vList, ParseException e) {
if (e == null) {
for (int i = 0; i != vList.size(); i++) {
commenterUsername = vList.get(i).getParseObject("video.videoOwner").getString("username");
commenterName = vList.get(i).getParseObject("video").getParseObject("videoOwner").getString("fullName");
Log.e("User", commenterUsername);
}
}
else {
}
}
});
but it clashes at the Log because commenterUsername is null. Any help to enable me to make this query is highly appreciated as i don't want to be making too many queries if there's a simple and cleaner solution available. Thanks
In the code you posted you have getParseObject("video.videoOwner") which is invalid.
getParseObject("video.videoOwner") should be getParseObject("video").getParseObject("videoOwner")
The dot notation only works for include statements, so you have to get the individual objects like this.
This is a basic question, but I can't understand how the relationship works in Parse.
I have this relationship: Image link
Briefly, it is a relationship 1 - N. One FeedPost have several comments.
I wish I can send the post ID in the Query and just get the araylist of comments on that post.
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("Comments");
innerQuery.whereExists("UXKFwWyn3l"); //ID of the post
ParseQuery<ParseObject> query = ParseQuery.getQuery("FeedPost");
query.whereMatchesQuery("objectId", innerQuery);
Anyone can help me?
With this line
innerQuery.whereExists("UXKFwWyn3l");
you are saying "all records that have a value in the column 'UXKFwWyn3l'"
Also, you are using PFRelation when you should rather use pointers. In Comment, you should have a column with a pointer to the FeedPost. If you did, this query would get you the comments you want, providing you have the FeedPost object already:
ParseQuery<ParseObject> query = ParseQuery.getQuery("Comments");
query.whereEqualTo("post", thePostObject );
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> comments, ParseException e) {
if (e == null) {
// "comments" is now a list of the comments
} else {
// Something went wrong...
}
}
});
You can also have a reverse relationship in FeedPost, which should be an array of pointers to the comments (not a PFRelation). If you do, you can get both the FeedPost and the comments with one query:
ParseQuery<ParseObject> query = ParseQuery.getQuery("FeedPost");
query.include("comments"); // this is the column with an array of pointers to comments
query.getInBackground("UXKFwWyn3l", new GetCallback<ParseObject>() {
public void done(ParseObject feedPost, ParseException e) {
if (e == null) {
// Your feedPost now has an array with all the comments
} else {
// something went wrong
}
}
});
You should only use PFRelation for advanced relations (like many-to-many).