Damien ef6ff45f40
All checks were successful
build-packages / run-tests (push) Successful in 6m16s
build-packages / nuget-package (push) Successful in 6m26s
feat!:comments for documentation in IDE
2025-03-01 14:43:13 -05:00
2025-03-01 14:42:26 -05:00
2024-10-01 22:55:24 -04:00
2024-10-01 22:55:24 -04:00
2025-02-24 09:18:51 +00:00
2025-03-01 19:13:25 +00:00

MeiliSearch .NET Embedded

Gitea Release Dotnet 8 Meilisearch Ollama Gitea License Discord

Overview

MeiliSearch .NET Embedded is a powerful NuGet package that seamlessly integrates MeiliSearch into your .NET applications. It provides a robust wrapper around MeiliSearch, handling process management, health monitoring, and advanced features like index compression - all while maintaining compatibility with the native MeiliSearch SDK.

Key Features

  • Embedded MeiliSearch Engine: Run MeiliSearch directly within your application
  • Automatic Process Management: Handles startup, shutdown, and health monitoring
  • Smart Index Management:
    • Create and manage indexes with type safety
    • Enable/disable indexes on demand
    • Automatic compression for optimized storage
  • Efficient Document Management:
    • Batch processing system with configurable thresholds
    • Automatic validation of index availability
  • Resource Monitoring:
    • Track memory and CPU usage
    • Monitor storage utilization
    • Index-specific metrics
  • Native SDK Compatibility: Full support for the official MeiliSearch SDK

Installation

Via Package Manager Console

Install-Package meilisearch.NET

Via .NET CLI

dotnet add package meilisearch.NET

Quick Start

1. Basic Setup

Add MeiliSearch service to your dependency injection container:

var builder = Host.CreateApplicationBuilder();
builder.Services.AddMeiliSearchService();

2. Configuration

Configure MeiliSearch in your appsettings.json:

{
  "MeiliSearch": {
    "Port": 7700,
    "UiEnabled": true
  }
}

3. Basic Usage

Define Your Document Model

public class Product : IDocument
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public decimal Price { get; set; }
}

Create and Manage Indexes

public class SearchService
{
    private readonly MeiliSearchService _searchService;

    public SearchService(MeiliSearchService searchService)
    {
        _searchService = searchService;
    }

    public async Task InitializeProductIndex()
    {
        // Create index
        await _searchService.CreateIndex<Product>("products");

        // Add documents
        var product = new Product 
        {
            Id = "1",
            Name = "Gaming Laptop",
            Description = "High-performance gaming laptop",
            Price = 1299.99m
        };
        
        _searchService.AddDocument("products", product);
        
        //_searchService.AddDocument("products", product, true); if you set the third parameter, which is autocommit, to true, it will ignore batching.
    }
}

4. Use MeiliSearch SDK

Using Native MeiliSearch SDK

await _searchService.SDK("products", async client => 
{
    var index = await client.GetIndex("products");
    var searchResults = await index.SearchAsync<Product>("laptop");
    return searchResults;
});

Advanced Usage

Resource Monitoring

var usage = _searchService.GetResourceUsage();
Console.WriteLine($"Memory Usage: {usage.MemoryUsageBytes} bytes");
Console.WriteLine($"CPU Usage: {usage.CpuPercentage}%");
Console.WriteLine($"Storage Usage: {_searchService.GetTotalStorageUsage()} bytes");

Index Management

// Disable an index (automatically compresses)
await _searchService.SetIndexEnabled("products", false);

// Enable an index (automatically decompresses)
await _searchService.SetIndexEnabled("products", true);

// Get all indexes
var indexes = await _searchService.GetAllIndexes();

Best Practices

  1. Resource Management

    • Always dispose of the MeiliSearchService when your application shuts down
    • Monitor resource usage in production environments
  2. Index Management

    • Disable unused indexes to save resources
    • Use type-safe index creation with generic parameters
  3. Document Management

    • Utilize batch processing for bulk operations
    • Handle exceptions when adding documents

Performance Considerations

  • The batch system automatically manages document additions with a default threshold of 100 documents
  • Compressed indexes use less storage but require decompression before use
  • Monitor resource usage in production environments

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

  • Create an issue on GitHub
  • Contact us on discord Discord
  • Visit our documentation at meilisearchdotnet.d4m13n.dev

Acknowledgments

  • Built on top of the excellent MeiliSearch search engine
  • Powered by Ollama for AI capabilities
Description
Package to embed meilisearch server in your .NET application and interact with it.
Readme 4 GiB
Release 0.4.0 Latest
2025-03-01 19:43:13 +00:00
Languages
C# 84.2%
PowerShell 15.8%