Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions and Spellchecking #326

Closed
wants to merge 64 commits into from

Conversation

nzdev
Copy link
Contributor

@nzdev nzdev commented Jan 18, 2023

Adds support for Suggestions for search text.

Adds ISuggester to IIndex for running suggestion queries, includes Lucene implementation.
Added suggester to Demo site.
Added documentation
Added tests

Registering Suggesters

On the index to register the Suggesters, create a SuggesterDefinitionCollection and set it on IndexOptions.SuggesterDefinitions. Only FullText fields can be source fields for suggesters.

Example

 var suggesters = new SuggesterDefinitionCollection();
          suggesters.AddOrUpdate(new AnalyzingInfixSuggesterDefinition(ExamineLuceneSuggesterNames.AnalyzingInfixSuggester, new string[] { "nodeName" }, new RAMSuggesterDirectoryFactory()));
            suggesters.AddOrUpdate(new AnalyzingSuggesterDefinition(ExamineLuceneSuggesterNames.AnalyzingSuggester, new string[] { "nodeName" }));
            suggesters.AddOrUpdate(new DirectSpellCheckerDefinition(ExamineLuceneSuggesterNames.DirectSpellChecker, new string[] { "nodeName" }));
            suggesters.AddOrUpdate(new LevensteinDistanceSuggesterDefinition(ExamineLuceneSuggesterNames.DirectSpellChecker_LevensteinDistance, new string[] { "nodeName" }));
            suggesters.AddOrUpdate(new JaroWinklerDistanceDefinition(ExamineLuceneSuggesterNames.DirectSpellChecker_JaroWinklerDistance, new string[] { "nodeName" }));
            suggesters.AddOrUpdate(new NGramDistanceSuggesterDefinition(ExamineLuceneSuggesterNames.DirectSpellChecker_NGramDistance, new string[] { "nodeName" }));
            suggesters.AddOrUpdate(new FuzzySuggesterDefinition(ExamineLuceneSuggesterNames.FuzzySuggester, new string[] { "nodeName" }));

Suggester API

var suggester = index.Suggester;
var query = suggester.CreateSuggestionQuery();
var results = query.Execute("Sam", new SuggestionOptions(5,ExamineLuceneSuggesterNames.AnalyzingSuggester));

This code will run a suggestion for the input text "Sam", returning up to 5 suggestions.

Lucene Suggesters

To generate suggestions for input text, retreive the ISuggester from the index IIndex.Suggester.

Analyzing Infix Suggester

var suggester = index.Suggester;
var query = suggester.CreateSuggestionQuery();
var results = query.Execute("Sam", new LuceneSuggestionOptions(5, ExamineLuceneSuggesterNames.AnalyzingInfixSuggester));

This code will run a suggestion for the input text "Sam", returning up to 5 suggestions, and will highlight the result text which matches the input text..

Analyzing Suggester

var suggester = index.Suggester;
var query = suggester.CreateSuggestionQuery();
var results = query.Execute("Sam", new LuceneSuggestionOptions(5, ExamineLuceneSuggesterNames.AnalyzingSuggester));

This code will run a suggestion for the input text "Sam", returning up to 5 suggestions.

Fuzzy Suggester

var suggester = index.Suggester;
var query = suggester.CreateSuggestionQuery();
var results = query.Execute("Sam", new LuceneSuggestionOptions(5, ExamineLuceneSuggesterNames.FuzzySuggester));

This code will run a Fuzzy suggestion for the input text "Sam", returning up to 5 suggestions.

Direct SpellChecker Suggester

var suggester = index.Suggester;
var query = suggester.CreateSuggestionQuery();
var results = query.Execute("Sam", new LuceneSuggestionOptions(5, ExamineLuceneSuggesterNames.DirectSpellChecker));

This code will run a spellchecker suggestion for the input text "Sam" returning up to 5 suggestions.

image

docs/suggesting.md Outdated Show resolved Hide resolved
@nzdev
Copy link
Contributor Author

nzdev commented Mar 24, 2023

I think this is in a good spot now that it can be extended and there is support for suggestions in the demoweb.

Copy link
Contributor

@nikcio nikcio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nzdev I've left some comments - It's mostly about XML comments and I didn't mark everything I think you get the gist. You should also consider if this feature should go into Examine v3 or v4. I can see some areas where this could have binary breaking changes and therefore this, should properly be in v4. And then you could rebase and get nullable and XML warnings.

src/Examine.Lucene/Suggest/AnalyzingSuggesterDefinition.cs Outdated Show resolved Hide resolved
src/Examine.Lucene/Suggest/DirectSpellCheckerDefinition.cs Outdated Show resolved Hide resolved
src/Examine.Lucene/Suggest/FuzzySuggesterDefinition.cs Outdated Show resolved Hide resolved
src/Examine.Lucene/Suggest/DirectSpellCheckerDefinition.cs Outdated Show resolved Hide resolved
src/Examine.Lucene/Suggest/AnalyzingSuggesterDefinition.cs Outdated Show resolved Hide resolved
@nikcio nikcio mentioned this pull request Jul 28, 2023
5 tasks
@nzdev nzdev changed the base branch from release/3.0 to release/4.0 July 30, 2023 10:38
@nzdev
Copy link
Contributor Author

nzdev commented Aug 16, 2023

Updated for V4. Docs added.

@nzdev nzdev marked this pull request as draft October 31, 2023 12:32
@nzdev nzdev closed this Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants