Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Implemented SearchIndex module based on lunr.js #118
To add items to the search index, the meta data
Values for document url, title and content are obligatory.
For JS, lunr.min.js is a prerequisite, which comes with the example. jQuery is not a dependency, but it is used for convinience in the example project.
This information can be used to display the results in a pleasent way and to generate an url that links to the respective document.
I added the possibility to add a stopword list to reduce the size of the generated index. The stoplist from lunr.js was disabled. Maintaining the stopwordlist via Wyam ist more flexible, because users can easily specify stopwordlists for other languages.
This was awesome, really excellent work. The example really sells it too, so thanks for including that. I'm going to push this in the next release - as far as I know, we've now got the only static site generator that can automatically generate client-side searching support.
I've merged the PR because I want to start using it right away. However, I do have a couple comments and observations that may warrant discussion.
Altogether, fantastic work. I'm really excited to have you on board as a team member.
Thanks for your kind words, I'm glad you like it.
Regarding your points:
It would be nice if you keep me up to date how the search index works for your documentation.
Glad to be on board :)
added a commit
this pull request
Nov 9, 2015
I was really anxious to see how this worked, so I went ahead and made the changes discussed above so that I could integrate into the new Wyam site. It worked perfectly! Here's a screen shot:
I've limited the search index to the names of classes and interfaces to make sure it was small enough, but that's really all I need right now. At some point I may investigate how to get the JS search index file to load asynchronously in the background so that we can load larger index files without noticeable lag, but this works great for now.
For context, here's the relevant segments of the config file:
Pipelines.Add("Code", //ReadSolution(@"..\Code\Wyam\Wyam.sln") // Read from the master Wyam branch in the Git submodule ReadSolution(@"..\..\Wyam\Wyam.sln") // Read from the current branch on disk in the actual repo .WhereProject(x => !x.EndsWith(".Tests")) ); Pipelines.Add("API", Documents("Code"), AnalyzeCSharp() .WhereNamespaces(false) .WhereNamespaces(x => !x.StartsWith("Wyam.Modules.Razor.Microsoft")) .WherePublic() .WithCssClasses("pre", "prettyprint") .WithWritePathPrefix("api"), Razor() .WithViewStart(@"api\_ApiViewStart.cshtml"), ConcatBranch( Where(@doc.String("Kind") == "NamedType"), SearchIndex(new SearchIndexItem( "/" + @doc.String("WritePath").Replace("/index.html", string.Empty), @doc.String("DisplayName"), @doc.String("DisplayName"))), Meta("WritePath", @"Scripts\searchIndex.js") ), WriteFiles() );
That loads the code source files in the "Code" module and then uses the AnalyzeCSharp module to output a document-per-symbol with some specific settings, runs each symbol document through a Razor template, and then concats the search index. You can see I'm using the new delegate support to create