How to sort search results in Confluence Cloud by update order, title order, or any other criteria.
Advanced Search
When you click on the search window in the upper right corner of Confluence, you will see the "Advanced Search in Confluence" link at the bottom, and clicking on the link will take you to the Advanced Search page, where you can perform more advanced searches.
Search results are sorted on this Advanced Search page.
Using CQL
Confluence's content search API provides an SQL-like language called CQL as a way to specify search conditions.
In fact, you can also search on the Advanced Search page, passing the CQL as a parameter.
Since CQL allows you to specify sorting, you can use CQL on the Advanced Search page to sort your search results.
procedure
- Pass the URL of the Advanced Search page with the parameter
cql
and the URL-encoded CQL statement as a value
That's all.
Example
Blogs posted by users "A" and "B" that contain "test" are displayed in descending order of update.
The CQL statement is as follows
CQL
( creator.fullname ~ "A" OR creator.fullname ~ "B" ) and type=blogpost and text ~ "test" order by lastmodified desc
URL encoding is done by JavaScript in the browser.
Open the console with F12, paste and run the JavaScript below to open a page that URL-encodes the CQL and passes it to Advanced Search for sorted search results.
JavaScript
const cqlPlain = ` ( creator.fullname ~ "A" OR creator.fullname ~ "B" ) and type=blogpost and text ~ "test" order by lastmodified desc `; const cqlEncoded = encodeURI(cqlPlain); const url = `https://[example].atlassian.net/wiki/search?cql=${cqlEncoded}`; window.open(url);
Impressions, etc.
It is not easy to use, but the full CQL syntax allows for a variety of elaborate searches.
There are macros that can use CQL, so if you can use those, that would be quicker.
It would be nice to be able to enter CQL statements directly on the Advanced Search screen, since it was originally provided as a feature in the API.