richardboehme / lexorank Goto Github PK
View Code? Open in Web Editor NEWStoring user-defined order of your models by utilizing lexicographical sorting
Home Page: https://lexorank.richardboeh.me
License: MIT License
Storing user-defined order of your models by utilizing lexicographical sorting
Home Page: https://lexorank.richardboeh.me
License: MIT License
The current ruby testing workflow of this repository does not mention any JRuby implementations, because sqlite3 needs native extensions that are not supported by JRuby.
To make sure that the gem works with JRuby we should add it to the automated Github workflow.
To avoid confusion with the setup of column collations, that is needed to use this gem, it should be as simple as using
class AddRankToPages < ActiveRecord::Migration[7.0]
def change
add_column :pages, :rank, :lexorank
add_index :pages, :rank, unique: true
end
end
or
$ rails g migration AddRankTo<insert model name here> rank:lexorank:uniq
This can be achieved by adding a custom column type to ActiveRecord. An example can be found in the Money-Rails gem.
Very good case create new items with some rank not based on last items rank but just based on current timestamp. In this case I can be totally sure that all items create in the end.
Very useful
Well done on putting together this gem. It's something I've theorised about with others as I maintain the acts_as_list
and ranked-model
gems and both have their downsides. Lexical ranking is kind of like what ranked-model
does but with more sparseness between ranks. One of the keys to limiting the amount of rebalancing is to not just go for 50% between surrounding ranks but rather have the concept of a minimum gap. If one doesn't do that in ranked-model
land we run out of ranks and have to rebalance after 30 or so appends to the end of the list. Anyway, just something to think about. I haven't actually implemented this in ranked-model
yet. It's a bit off topic lol! :)
I had a go at creating a migration on MySQL but got the following error:
ActiveRecord::StatementInvalid: Mysql2::Error: BLOB/TEXT column 'rank' used in key specification without a key length
It seems that indexing a variable length text column isn't possible in MySQL? Have you run into this on your end?
First of all thanks a lot for this gem :)
This is not really a bug report, but rather a summary of an issue I've stumbled across. I'm not an DB expert and therefore not 100% certain if all this is correct. But, maybe it helps others how run into the same issue.
After integrating your gem everything worked correctly in development/test environment on my local laptop. But, when deploying to Heroku on production it raised duplicate entry errors caused by the unique index on the "rank" column. This was indirectly caused by the wrong sorting order.
On Heroku PostgreSQL LC_COLLATE is set to en_US.UTF-8
. But, on my laptop it is set to C
.
When using C
the sorting order is (I think) what we want, where uppercase letters come before lowercase letters. But, when using en_US.UTF-8
the sorting order is different.
One can solve this at query time in sql order by rank collate "C" asc
or in ruby order(Arel.sql('rank collate "C" asc'))
.
Alternatively, the column collate value can be changed with a migration:
ALTER TABLE items ALTER COLUMN rank TYPE varchar COLLATE "C";
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.