2024-10-01 23:36:40 -04:00
# MeiliSearch .NET Embedded
2024-10-01 22:41:07 -04:00
2025-02-24 09:12:27 +00:00


2025-02-25 10:11:10 +00:00


2025-02-24 09:12:27 +00:00
[](#)
2024-10-01 22:41:07 -04:00
[](LICENSE)
## Overview
2025-03-01 13:32:06 -05:00
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
2024-10-01 22:41:07 -04:00
## Installation
2025-03-01 13:32:06 -05:00
### Via Package Manager Console
2024-10-01 22:41:07 -04:00
```bash
2025-02-25 01:32:35 -05:00
Install-Package meilisearch.NET
2024-10-01 23:36:40 -04:00
```
2024-10-01 23:29:10 -04:00
2025-03-01 13:32:06 -05:00
### Via .NET CLI
2024-10-01 22:41:07 -04:00
```bash
2025-02-25 01:32:35 -05:00
dotnet add package meilisearch.NET
2024-10-01 22:41:07 -04:00
```
2025-03-01 13:32:06 -05:00
## Quick Start
2024-10-01 23:29:10 -04:00
2025-03-01 13:32:06 -05:00
### 1. Basic Setup
Add MeiliSearch service to your dependency injection container:
2024-10-01 22:41:07 -04:00
2025-03-01 13:32:06 -05:00
```csharp
var builder = Host.CreateApplicationBuilder();
builder.Services.AddMeiliSearchService();
```
2024-10-01 22:41:07 -04:00
2025-03-01 13:32:06 -05:00
### 2. Configuration
Configure MeiliSearch in your `appsettings.json` :
2025-02-25 01:32:35 -05:00
```json
{
"MeiliSearch": {
"Port": 7700,
2025-03-01 13:32:06 -05:00
"UiEnabled": true
2025-02-25 01:32:35 -05:00
}
}
```
2025-03-01 13:32:06 -05:00
### 3. Basic Usage
2024-10-01 22:41:07 -04:00
2025-03-01 13:32:06 -05:00
#### Define Your Document Model
2024-10-01 22:41:07 -04:00
```csharp
2025-03-01 13:32:06 -05:00
public class Product : IDocument
{
public string Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
2024-10-01 22:41:07 -04:00
```
2025-03-01 13:32:06 -05:00
#### Create and Manage Indexes
2024-10-01 22:59:24 -04:00
```csharp
2025-03-01 13:32:06 -05:00
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);
}
}
2024-10-01 22:59:24 -04:00
```
2025-03-01 13:32:06 -05:00
## Advanced Usage
2024-10-01 22:59:24 -04:00
2025-03-01 13:32:06 -05:00
### Resource Monitoring
2024-10-01 22:59:24 -04:00
```csharp
2025-03-01 13:32:06 -05:00
var usage = _searchService.GetResourceUsage();
Console.WriteLine($"Memory Usage: {usage.MemoryUsageBytes} bytes");
Console.WriteLine($"CPU Usage: {usage.CpuPercentage}%");
Console.WriteLine($"Storage Usage: {_searchService.GetTotalStorageUsage()} bytes");
2024-10-01 22:59:24 -04:00
```
2025-03-01 13:32:06 -05:00
### Index Management
2025-02-25 01:32:35 -05:00
```csharp
2025-03-01 13:32:06 -05:00
// Disable an index (automatically compresses)
await _searchService.SetIndexEnabled("products", false);
2025-02-25 01:32:35 -05:00
2025-03-01 13:32:06 -05:00
// Enable an index (automatically decompresses)
await _searchService.SetIndexEnabled("products", true);
2025-02-25 01:32:35 -05:00
2025-03-01 13:32:06 -05:00
// Get all indexes
var indexes = await _searchService.GetAllIndexes();
2025-02-25 01:32:35 -05:00
```
2025-03-01 13:32:06 -05:00
### Using Native MeiliSearch SDK
2025-02-25 01:32:35 -05:00
```csharp
2025-03-01 13:32:06 -05:00
await _searchService.SDK("products", async client =>
2025-02-25 01:32:35 -05:00
{
2025-03-01 13:32:06 -05:00
var index = await client.GetIndex("products");
var searchResults = await index.SearchAsync< Product > ("laptop");
return searchResults;
});
2025-02-25 01:32:35 -05:00
```
2025-03-01 13:32:06 -05:00
## Best Practices
2025-02-25 01:32:35 -05:00
2025-03-01 13:32:06 -05:00
1. **Resource Management**
- Always dispose of the `MeiliSearchService` when your application shuts down
- Monitor resource usage in production environments
2025-02-25 01:32:35 -05:00
2025-03-01 13:32:06 -05:00
2. **Index Management**
- Disable unused indexes to save resources
- Use type-safe index creation with generic parameters
2025-02-25 01:32:35 -05:00
2025-03-01 13:32:06 -05:00
3. **Document Management**
- Utilize batch processing for bulk operations
- Handle exceptions when adding documents
2024-10-01 23:36:40 -04:00
2025-03-01 13:32:06 -05:00
## Performance Considerations
2024-10-01 22:59:24 -04:00
2025-03-01 13:32:06 -05:00
- 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
2024-10-01 22:59:24 -04:00
2025-03-01 13:32:06 -05:00
## Contributing
We welcome contributions! Please follow these steps:
2025-02-25 09:57:13 +00:00
2025-03-01 13:32:06 -05:00
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
2025-02-25 09:57:13 +00:00
2024-10-01 22:41:07 -04:00
## License
This project is licensed under the MIT License - see the [LICENSE ](LICENSE ) file for details.
## Support
2025-03-01 13:32:06 -05:00
- Create an issue on GitHub
- Contact us at [your contact method]
- Visit our documentation at [your docs URL]
2024-10-01 22:41:07 -04:00
2025-03-01 13:32:06 -05:00
## Acknowledgments
2024-10-01 22:41:07 -04:00
2025-03-01 13:32:06 -05:00
- Built on top of the excellent [MeiliSearch ](https://www.meilisearch.com/ ) search engine
- Powered by [Ollama ](https://ollama.ai/ ) for AI capabilities