Skip to content
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

Merged
merged 8 commits into from
Jun 18, 2012
Merged

Conversation

mceachen
Copy link
Contributor

@mceachen mceachen commented Jun 4, 2012

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.

@mceachen
Copy link
Contributor Author

I removed a not-thought-through scalar, and simplified the ranking column to only support one specific column.

@mceachen
Copy link
Contributor Author

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.

@spilliton
Copy link
Owner

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?

spilliton added a commit that referenced this pull request Jun 18, 2012
Added ranking column and scalar
@spilliton spilliton merged commit 7f58a4f into spilliton:master Jun 18, 2012
@spilliton
Copy link
Owner

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...

@spilliton
Copy link
Owner

Fixed sqlite thing and made a few other change:

299d2e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants