Sort Event in ZK - zk

I have added comparators for sorting in asc,desc order.
listHeader.setSortAscending(new MyComparator(true)); //True for asc
listHeader.setSortDescending(new MyComparator(false)); //False for asc
when I do this. Events.postEvent(Events.ON_SORT,listHeader,null);
I get the listbox sorted in ascending order, but I want it to be sorted in descending order when I call above Events.postEvent(); am I missing setting any attribute?

Found answer :)
I had to set attribute Sort Direction to "ascending" listHeader.setSortDirection("ascending");

Related

Which elememt does DataFrame. DropDuplicate drop

If I sort a dataframe in descending ortder based on a column. And then drop the duplicates using df.dropDuplicate then which element will be removed? The element which was smaller based on sort?
DropDuplicate method preserves the first Element and removing the others.
So yes , on descending sort only the largest(based on sort) will be preserved and others removed.

Sorting priority

I have a collection Answers in a MongoDB database and I sort the documents with the number of upvotes each answer has.
Answers.find({}, {sort: {voteCount: -1}})
Some of these answers, however, are posted by instructors and they should be sorted before of "regular" answers. Answer posted by instructors have a field isInstructor: true.
How do I retrieve my list of answers sorted in a way that instructors' answers come first (sorted by voteCounts as well) and then, after those, the normal answers (still sorted by voteCounts)?
Well As mention in my comment you must sort your answers by isInstructor in descending order and by voteCount in descending order. Also note that the second argument to .find is a projection document. Thus to sort your document you need to use the cursor.sort method instead.
Answers.find().sort({ "isInstructor": -1, "voteCount": -1 })
Use the cursor's sort() method, listing the fields you would like to sort by, in order. EG
db.answers.find({}).sort(isInstructor: -1, voteCount: -1})
Reference: MongoDB Manual

What's the behavior of db.find.sort()?

For example this is our document schema, which has an descending index on created_at field.
var titles = {
title: String,
created_at:{
type: Date,
index: -1
}
}
Here are 2 questions:
1st:
If we call db.titles.find() or db.titles.findOne() how result order will be?
I mean it will returns objects in desc or asc order?
2nd:
How about here?
db.titles.find().sort({created_at: -1})
How does MongoDB behave in the code above? Sort the result on the fly or it just use index order which we defined in the schema?
1st: If we call db.titles.find() or db.titles.findOne() how result
order will be? I mean it will returns objects in desc or asc order?
It will return documents in natural order - in order in which documents are stored on disk. If you want to sort documents by created_at you should explicitly specify it:
db.titles.find().sort({created_at: -1})
How does MongoDB behave in the code above? Sort the result on the fly
or it just use index order which we defined in the schema?
Since you already have an index on created_at field, Mongo will use it. But if you'll add some query
db.titles.find({title: /Foo/}).sort({created_at: -1})
then Mongo will no longer be able to use your index to sort query results and will be forced to sort it on the fly.
You can find more aboun MongoDB indexes in this blog post.

What's the purpose of specifying IndexDirection for indexes in MongoDB?

I am using Morphia to communicate with MongoDb. When annotating fields with #Indexed, it's allowed to specify the IndexDirection of DESC, ASC, BOTH, GEO2D, what's the purpose of those separately?
If I specify BOTH, does it mean that there would have two indexes created?
And also, if I want the filtered entities to be order in descending order, does it mean that I'd better to have the index to have IndexDirection of DESC?
DESC = Descending, ASC = Ascending, and GEO2D = 2D/Geography
BOTH is not a valid option unfortunately. That was a mistake of the enum definition and no longer exists.
They indicate how the values are stored in the index. For a single index the direction is not important.
For compound indexes you can specify the orders for each field and it will make a difference. See the docs on the mongodb site for specifics.

In Mongodb, how do I first sort by score, then sort by time if there is a "tie"?

results = docDB.posts.find({"active":True }).sort("pop_score", pymongo.DESCENDING)
This is my sort right now. But the problem is, some things have the same "score". In that case, if they tie, I want them to sort by "time" within the ones who tied.
How do I do that? It's possible to do that in Mysql...
You can sort by more than one attribute at a time. e.g.
sort({name : 1, age : -1})
will sort by name ascending then by age descending
See here for reference: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order
Edit:
In pymongo, that would be
.sort([['name', pymongo.ASCENDING], ['age', pymongo.DESCENDING]])
referenceL http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.sort