Our.Umbraco.SearchSpellCheck 1.0.0-beta.3

This is a prerelease version of Our.Umbraco.SearchSpellCheck.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Our.Umbraco.SearchSpellCheck --version 1.0.0-beta.3
NuGet\Install-Package Our.Umbraco.SearchSpellCheck -Version 1.0.0-beta.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Our.Umbraco.SearchSpellCheck" Version="1.0.0-beta.3" />
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.3
#r "nuget: Our.Umbraco.SearchSpellCheck, 1.0.0-beta.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. 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.3&prerelease

// Install Our.Umbraco.SearchSpellCheck as a Cake Tool
#tool nuget:?package=Our.Umbraco.SearchSpellCheck&version=1.0.0-beta.3&prerelease

Our.Umbraco.SearchSpellCheck

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

NuGet release Build Status

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

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.AutoRebuildIndex" value="true" />
<add key="Our.Umbraco.SearchSpellCheck.AutoRebuildDelay" value="5" />
<add key="Our.Umbraco.SearchSpellCheck.AutoRebuildRepeat" value="30" />

v9

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

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

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 text, Grid Layout and Block List Editor fields.

AutoRebuildIndex

Boolean indicating if you want a background process to run to rebuild the index. Defaults to true.

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.

Usage

The package is a single class called Our.Umbraco.SearchSpellCheck.Suggestions. This class contains two methods:

  • IOrderedEnumerable<Suggestion> GetSuggestions(string searchTerm) - returns a list of suggestions for the given word, and their weight.
  • string GetSuggestion(string searchTerm) - returns the first suggestion for the given word.

v8

Within a SearchService, you could use the Suggestions class to get suggestions for a given word:

public string GetSuggestion(string searchTerm)
{
    return Suggestions.GetSuggestion(searchTerm);
}

This could then be returned within a ViewModel:

if (!string.IsNullOrEmpty(viewModel.SearchTerm))
{
    viewModel.SpellCheck = _searchService.GetSuggestion(viewModel.SearchTerm);
}

And then in your view:

@if (Model.TotalResults == 0 && !string.IsNullOrEmpty(Model.SpellCheck))
{
    @:Did you mean <em><a href="?q=@Model.SpellCheck">@Model.SpellCheck</a></em>?
}

License

Copyright © 2021 Rick Butterfield, and other contributors

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 2,094 12/3/2021
1.0.0-beta.10 2,966 11/25/2021
1.0.0-beta.9 2,608 11/25/2021
1.0.0-beta.8 3,636 11/25/2021
1.0.0-beta.7 170 11/22/2021
1.0.0-beta.6 152 11/22/2021
1.0.0-beta.5 160 11/19/2021
1.0.0-beta.4 184 11/19/2021
1.0.0-beta.3 155 11/19/2021