bannerBaka-UpdatesManga
Manga Poll
Do you go back and read the extras and side stories that are released after you've already finish the main series?
Always
Usually
Sometimes
Never
 
mascot
Manga is the Japanese equivalent of comics
with a unique style and following. Join the revolution! Read some manga today!

RSS Feed

Releases ordering by chapter number is wrong

You must be registered to post!
From User
Message Body
Member


5 months ago
Posts: 3

I know this probably has been reported countless times already but I can't find any post mentioning it and I'm losing my mind every time I see it

When ordering releases by chapter number (/releases/archive with orderby=chap) the order is wrong, because it uses text sorting instead of number sorting function (eg. 1 -> 10 -> 2 instead of 1 -> 2 -> 10).

(It also happens with orderby=vol but that's not as important)

I'm aware that this is caused by the tragic decision to make chapter number a string to allow for using chapter ranges, but there must be a way to sort at least pure numbers correctly.

For example ORDER BY CAST(chp as SIGNED); (in MySQL) seems to mostly work (1 -> 1-10 -> 2 -> 10) which would already be WAY better than the current situation.

(Here's a link to what I'm talking about: MySQL compiler).


... Last edited by Archimedes5000 5 months ago
Post #808784 - Reply To (#808782) by Archimedes5000
Post #808784 - Reply To (#808782) by Archimedes5000
user avatar
Site Admin


5 months ago
Posts: 2855

Hi,

We are using elasticsearch. Any idea how to do that simply with elastic?


Post #808785 - Reply To (#808784) by Manick
Post #808785 - Reply To (#808784) by Manick
Member


5 months ago
Posts: 3

Oh damn I didn't expect it to be that. I never used ElasticSearch myself, the configuration syntax seems unhinged and there is no online sandbox for me to try, so all I have is this.

Apparently you can also do this using the "painless" scripting language for it, but unlike what the name suggests finding an interpreter for it is a pain


... Last edited by Archimedes5000 5 months ago
Member


5 months ago
Posts: 3

Ok so I installed ElasticSearch 2.4.0 and was able to do something using an inline groovy script. I have no idea how heavy that is or even how to use it from server side but I'm sure you can figure that out better than me.

Config in elasticsearch.yml:

script.inline: true
script.indexed: true
script.file: true
script.engine.groovy.inline: true
script.engine.groovy.inline.search: true
script.engine.groovy.inline.update: true
script.engine.groovy.inline.mapping: true
script.groovy.sandbox.enabled: true

Example data:

curl -X DELETE "http://127.0.0.1:9200/test1"
curl -X PUT "http://127.0.0.1:9200/test1/doc/1" -H 'Content-Type: application/json' -d'{"n":1, "t":"1"}' 
curl -X PUT "http://127.0.0.1:9200/test1/doc/2" -H 'Content-Type: application/json' -d'{"n":2, "t":"2"}' 
curl -X PUT "http://127.0.0.1:9200/test1/doc/10" -H 'Content-Type: application/json' -d'{"n":10, "t":"10"}' 
curl -X PUT "http://127.0.0.1:9200/test1/doc/1to10" -H 'Content-Type: application/json' -d'{"n":10, "t":"1-10"}' 
curl -X PUT "http://127.0.0.1:9200/test1/doc/string" -H 'Content-Type: application/json' -d'{"n":null, "t":"string"}' 

Query with script:

curl -XGET "http://127.0.0.1:9200/test1/_search?pretty=1" -d '{
"sort":{
"_script":{
"script":"
s = _source.t;
x = s.split(\"-\");
s = x[x.length-1];
if(s.matches(/^\\\d+(?:\\\.\\\d+)?$/)){
s.toFloat();
}else{
Integer.MAX_VALUE;
};
",
"type":"number"
}
},
"query":{
"matchAll":{}
}
}'

I made it sort ranges (like 1-2-10) using the last number, and made failed conversions (anything with any letters) appear at the end by giving them max integer.

Bruh why did the indentation get flattened... whatever


... Last edited by Archimedes5000 5 months ago
user avatar
Site Admin


5 months ago
Posts: 2855

Hey,

I appreciate your enthusiasm! I have been less responsive due to other things going on at the moment. I like your solution idea from the previous post, and I will try it once I get a chance!


You must be registered to post!