SearchIndexItem metadata key or a delegate that returns a SearchIndexItem
instance.
Package
#n Wyam.SearchIndex
Examples
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());
});
});
Usage
-
SearchIndex(DocumentConfig searchIndexItem, FilePath stopwordsPath = null, bool enableStemming = false)Creates the search index by using a delegate that returns a
SearchIndexIteminstance for each input document.searchIndexItemA delegate that should return a
SearchIndexItem.stopwordsPathA file to use that contains a set of stopwords.
enableStemmingIf set to
true, stemming is enabled.
-
SearchIndex(FilePath stopwordsPath = null, bool enableStemming = false)Creates the search index by looking for a
SearchIndexItemmetadata key in each input document that contains aSearchIndexIteminstance.stopwordsPathA file to use that contains a set of stopwords.
enableStemmingIf set to
true, stemming is enabled.
-
SearchIndex(string searchIndexItemMetadataKey, FilePath stopwordsPath = null, bool enableStemming = false)Creates the search index by looking for a specified metadata key in each input document that contains a
SearchIndexIteminstance.searchIndexItemMetadataKeyThe metadata key that contains the
SearchIndexIteminstance.stopwordsPathA file to use that contains a set of stopwords.
enableStemmingIf set to
true, stemming is enabled.
Fluent Methods
Chain these methods together after the constructor to modify behavior.
-
EnableStemming(bool enableStemming = true)Controls whether stemming is turned on.
enableStemmingIf set to
true, stemming is enabled.
-
IncludeHost(bool includeHost = true)Indicates whether the host should be automatically included in generated links.
includeHosttrueto include the host.
-
WithPath(ContextConfig path)Controls the output path of the result document. If this is specified, the resulting
Wyam.Common.IO.FilePathwill be used to set aWritePathmetadata value.pathA delegate that should return a
Wyam.Common.IO.FilePathto the output file.
-
WithPath(FilePath path)Controls the output path of the result document. If this is specified, the resulting
Wyam.Common.IO.FilePathwill be used to set aWritePathmetadata value.pathThe path to the output file.
-
WithScript(Func<StringBuilder, IExecutionContext, string> script)This allows you to customize the Lunr.js JavaScript that this module creates.
scriptA script transformation function. The
System.Text.StringBuildercontains the generated script content. You can manipulate as appropriate and then return the final script as astring.
-
WithStopwordsPath(FilePath stopwordsPath)Sets the path to a stopwords file.
stopwordsPathA file to use that contains a set of stopwords.
Input Metadata
The metadata values listed below apply to individual documents and are typically set from front matter (with just the name of the key) and used as inputs to the module to control behavior.
-
SearchIndexKeys.SearchIndexItem:Wyam.SearchIndex.SearchIndexKeys.SearchIndexItemContains a
Wyam.SearchIndex.SearchIndexKeys.SearchIndexItemthat can be used to provide specific search index information for a given document.
Output Metadata
The metadata values listed below apply to individual documents and are created and set by the module as indicated in their descriptions.
-
Keys.RelativeFilePath:Wyam.Common.IO.FilePathRelative path to the output search index file.
-
Keys.WritePath:Wyam.Common.IO.FilePathThe path to use when writing the file.
