Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Sort results in FTS #815

Open
rbovard opened this issue Jul 23, 2014 · 4 comments
Open

Sort results in FTS #815

rbovard opened this issue Jul 23, 2014 · 4 comments

Comments

@rbovard
Copy link
Contributor

rbovard commented Jul 23, 2014

Is it possible to sort FTS results alpha numerically and not just alphabetically?

@ochriste
Copy link
Member

Ext automatically sort the values alphabetically, but has no "natural order" sorting,
it will require some explicit javascript coding to do that

@sbrunner sbrunner added this to the 1.6 milestone Jul 23, 2014
@rbovard
Copy link
Contributor Author

rbovard commented Sep 3, 2014

Ok thanks for the feedback.

I think the same behaviour should be implemented with the ThemeFinderplugin.

@sbrunner
Copy link
Member

sbrunner commented Sep 3, 2014

We can make something like:

https://blog.jcoglan.com/2008/01/04/natural-order-sort-in-javascript/

Array.prototype.naturalSort = function() {
  var p, q, valueOf = function(t) {
    return isNaN(t) ? t.charCodeAt(0) :
        Number(t) - Math.pow(2,32);
  };
  return this.sort(function(a,b) {
    var values = [a,b].map(function(s) {
      return s.toString().toLowerCase()
          .match(/([a-z]|[0-9]+(?:\.[0-9]+)?)/ig);
    });
    a = values[0]; b = values[1];
    for (var i = 0, n = Math.min(a.length, b.length); i < n; i++) {
      p = valueOf(a[i]), q = valueOf(b[i]);
      if (p != q) return p - q;
    }
    return a.length - b.length;
  });
};

@rbovard
Copy link
Contributor Author

rbovard commented Sep 4, 2014

I just saw I've already opened an issue #782 for the ThemeFinder plugin :)

@sbrunner sbrunner removed this from the 1.6 milestone Apr 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants