Home / GitHub Page

Sorting search results

Yes, but I was thinking that the relevance function, which depends on the matchinfo/offset functions of fts, won’t work if there is no text to match against.

for example notebook:n1 tag:t1

Do you mean that for this query we cannot use FTS?

No text to fts search here, so how do we sort the results? Another example created:2015 . This would return all notes created from 2015 onwards but I don’t think giving the result without any ability to control its order would be helpful. The user is interested in the time aspect of the notes, so doesn’t it make sense to allow sorting by asc/desc time?

The query should be used a signal that affects the relevance algorithm. If the query is “created:2015” indeed it means that the note creation date is important and should affect relevance more. In that case, maybe that would be the only thing that affects relevance and the results would be sorted by creation date.

On the other hand, a query like “created:2015 car repair” should give more weight to the results that contain both words “car” and “repair”.

No, we’re still using FTS. But the query would be a fast rowid lookup instead of a full-text query.
https://www.sqlite.org/fts3.html#simple_fts_queries
So there won’t be a return value for the FTS auxiliary function offsets/matchinfo.

Yes, but if we only sort by, let’s say, ascending creation date, won’t that be too restrictive? There’s an equally valid case where users might want the notes to be sorted by descending creation date.

What do we do with created:2015 updated:2020 ?
Is creation date the sole factor for relevance or created and updated both or maybe just ordering by title is enough. Seems like the user doing the search would be more informed about how to go about this.

And sometimes people just want the notes sorted alphabetically by title (ignoring any complicated relevance algorithm)

Here’s a popular post by @foxmask about ordering the search results.

Trilium allows sorting search results by note attributes.

It’s possible to order the results by one or more attribute, e.g. @orderBy=year,-genre will order notes by year label in ascending order and then by genre label in descending order (because of - sign).

So does Evernote.