I’ve been playing with the search in the excellent commandpalette plugin, and just submitted a pull request with some minor improvements.
I have some tips for improving the search results. Do you have any tips or suggestions?
Rank matches at the beginning of words higher
When I search for “arch”, I usually mean “architecture”, not “search” or “hierarchy”.
The filter [regexp:title[(?i)\barch]]
matches “architect”, “architecture”, “archetype” and so on – but not “search” or “hierarchy”.
The \b
is a word boundary assertion, that matches the end or beginning of words in a clever way. (Note that you must write \\b
in the JSON in the CommandPaletteSearchSteps tiddler!
The (?i)
prefix makes sure you match both upper and lower case letters (as in case insensitive).
By adding new “search steps” at the top of $:/plugins/souk21/commandpalette/CommandPaletteSearchSteps
, I can make sure that these matches are shown first.
Then I did the same with [regexp:text[]]
for full-text search.
Search in all custom fields
The filter [search[]]
searches title, text and tags by default. But if we change this to [search:*[]]
, it will search all fields! This is really neat when you’re using custom fields.
You could add this as a separate search step, in case you want matches to custom fields to rank lower than matches to the text and tags.
Ignore images
I have added !is[image]
to ignore images in my search results, but that’s a personal preference.
If you put this JSON in $:/plugins/souk21/commandpalette/CommandPaletteSearchSteps
, you will get the behaviour described above:
{
"steps": [
{"filter": "[!is[system]!is[image]regexp:title[(?i)\\b]]", "hint": "in title", "caret": "41"},
{"filter": "[!is[system]!is[image]search:title[]]", "hint": "in title", "caret": "35"},
{"filter": "[!is[system]!is[image]regexp:text[(?i)\\b]]", "hint": "fulltext", "caret": "40"},
{"filter": "[!is[system]!is[image]search:text[]]", "hint": "fulltext", "caret": "34"},
{"filter": "[!is[system]!is[image]search:*[]]", "hint": "fields", "caret": "31"},
{"filter": "[all[system+shadows]search:title[]]", "hint": "in title (system)", "caret": "33"},
{"filter": "[all[system+shadows]search:text[]]", "hint": "fulltext (system)", "caret": "32"}
]
}