Silversearch - Fulltext search for Silverbullet

I made a plug called Silversearch (don’t judge my creativity) implementing a fulltext search for Silverbullet. It’s basically a port of Omnisearch from Obsidian if you ever used that, although it doesn’t have feature parity with Omnisearch yet.

The install instructions and config options are on github. There are probably still a few bugs right now as I have ported a lot of stuff directly and not yet tested every setting and every combination of settings. So if you encounter something feel free to open an issue.

There are a few SpaceStyles you have to set as mentioned in the docs. I will create a pull request soon (hopefully) to change that in Silverbullet directly as I see no reason for those styles. PR to integrate those into Silverbullet

I’m also thinking about indexing PDFs and images, but I’ll have to think about it/talk to @zef on how to best achieve this, because there are a few limitations with plugs. After some more research I think the limitations I thought existed, don’t actually exist.

That’s all, hope this is useful to some of you.

13 Likes

This looks very promising! Thank you for making it and sharing it!

The lackluster search is honestly one of the worst features of SilverBullet. Something like this should really be baked-in. Maybe we’ll get there some day!

Very cool! I’ve been using git grep so far which works great, will give this a spin for a large space.

Wow this looks very cool. Can’t wait to try this one out!

Wow, thanks a lot @MrMugame, thats really great! :clap:

The keyboard shortcut to open Silversearch is cmd q on macOS, can I change this somewhow? cmd q is also ‘quit’ for FireFox :slight_smile:

Whoops forgot to change that one. Pushed a fix.
But you can also use Spacelua to update the shortcut

command.update {
  name = "Silversearch: Search",
  mac = "Cmd-p"
}

Or even define your own command as there is a syscall for opening the search. You can also pass it a default string.

command.define {
  name = "Search books",
  run = function()
    silversearch.openSearch("path:books/ ")
  end,
  mac = "Cmd-s"
}

There is also a search syscall silversearch.search, if you want to somehow make a search widget or something like that.

2 Likes

This is an awesome addition! Thanks MrMugame

Great, thanks a lot for the fix and the elaborations. This search is an outstanding addition to SB :partying_face:

@zef native intégration of this plug-ins could be fantástico?

Just installed this and it works… really well and fast. Cool! Weird thing that seems to happen on my install is that the search input box is not showing the cursor (Chromiun, macOS) anybody else seeing this?

I’d like to have a closer look at the implementation. A quick look suggests that this stores the entire search index in a single database key, is that right? I wonder how well that scales.

Found the white mode user
image
Pushed a fix.

It keeps the minisearch instance/class as a global variable in the worker and just caches it into the clientstore after every change (indexing). When it’s used it checks if the variable in the worker is still initiated and if not loads it again. So it only really has to load stuff it the worker is suspended.

hmm, updated it again just now but now it doesn’t find anything, seems it doesn’t build an index.

When I do a page reload of the space index page, I get this error in a blue bubble popup:

I double-checked the config I created and re-pasted it, can’t see any error. Any ideas?

Thanks for pointing that out, that’s what I meant with not having tested all settings. It should work now.

1 Like

Thanks a lot, works again :folded_hands:

Searching works like charm :heart: but the page content disappears. It’s not like in your screenshot above, when I spawn the Silversearch I see only the Silversearch dialog and the page “under” is hidden. Is that intended behaviour? (Firefox 137 on Linux)

Update your silverbullet or if you can‘t use these space styles

Updated, fixed, thank you.

I want to align the look and feel more with common Silverbullets’.

```space-style
.silversearch-selected {
  color: rgb(238, 238, 238) !important;
  background-color: rgb(70, 76, 252) !important;
}
.silversearch-highlight {
  color: rgb(238, 238, 238) !important;
  background-color: rgb(33, 36, 118) !important;
}
```

This works. But how do I style the non-selected .sb-options, please?

UPDATE

I ended up with something very ugly…

```space-style
.sb-option:is(.silversearch-selected) {
  color: var(--modal-selected-option-color) !important;
  background-color: var(--modal-selected-option-background-color) !important;
}

.sb-option:is(.silversearch-selected) .silversearch-highlight {
  color: var(--modal-selected-option-color) !important;
  background-color: color-mix(
    in srgb,
    var(--modal-selected-option-background-color),
    black 35%
  ) !important;
}

.sb-option:not(:is(.silversearch-selected)) .silversearch-highlight {
  background-color: var(--editor-highlight-background-color) !important;  
}
```

But it seems to work. Suggestions are welcome. :slight_smile:

1 Like

Just had a look at the code. Very interesting mix of tech (some node.js and vite, some svelte, some Deno) :smile: Pretty amazing you got it to work.

It looks like indeed the entire search index is kept in a single key in the DB. In my space with about 1.6k pages this takes up >5MB of JSON but somehow this just seems to be fine and pretty snappy! I’m surprised to be honest. Perhaps the whole full-text seach indexing thing I built (which is way worse in terms of result quality) was way over engineered compared to what is actually needed.

Perhaps it would be nice to have this in SB core at some point, but the current license (GPL) prevents that. The core seems to be minisearch (GitHub - lucaong/minisearch: Tiny and powerful JavaScript full-text search engine for browser and Node) which is MIT licensed, so that can be built on top of more directly.

I have used this architecture of Deno + Nodejs Vite multiple times now. It’s pretty annoying to set up, because Deno just sometimes does weird stuff like use your package.json instead of the deno.json, but once it works it’s pretty flawless. It’s also really the only option here as Deno building frontend code is a massive pain as you know from silverbullet itself. Especially when you want to extract css and stuff. (I still don’t understand what the recommend way here is instead of using something like fresh. Frontend doesn’t seem to be a concern for Deno devs)

I haven’t really tested it on super large spaces myself, but yeah, it’s surprisingly snappy, I think it really speaks volumes to how optimized browsers are with core operations like json parsing.

Generally I would have no problem with it being merged into Silverbullet, but I really don’t have a lot of choice with the licensing. Omnisearch is GPL (Don’t really know why, maybe to prevent the obsidian devs from yoinking it) and I took large code snippets and “algorithms” from Omnisearch, so yeahh … Rebuilding this completely with the same features would probably take waaaaaay more time when I spent to build it now and would also cause a lot more bugs. (also it’s like 600+kB, which is not super great reduced it to ~300kB)

1 Like