Our.Umbraco.SearchSpellCheck 1.0.0-beta.11

This is a prerelease version of Our.Umbraco.SearchSpellCheck.
Install-Package Our.Umbraco.SearchSpellCheck -Version 1.0.0-beta.11
dotnet add package Our.Umbraco.SearchSpellCheck --version 1.0.0-beta.11
<PackageReference Include="Our.Umbraco.SearchSpellCheck" Version="1.0.0-beta.11" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Our.Umbraco.SearchSpellCheck --version 1.0.0-beta.11
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Our.Umbraco.SearchSpellCheck, 1.0.0-beta.11"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Our.Umbraco.SearchSpellCheck as a Cake Addin
#addin nuget:?package=Our.Umbraco.SearchSpellCheck&version=1.0.0-beta.11&prerelease

// Install Our.Umbraco.SearchSpellCheck as a Cake Tool
#tool nuget:?package=Our.Umbraco.SearchSpellCheck&version=1.0.0-beta.11&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Our.Umbraco.SearchSpellCheck GitHub license NuGet CI

A Lucene.Net-based spell checker for Umbraco v8 and v9.

This project wouldn't exist without Lars-Erik Aabech who created a v7 version of this, which a lot of the work is based on.

How it works

alt text

On startup, this extension will index all the content in your site based on the IndexedFields settings. On every search, the extension will check the multi-word search term against the index and suggest the most likely words to the user.

Installation

At present, the only way to install this is to use NuGet. You can find the package on NuGet.org and install it using the Package Manager UI in Visual Studio.

Configuration

v9

In v9 you'll need to use the appSettings.json file instead of the web.config file.

{
    "SearchSpellCheck": {
        "IndexName": "SpellCheckIndex",
        "IndexedFields": [ "nodeName" ],
        "BuildOnStartup": true,
        "RebuildOnPublish": true,
        "AutoRebuildIndex": false,
        "AutoRebuildDelay": 5,
        "AutoRebuildRepeat": 30,
        "EnableLogging": false
    }
}

v8

When the package is installed, new keys will be added to the appSettings section of your web.config:

<add key="Our.Umbraco.SearchSpellCheck.IndexName" value="SpellCheckIndex" />
<add key="Our.Umbraco.SearchSpellCheck.IndexedFields" value="nodeName" />
<add key="Our.Umbraco.SearchSpellCheck.BuildOnStartup" value="true" />
<add key="Our.Umbraco.SearchSpellCheck.RebuildOnPublish" value="true" />
<add key="Our.Umbraco.SearchSpellCheck.AutoRebuildIndex" value="false" />
<add key="Our.Umbraco.SearchSpellCheck.AutoRebuildDelay" value="5" />
<add key="Our.Umbraco.SearchSpellCheck.AutoRebuildRepeat" value="30" />
<add key="Our.Umbraco.SearchSpellCheck.EnableLogging" value="false" />

Settings

IndexName: The name of the Lucene index to be created. This is the also name of the folder in the App_Data folder that contains the Lucene index. By default it is SpellCheckIndex but this can be changed if you need a different naming convention.

IndexedFields: The alias(es) of fields to be indexed. This is a comma-separated list of field names. By default only the nodeName field is indexed. Currently, there is support for textstring, textareas, TinyMCE, Grid Layout and Block List Editor fields.

BuildOnStartup: Boolean indicating if you want the index to be populated on startup. Defaults to true.

RebuildOnPublish: Boolean indicating if you want the index to be populated on content being saved and published successfully. Defaults to true.

AutoRebuildIndex: Boolean indicating if you want a background process to run to rebuild the index. Defaults to false.

AutoRebuildDelay: Number of minutes you want to delay the background process from starting. Defaults to 5 minutes.

AutoRebuildRepeat: Number of minutes you want the scheduled background process to run. Defaults to 30 minutes.

EnableLogging: Useful if you want to see what properties are being indexed and the content that is returned from the index. Defaults to false.

Usage

The package enables an ISuggestionService to be injected into your constructor:

private readonly IExamineManager _examineManager;
private readonly ISuggestionService _suggestionService;

public SearchService(IExamineManager examineManager, ISuggestionService suggestionService)
{
    _examineManager = examineManager;
    _suggestionService = suggestionService;
}

public string GetSuggestions(string searchTerm)
{
    return _suggestionService.GetSuggestion(searchTerm, suggestionAccuracy: 0.25f);
}

Which could in turn be returned in a view component or model:

if (model.TotalResults == 0)
{
    model.SpellCheck = _searchService.GetSuggestions(model.SearchTerm);
}

And then returned in the view:

@if (!string.IsNullOrEmpty(Model.SpellCheck))
{
    <p>Did you mean <a href="?s=@Model.SpellCheck"><em>@Model.SpellCheck</em></a>?</p>
}

License

Copyright © 2021 Rick Butterfield, and other contributors

Licensed under the MIT License.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-beta.11 520 12/3/2021
1.0.0-beta.10 2,890 11/25/2021
1.0.0-beta.9 2,529 11/25/2021
1.0.0-beta.8 3,549 11/25/2021
1.0.0-beta.7 71 11/22/2021
1.0.0-beta.6 54 11/22/2021
1.0.0-beta.5 63 11/19/2021
1.0.0-beta.4 81 11/19/2021
1.0.0-beta.3 58 11/19/2021