brianreavis / sifter.js

A library for textually searching arrays and hashes of objects by property (or multiple properties). Designed specifically for autocomplete.
1.09k stars 125 forks source link

Allow options.sort to be a sort function #24

Open franklin-ross opened 9 years ago

franklin-ross commented 9 years ago

This would make it consistent with the undocumented options.score, and would provide much simpler workarounds for some of the other issues which want to disable sorting. In that case you could just do something like options.sort = function (results) { return results; }.

broerse commented 9 years ago

We use this:

  sifter = new Sifter(input);
  if (!sort) {
    sifter.getSortFunction = function() {
      return null;
    };
  }
  result = sifter.search(query, options);

in ember-cli-filter-by-query

franklin-ross commented 9 years ago

Yeah I did see that solution in one of the other issues. I just think it'd be easy and clear to add this kind of thing to the API as a documented and supported thing. People obviously want to be able to do it, and I don't think what you put above is very obvious for a casual user of the library, even if it's fairly easy to do.

On Wed, 22 Jul 2015 8:17 pm Martin Broerse notifications@github.com wrote:

We use this:

sifter = new Sifter(input); if (!sort) { sifter.getSortFunction = function() { return null; }; } result = sifter.search(query, options);

in ember-cli-filter-by-query https://github.com/lazybensch/ember-cli-filter-by-query/blob/master/addon/util/filter.js

— Reply to this email directly or view it on GitHub https://github.com/brianreavis/sifter.js/issues/24#issuecomment-123652209 .

franklin-ross commented 9 years ago

Hmm. Well, maybe it is reasonably obvious and I'm just being pedantic 😜

On Wed, 22 Jul 2015 10:10 pm Franklin Ross fhross@gmail.com wrote:

Yeah I did see that solution in one of the other issues. I just think it'd be easy and clear to add this kind of thing to the API as a documented and supported thing. People obviously want to be able to do it, and I don't think what you put above is very obvious for a casual user of the library, even if it's fairly easy to do.

On Wed, 22 Jul 2015 8:17 pm Martin Broerse notifications@github.com wrote:

We use this:

sifter = new Sifter(input); if (!sort) { sifter.getSortFunction = function() { return null; }; } result = sifter.search(query, options);

in ember-cli-filter-by-query https://github.com/lazybensch/ember-cli-filter-by-query/blob/master/addon/util/filter.js

— Reply to this email directly or view it on GitHub https://github.com/brianreavis/sifter.js/issues/24#issuecomment-123652209 .

broerse commented 9 years ago

@alpha-cast Many people searched for it and didn't find it so I don't think it is to obvious. So perhaps you are not pedantic :smile: It would be great if you can create a PR for the documentation.

franklin-ross commented 9 years ago

Yeah OK. I've never actually created a pull request for GitHub before, but have been meaning to learn for a while. Better late than never ;-P

Give me a few days, I've got a sprint review for a client tomorrow and want to get a couple of things done.

broerse commented 9 years ago

Super! If you need help with github please let me know.