Souk21 / TW-commandpalette

A command palette for TiddlyWiki. Demo: https://souk21.github.io/TW-commandpalette/
Other
39 stars 5 forks source link

Search improvements #19

Open cdaven opened 1 year ago

cdaven commented 1 year ago

I have some suggestions for improvements:

  1. Instead of using the "caret" logic for CommandPaletteSearchSteps, I suggest using a "%s"-based logic, where we use string.replace(). This is slower, but easier to work with.
  2. If the filter contains "regexp[]" or "regexp:title[]" filter operators, escape the search terms to work inside a regular expression.
  3. Make sure that the search results always contain each tiddler only once. Previously, the same tiddler could be listed as matching different "hints".

Personally, I think the search should first match the query by the beginning of words, and after that, look inside words. I have altered my personal CommandPaletteSearchSteps to do that with regular expressions, but I'm not sure this is wanted by default?

I also don't want images in my search results.

This is my current CommandPaletteSearchSteps:

{
    "steps": [
          {"filter": "[!is[system]!is[image]regexp:title[(?i)\\b%s]]", "hint": "in title"},
          {"filter": "[!is[system]!is[image]search:title[%s]]", "hint": "in title"},
          {"filter": "[!is[system]!is[image]regexp:text[(?i)\\b%s]]", "hint": "fulltext"},
          {"filter": "[!is[system]!is[image]search:text[%s]]", "hint": "fulltext"},
          {"filter": "[!is[system]!is[image]search:*[%s]]", "hint": "fields"},
          {"filter": "[all[system+shadows]search:title[%s]]", "hint": "in title (system)"},
          {"filter": "[all[system+shadows]search:text[%s]]", "hint": "fulltext (system)"}
    ]
}
linonetwo commented 3 months ago

You can remove search from the filter, and use +[search[xxx]] later, see https://github.com/tiddly-gittly/tw-command-palette/blob/404a2f70047311341802d84bb1a54b1c6e47bb70/src/commandpalette/widgets/build-in-sub-plugins/search-filter.ts#L77