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

Hard to find documentation about highlighting. #851

Open
SebastianStehle opened this issue Feb 11, 2024 · 2 comments
Open

Hard to find documentation about highlighting. #851

SebastianStehle opened this issue Feb 11, 2024 · 2 comments

Comments

@SebastianStehle
Copy link
Contributor

I spent hours to find documentation or a sample how to use highlighting. Eventually I figured it out myself and created the following base class:

public abstract record IndexedSearchItem
{
    [JsonProperty(PropertyName ="_snippetResult")]
    public Dictionary<string, SnippetResult>? SnippetResult { get; set; }

    [JsonProperty(PropertyName = "_highlightResult")]
    public Dictionary<string, HighlightResult>? HighlightResult { get; set; }

    public string RenderProperty(string property)
    {
        if (SnippetResult?.TryGetValue(property, out var snippetResult) == true)
        {
            return snippetResult.Value;
        }

        if (HighlightResult?.TryGetValue(property, out var highlightResult) == true)
        {
            return highlightResult.Value;
        }

        var clrProperty = GetType().GetProperties().FirstOrDefault(x => string.Equals(x.Name, property, StringComparison.OrdinalIgnoreCase));

        if (clrProperty?.CanRead == true)
        {
            return clrProperty.GetValue(this)?.ToString() ?? string.Empty;
        }

        return string.Empty;
    }

    public bool ShouldSerializeSnippetResult()
    {
        return false;
    }

    public bool ShouldSerializeHighlightResult()
    {
        return false;
    }
}

Would be great to have documentation about this...

@morganleroi
Copy link
Contributor

Hello,

We will release in few days a new major version of all Algolia C# Clients. In this version, Highlight and Snippet are directly available.

I'll reply in this thread as soon as the client is released.

@morganleroi
Copy link
Contributor

The Alpha version is now released on Nuget.

If you have time, we need customer feedback about this new version. It's still not GA so you may not want to use it in production.

There is no more deps on Newtonsoft, all Algolia APIs are now available (Insights, Recommend, Query Perso, ...) and all models and routes are synced.

To help you migrate, there is a Migration guide.

Happy to help in your migration process !

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

No branches or pull requests

2 participants