fix: readme
Some checks failed
build-packages / meilisearch-dotnet-packages (push) Has been cancelled

This commit is contained in:
Damien 2025-03-01 13:32:06 -05:00
parent 845d0a332b
commit d3c4be572b

261
README.md
View File

@ -9,190 +9,175 @@
## Overview
MeiliSearch .NET Integration is a NuGet package that seamlessly embeds MeiliSearch into your C# application. It manages the background process and health checks for you, simplifying the integration of full-text search capabilities. In future updates, it will also handle automatic compression and decompression of indexes to help manage local storage usage effectively.
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.
`You can use the default SDK for everything, but indexs that are disabled through the SDK wont appear until reenabled with the SDK.`
## Key Features
## Features
- [x] **Embedded MeiliSearch**: Integrate MeiliSearch directly into your application.
- [x] **Manage Indexes**: Manage your indexs and documents through the SDK, you can still use the default Meilisearch SDK.
- [x] **Add Documents**: Ability to add documents and have validation on if the index is loaded.
- [x] **Document Batch System**: Automatic batch system for adding documents to indexes that will wait for configured threshold.
- [x] **Background Process Management**: Automatically handles the lifecycle of the MeiliSearch process.
- [x] **Health Monitoring**: Regular checks on the health of the MeiliSearch instance to ensure it stays running.
- [x] **API Key Management**: An API key is automatically regenerated every time the MeiliSearch service starts unless one is specified in the configuration.
- [x] **Resource Monitoring**: Monitor the resources being used including storage by your MeiliSearch.
- [x] **Future Index Management**: Upcoming feature to automatically compress and decompress indexes for optimized local storage.
- [x] **Caching Mechanism**: Cache the comrpessed indexes so they are returned when you ask for a list of all indexs.
- [ ] **Search Capabilities**: Ability to use the meilisearch native search capabilities with the index being loaded validation.
- [ ] **Embedded Ollama**: Intergated Ollama directly into your application with a configured model.
- [ ] **AI Search Capabilities**: Ability to use the meilisearch native AI search capabilities with the index being loaded validation.
- **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
To add the MeiliSearch .NET Integration package to your project, you can install it directly from NuGet. Follow the steps below based on your preferred method:
### Package Manager Console
Open the Package Manager Console in Visual Studio and run the following command:
### Via Package Manager Console
```bash
Install-Package meilisearch.NET
```
### .NET CLI
If you're using the .NET CLI, run the following command in your terminal:
### Via .NET CLI
```bash
dotnet add package meilisearch.NET
```
## AppSettings Options
## Quick Start
- **Port**: The port on which MeiliSearch will run (default is `7700`).
- **UiEnabled**: A boolean value to enable or disable the MeiliSearch UI (default is `true`).
- **ApiKey**: An optional API key. If specified, this key will be used; otherwise, a new key will be generated each time the service starts.
### 1. Basic Setup
Add MeiliSearch service to your dependency injection container:
## Configuration
```csharp
var builder = Host.CreateApplicationBuilder();
builder.Services.AddMeiliSearchService();
```
The MeiliSearch service can be configured using the `MeiliSearchConfiguration` class. The following options are available:
- **Port**: The port on which MeiliSearch will run (default is `7700`).
- **UiEnabled**: A boolean value to enable or disable the MeiliSearch UI (default is `true`).
- **ApiKey**: An optional API key. If specified, this key will be used; otherwise, a new key will be generated each time the service starts.
You can configure these options in your `appsettings.json` file as follows:
### 2. Configuration
Configure MeiliSearch in your `appsettings.json`:
```json
{
"MeiliSearch": {
"Port": 7700,
"UiEnabled": true,
"ApiKey": "your_api_key"
"UiEnabled": true
}
}
```
## Usage
To set up the MeiliSearch service in your application, configure dependency injection as shown below:
### 3. Basic Usage
#### Define Your Document Model
```csharp
using System.Net;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
var builder = Host.CreateApplicationBuilder();
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Services.AddMeiliSearchService();
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.SetMinimumLevel(LogLevel.Information);
builder.Services.AddLogging();
var app = builder.Build();
app.Run();
Console.ReadLine();
```
## MeiliSearchService Class Usage Guide
### Methods
#### Start
Starts the MeiliSearch process. Logs the start of the process, sets the status to **Starting**, and attempts to start the process.
```csharp
MeiliSearchService service = new MeiliSearchService();
service.Start();
```
#### Stop
Stops the MeiliSearch process. Logs the stop of the process, sets the status to **Stopping**, and attempts to stop the process.
```csharp
service.Stop();
```
#### Restart
Restarts the MeiliSearch process. Stops the process using the **Stop** method and starts it using the **Start** method.
```csharp
service.Restart();
```
#### CreateIndex
Creates a new index with the specified name.
```csharp
service.CreateIndex("my_index");
```
#### DeleteIndex
Deletes an existing index with the specified name.
```csharp
service.DeleteIndex("my_index");
```
#### AddDocument
Adds a document to the specified index.
```csharp
public class MyDocument : IDocument
public class Product : IDocument
{
public string Id { get; set; }
public string Title { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
}
var document = new MyDocument { Id = "1", Title = "My Document" };
service.AddDocument("my_index", document);
```
#### GetAllIndexes
Retrieves a list of all existing indexes.
#### Create and Manage Indexes
```csharp
List<string> indexes = service.GetAllIndexes();
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);
}
}
```
### Status
Indicates the current status of the MeiliSearch process.
## Advanced Usage
### Resource Monitoring
```csharp
MeiliSearchStatus status = service.Status;
var usage = _searchService.GetResourceUsage();
Console.WriteLine($"Memory Usage: {usage.MemoryUsageBytes} bytes");
Console.WriteLine($"CPU Usage: {usage.CpuPercentage}%");
Console.WriteLine($"Storage Usage: {_searchService.GetTotalStorageUsage()} bytes");
```
## Notes
https://github.com/Mozilla-Ocho/llamafile
### Index Management
```csharp
// 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();
```
### Using Native MeiliSearch SDK
```csharp
await _searchService.SDK("products", async client =>
{
var index = await client.GetIndex("products");
var searchResults = await index.SearchAsync<Product>("laptop");
return searchResults;
});
```
## 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](LICENSE) file for details.
## Contributing
We welcome contributions! Please feel free to submit issues, pull requests, or suggestions to improve this project.
## Support
For any issues or questions, please open an issue on GitHub or contact us via [your contact method].
- Create an issue on GitHub
- Contact us at [your contact method]
- Visit our documentation at [your docs URL]
---
## Acknowledgments
Feel free to customize this README as necessary for your package, especially regarding the project name and license details!
---
- Built on top of the excellent [MeiliSearch](https://www.meilisearch.com/) search engine
- Powered by [Ollama](https://ollama.ai/) for AI capabilities