Custom search sample or ability to reload search index help needed #2615
-
Hello my friends. Our prebuilt mkdocs site is modified at runtime by javascript on a page-by-page basis to dynamically hide sections that are not applicable to a particular configuration. This is done simply by hiding various divs by class name. We also have a renumbering javascript which then runs on each page and renumbers the sections of any content left visible including their corresponding table of contents. This works in conjunction with a selection screen (a bunch of HTML selects) that rewrite the current URL history entry with these selection parameters, so when someone visits one of these pages, the aforementioned code knows what to hide and show. This all works great, except for the site search of course, since it is not dynamic, and the search index would need to be categorized by all possible combinations, so not good. This is what I need help with. Our current plan is at build time to walk all the combinations for pages that have dynamic content and generate a search_index_{section}_{combination}.json for each section and parameter combination. Later when someone makes a change on the selection screen we would like to construct a new search_index.json (in memory at least) by concatenating the correct json combinations we previously built, and then have the search work as normal on this new index. Not being that familiar with the React way of coding, are there any samples which show calling out to get an index or build a search_index.json and return it such that the search framework reloads and uses it. All I can currently see is initialization but no way to reload it or have it load my own json file or json from memory. Any help getting this going would be immensely helpful. I’m a very experienced programmer, but just have very little react experience and this is also my first time trying to modify the mkdocs-material search integration. Thank you! All the best. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
As a start, the section on custom search explains how search works on a high level, but it's more dedicated to users who want to replace the search engine without losing the interface. I believe that what you're trying is certainly possible, but definitely tricky. On a side note, Material for MkDocs is not a single page application, and thus not implemented on top of React. We use RxJS for all the plumbing, so a good understanding of that is definitely a plus when you want to dig into the internals. In general, the theme is very hackable and exposes a lot of what's going on to hook into. This folder includes the whole search implementation, i.e. all parts that are of interest, some of which would need to be touched. I have a rough idea of how what you're asking for could be pulled off, but I don't have all of your specs available to sketch out a working solution. It's a very specific request after all. I'm available as a freelancer, so if you want professional support, just drop me an email. |
Beta Was this translation helpful? Give feedback.
As a start, the section on custom search explains how search works on a high level, but it's more dedicated to users who want to replace the search engine without losing the interface. I believe that what you're trying is certainly possible, but definitely tricky.
On a side note, Material for MkDocs is not a single page application, and thus not implemented on top of React. We use RxJS for all the plumbing, so a good understanding of that is definitely a plus when you want to dig into the internals. In general, the theme is very hackable and exposes a lot of what's going on to hook into.
This folder includes the whole search implementation, i.e. all parts that are of interest, some of whi…