Command Palette Search Tips

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"}
    ]
}
4 Likes

I had a suggestion and left a comment in the PR ;).

Neat advice, thanks. I also use the CommandPalette plugin extensively and love it.

It would be nice to avoid duplicate results between search steps also. For instance, removing the matches from earlier search steps in subsequent ones.

In your example, I imagine the first two search steps will both return titles starting with the search string. How would you recommend step 2 not repeating results that already were shown by step 1?

(Oh, I see @cdaven left that in the PR as item 3.)

I’ve tried reflecting on this myself, but haven’t yet come up with a solution. The filter portion would be relatively easy (- filter operator?), but requires the insertion of the search string at multiple caret positions. If there was a way to specify an array of caret positions which would all insert the search string. This would allow very complex filters to be crafted.

(oh, @Maurycy made the same observation to the PR)