Closed mtford-carewell closed 5 months ago
The documentation should probably a bit better here: you can only SORT on a SCORE (this makes sense with larger resultsets from a performance standpoint)
Something like this should work:
import SearchIndex from "search-index";
const si = await SearchIndex();
await si.PUT([
{ timestamp: 1 },
{ timestamp: 2 },
{ timestamp: 3 },
{ timestamp: 4 },
{ timestamp: 5 },
]);
const results = await si.QUERY(
{
FIELD: "timestamp",
},
{
SCORE: {
FIELDS: ["timestamp"],
TYPE: "VALUE",
},
SORT: {
DIRECTION: "DESCENDING",
TYPE: "NUMERIC",
FIELD: "timestamp",
},
}
);
console.log("results", JSON.stringify(results, null, 2));
ah! that did the trick!
thanks!
You're welcome and thanks for opening the issue 👍
@fergiemcdowall I strongly suspect this is just user error, but I'm having some trouble with numeric sorts...
Despite opting for
DESCENDING
I'm actually getting the results in ascending order.Here's a minimal reproduction. I tried various options for
FIELD
e.g._match.timestamp
too. Am I missing something?Result: