question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V2: Add new query `SortByNatural`

See original GitHub issue

Is your feature request related to a problem? Please describe

Currently (even in V1), we can only fetch and sort using normal SortBy, but it sorts files like this… 1-name, 10-name, 2-name, 3-name, etc.

Describe the solution you’d like

  1. To be able to sort the files naturally like this… 1-name, 2-name, 3-name, 10-name
  2. So, in addition to the SortBy option, kindly add one more option of SortByNatural using Intl.collator https://github.com/nuxt/content/blob/1968257881db58634bdf4448bd85d7b059f88e4c/src/runtime/query/query.ts#L35

This way we can directly naturally sort while fetching itself and then properly use limit, etc. options.

Describe alternatives you’ve considered

Fetch thousands of posts without any sort, and then use Intl.collator to sort them, and then filter out only first n posts. But it’s not performant if there are so many posts.

Additional context

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Atinuxcommented, May 12, 2022

Seems like a good solution to order by default, what do you think @farnabaz ?

1reaction
farnabazcommented, May 16, 2022

Instead of having sortByNatural I’m proposing a change in sortBy and create mongo like sorting util which is more powerful and fix multiple issues in sorting, like case insensitive sorting, or natural sorting.

queryContent().sort({
  title: 1, // title ascending
  description: 0, // descending
  $numeric: 1, // natural sort
  $sensitivity: 'case' // define case sensitivity
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with query editor v2 - Amazon Redshift
The query editor v2 opens in a new browser tab. The query editor page has a navigator menu where you choose a view...
Read more >
Append queries (Power Query) - Microsoft Support
In Power Query, the Append operation creates a new query that contains all rows from a first query followed by all rows from...
Read more >
How to use Microsoft Power Query - YouTube
Power Query is the easiest way to connect, extract, transform and load ... Excel 13:34 Insert pivot table & chart 14:46 Importing additional...
Read more >
QMF V11.2 - Creating analytical queries - IBM
Conditional Grouping Query - With Conditional Grouping queries you can create aggregated summaries of result set data based on conditional expressions. Column ...
Read more >
Join two or more tables in Excel with Power Query - Ablebits
Among other things, Power Query can join 2 tables into 1 or combine data from multiple tables by matching data in columns, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found