SearchIndex Class

Summary

Generates a JavaScript-based search index from the input documents.
Assembly
Wyam.SearchIndex.dll
Namespace
Wyam.SearchIndex
Interfaces
Base Types
  • Object
graph BT Type-->Base0["Object"] Type-.->Interface0["IModule"] click Interface0 "/api/Wyam.Common.Modules/IModule" Type["SearchIndex"] class Type type-node

Syntax

public class SearchIndex : IModule

Examples

The client-side JavaScript code for importing the search index should look something like this (assuming you have an HTML input with an ID of #search and a div with an ID of #search-results):
 function runSearch(query) {
     $("#search-results").empty();
     if (query.length < 2)
     {
         return;
     }
     var results = searchModule.search(query);
     var listHtml = "<ul>";
     listHtml += "<li><strong>Search Results</strong></li>";
     if (results.length == 0)
     {
         listHtml += "<li>No results found</li>";
     }
     else
     {
         for (var i = 0; i < results.length; ++i)
         {
             var res = results[i];
             listHtml += "<li><a href='" + res.url + "'>" + res.title + "</a></li>";
         }
     }
     listHtml += "</ul>";
     $("#search-results").append(listHtml);
 }

 $(document).ready(function() {
     $("#search").on('input propertychange paste', function() {
         runSearch($("#search").val());
     });
 });

Remarks

This module generates a search index that can be imported into the JavaScript Lunr.js search engine. Each input document should either specify the SearchIndexItem metadata key or a delegate that returns a SearchIndexItem instance.

Constructors

Name Summary
SearchIndex(DocumentConfig, FilePath, bool) Creates the search index by using a delegate that returns a SearchIndexItem instance for each input document.
SearchIndex(FilePath, bool) Creates the search index by looking for a SearchIndexItem metadata key in each input document that contains a SearchIndexItem instance.
SearchIndex(string, FilePath, bool) Creates the search index by looking for a specified metadata key in each input document that contains a SearchIndexItem instance.

Methods

Name Value Summary
EnableStemming(bool) SearchIndex
Controls whether stemming is turned on.
Execute(IReadOnlyList<IDocument>, IExecutionContext) IEnumerable<IDocument>
This should not be called directly, instead call IExecutionContext.Execute() if you need to execute a module from within another module.
IncludeHost(bool) SearchIndex
Indicates whether the host should be automatically included in generated links.
WithPath(ContextConfig) SearchIndex
Controls the output path of the result document. If this is specified, the resulting Wyam.Common.IO.FilePath will be used to set a WritePath metadata value.
WithPath(FilePath) SearchIndex
Controls the output path of the result document. If this is specified, the resulting Wyam.Common.IO.FilePath will be used to set a WritePath metadata value.
WithScript(Func<StringBuilder, IExecutionContext, string>) SearchIndex
This allows you to customize the Lunr.js JavaScript that this module creates.
WithStopwordsPath(FilePath) SearchIndex
Sets the path to a stopwords file.
GitHub