-
Notifications
You must be signed in to change notification settings - Fork 24
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
Added ranking column and scalar #8
Conversation
…_by_#{column name}.
… column. The scalar is dumb -- it wouldn't work.
I removed a not-thought-through scalar, and simplified the ranking column to only support one specific column. |
Oh, and btw -- the sqlite order by doesn't work correctly -- only postgres and mysql seem to do the correct thing and generate a proper distribution. |
Nice refactor! I think the choice to go to the single column rank was a good one. I'm going to merge in and further familiarize myself with it. I'll prolly add some tests to ensure that the method_missing doesn't interfere with active record's and add a respond_to? method: http://stackoverflow.com/questions/291132/method-missing-gotchas-in-ruby The sqlite thing you are talking about, is that just when using the new column, or were you noticing an issue before you added the feature? |
Added ranking column and scalar
I understand the SQLite thing now. It's because SQLite's implementation of random(), unlike the other DBs that generate a float between 0 and 1, it generates an integer between -9223372036854775808 and +9223372036854775807, so that throws the multiplication way off for ordering. I guess we have to coax the random function into something between 0-1 for sqlite... |
Fixed sqlite thing and made a few other change: |
This lets randumb be a little less random and a bit more probabilistic, by letting the caller specify a "ranking" column that must be numeric, and the larger the value in that column, the more likely that row will be returned.
In the case of "rated" entities, it would let higher-rated entities show up more likely than lower rated entities.