matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
436 stars 68 forks source link

New reactive results not sorted correctly #573

Closed steven-tib closed 7 years ago

steven-tib commented 7 years ago

Hi @matteodem,

When I add new data to the database, I see them instantly (reactively) in my search results. However they are not appearing at the correct position in the list, according to my sort parameters.

I'm sorting the result to show the most recent at the top, thus expecting to have new data reactively added at the top, but they appear either at the end of the list or after the first result.

How can I force new results to be reactively added at the top (if sorted by date, most recent at top) ?

here are my settings for easysearch :

export const jobofferIndex = new EasySearch.Index({
    collection: jobofferCollection,
    fields: ['Message','tags','durationType','createdAt','languages','languages.language','certificationRequired','certifications.organisation','locationCountry','locationCity', 'businessName'],
    engine: new EasySearch.MongoDB({
            sort: function () {
              return {createdAt: -1}
            },
            selector: function(searchObject, options, aggregation) {
                let selector = this.defaultConfiguration().selector(searchObject, options, aggregation);

                var freedive = {};

                if (options.search.props.filterAll) {
                    return selector;
                } else if (options.search.props.filterFunction) {
                    selector.certificationRequired = options.search.props.filterFunction;
                } else if (options.search.props.filterDuration) {
                    selector.durationType = options.search.props.filterDuration;
                } else if (options.search.props.filterFreediving){
                    freedive.$regex = '.*'+options.search.props.filterFreediving+'.*';

                    selector.certificationRequired = freedive;
                }
                return selector;
            }
    }),
});

Thanks for your help

matteodem commented 7 years ago

duplicate of #513. Feel free to create a PR to fix this problem, I'm rather busy until January.