matteodem / meteor-easy-search

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

Sorting by Date not working #554

Closed zyonnetworks closed 7 years ago

zyonnetworks commented 7 years ago

Hi,

For some reason, the sort feature isn't working. Am I doing something wrong?

export const LeadsIndex = new Index({
  collection: Leads,
  fields: ['firstName', 'lastName', 'createdAt'],
  engine: new MongoDBEngine({
    sort: () => { createdAt: -1 }
  }),
  defaultSearchOptions: { limit: 25 }
});

Mongo is saving date as ISODate().

I even tried to sort by a field called 'firstName', but it didn't work either. Please advise.

matteodem commented 7 years ago

shouldn't sort: () => { createdAt: -1 } be sort: () => ({ createdAt: -1 })?

Looks like invalid syntax to me.

zyonnetworks commented 7 years ago

Perfect. That worked! It was a syntax error on my end.

Is there a feature to refresh the search because when a new document is added, it puts it on the bottom. It doesn't order correctly until I hit refresh.

matteodem commented 7 years ago

Please create a new story for the question

guillim commented 7 years ago

thanks @matteodem I had the exact same problem. maybe the doc is a bit confusing ? -> http://matteodem.github.io/meteor-easy-search/docs/engines/

matteodem commented 7 years ago

Can you explain what you think is confusing? I happily will adjust the docs (or you can create a PR in the gh-pages branch)

guillim commented 7 years ago

@matteodem yes, here is the sentence that confused me: on the first paragraph, under the title ENGINES, there is a piece of example code where is written sort: () => { score: 1 }, And you mentioned above in this conversation that it would better be sort: () => ({ score: 1 }),

Am I right?

matteodem commented 7 years ago

oh yeah. Feel free to either create a PR fixing this in the gh-pages branch or creating a new issue