How to show core search results by date?

Hello,

Is it possible to modify/override the core search results so that resulting tiddlers are shown ordered by date? What I would like is to see recent results first, exactly like with the timeline macro in the ‘Recent’ tab.

If possible, I would prefer to modify/override the system search (this is in $:/core/ui/DefaultSearchResultList, isn’t it?) in order not to redo the whole search system. But I’m open to alternative options as well.

Thank you !
Erwan

There are two fields in that tiddler, first-search-filter and second-search-filter. These fields contain filter syntax that is used to produce the “title matches” and “all matches” list output, respectively.

In each of these filters, find sort[title] and replace it with !sort[modified]. The search results will then show the lists ordered by modification date (most recent first).

enjoy,
-e

3 Likes

Addendum:

If you want to show the results lists with date headings, you can replace the “title matches” code:

<$list filter="[<userInput>minlength[1]]" variable="ignore">
<$list filter={{{ [<configTiddler>get[first-search-filter]] }}} emptyMessage={{$:/language/Search/Matches/NoResult}}>
<span class={{{[<currentTiddler>addsuffix[-primaryList]] -[<searchListState>get[text]] +[then[]else[tc-list-item-selected]] }}}>
<$transclude tiddler="$:/core/ui/ListItemTemplate"/>
</span>
</$list>
</$list>

with:

<$list filter="[<userInput>minlength[1]]" variable="ignore">
<<timeline limit:250 subfilter:"search:title<userInput>">>
</$list>

and relace the “all matches” code:

<$list filter="[<userInput>minlength[1]]" variable="ignore">
<$list filter={{{ [<configTiddler>get[second-search-filter]] }}} emptyMessage={{$:/language/Search/Matches/NoResult}}>
<span class={{{[<currentTiddler>addsuffix[-secondaryList]] -[<searchListState>get[text]] +[then[]else[tc-list-item-selected]] }}}>
<$transclude tiddler="$:/core/ui/ListItemTemplate"/>
</span>
</$list>
</$list>

with:

<$list filter="[<userInput>minlength[1]]" variable="ignore">
<<timeline limit:250 subfilter:"search<userInput>">>
</$list>

-e

2 Likes

Great, I’ll try this tomorrow. Thank you so much Eric!

@erwan fortunatly @EricShulman has answered your question. However I am not sure this is wise, its best to leave the default search behaviour as is. If I were doing it for myself I would clone the existing Advanced Search Filters tab, and make a new one with the search features.

If you don’t want to change the $:/core/ui/DefaultSearchResultList, you can define an alternative, like this:

  • Clone $:/core/ui/DefaultSearchResultList
  • Name it something like $:/custom/ui/SearchResultsByDate
  • Note that this tiddler is tagged with $:/tags/SearchResults. Keep this tag.
  • Edit the contents as previously described (to use the <<timeline>> macro)
  • Change the caption to something like “By date”
  • You can delete the first-search-filter and second-search-filter fields, since they are not used by this tiddler

After making this tiddler, when you search, there will be two tabs of results:

  • “List” shows the standard search results lists
  • “By date” shows the search results in date order using the <<timeline>> macro to format the lists with date headings

Note that the new “By date” tab will appear in the Sidebar search results AND also in the $:/AdvancedSearch > Standard tab results.

enjoy,
-e

2 Likes