fix: readme
Some checks failed
build-packages / meilisearch-dotnet-packages (push) Has been cancelled
Some checks failed
build-packages / meilisearch-dotnet-packages (push) Has been cancelled
This commit is contained in:
parent
845d0a332b
commit
d3c4be572b
261
README.md
261
README.md
@ -9,190 +9,175 @@
|
|||||||
|
|
||||||
## Overview
|
## 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
|
- **Embedded MeiliSearch Engine**: Run MeiliSearch directly within your application
|
||||||
|
- **Automatic Process Management**: Handles startup, shutdown, and health monitoring
|
||||||
- [x] **Embedded MeiliSearch**: Integrate MeiliSearch directly into your application.
|
- **Smart Index Management**:
|
||||||
- [x] **Manage Indexes**: Manage your indexs and documents through the SDK, you can still use the default Meilisearch SDK.
|
- Create and manage indexes with type safety
|
||||||
- [x] **Add Documents**: Ability to add documents and have validation on if the index is loaded.
|
- Enable/disable indexes on demand
|
||||||
- [x] **Document Batch System**: Automatic batch system for adding documents to indexes that will wait for configured threshold.
|
- Automatic compression for optimized storage
|
||||||
- [x] **Background Process Management**: Automatically handles the lifecycle of the MeiliSearch process.
|
- **Efficient Document Management**:
|
||||||
- [x] **Health Monitoring**: Regular checks on the health of the MeiliSearch instance to ensure it stays running.
|
- Batch processing system with configurable thresholds
|
||||||
- [x] **API Key Management**: An API key is automatically regenerated every time the MeiliSearch service starts unless one is specified in the configuration.
|
- Automatic validation of index availability
|
||||||
- [x] **Resource Monitoring**: Monitor the resources being used including storage by your MeiliSearch.
|
- **Resource Monitoring**:
|
||||||
- [x] **Future Index Management**: Upcoming feature to automatically compress and decompress indexes for optimized local storage.
|
- Track memory and CPU usage
|
||||||
- [x] **Caching Mechanism**: Cache the comrpessed indexes so they are returned when you ask for a list of all indexs.
|
- Monitor storage utilization
|
||||||
- [ ] **Search Capabilities**: Ability to use the meilisearch native search capabilities with the index being loaded validation.
|
- Index-specific metrics
|
||||||
- [ ] **Embedded Ollama**: Intergated Ollama directly into your application with a configured model.
|
- **Native SDK Compatibility**: Full support for the official MeiliSearch SDK
|
||||||
- [ ] **AI Search Capabilities**: Ability to use the meilisearch native AI search capabilities with the index being loaded validation.
|
|
||||||
|
|
||||||
## Installation
|
## 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:
|
### Via Package Manager Console
|
||||||
|
|
||||||
### Package Manager Console
|
|
||||||
|
|
||||||
Open the Package Manager Console in Visual Studio and run the following command:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
Install-Package meilisearch.NET
|
Install-Package meilisearch.NET
|
||||||
```
|
```
|
||||||
|
|
||||||
### .NET CLI
|
### Via .NET CLI
|
||||||
|
|
||||||
If you're using the .NET CLI, run the following command in your terminal:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
dotnet add package meilisearch.NET
|
dotnet add package meilisearch.NET
|
||||||
```
|
```
|
||||||
|
|
||||||
## AppSettings Options
|
## Quick Start
|
||||||
|
|
||||||
- **Port**: The port on which MeiliSearch will run (default is `7700`).
|
### 1. Basic Setup
|
||||||
- **UiEnabled**: A boolean value to enable or disable the MeiliSearch UI (default is `true`).
|
Add MeiliSearch service to your dependency injection container:
|
||||||
- **ApiKey**: An optional API key. If specified, this key will be used; otherwise, a new key will be generated each time the service starts.
|
|
||||||
|
|
||||||
## Configuration
|
```csharp
|
||||||
|
var builder = Host.CreateApplicationBuilder();
|
||||||
|
builder.Services.AddMeiliSearchService();
|
||||||
|
```
|
||||||
|
|
||||||
The MeiliSearch service can be configured using the `MeiliSearchConfiguration` class. The following options are available:
|
### 2. Configuration
|
||||||
|
Configure MeiliSearch in your `appsettings.json`:
|
||||||
- **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:
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"MeiliSearch": {
|
"MeiliSearch": {
|
||||||
"Port": 7700,
|
"Port": 7700,
|
||||||
"UiEnabled": true,
|
"UiEnabled": true
|
||||||
"ApiKey": "your_api_key"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
### 3. Basic Usage
|
||||||
|
|
||||||
To set up the MeiliSearch service in your application, configure dependency injection as shown below:
|
|
||||||
|
|
||||||
|
#### Define Your Document Model
|
||||||
```csharp
|
```csharp
|
||||||
using System.Net;
|
public class Product : IDocument
|
||||||
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 string Id { get; set; }
|
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
|
#### Create and Manage Indexes
|
||||||
|
|
||||||
Retrieves a list of all existing indexes.
|
|
||||||
|
|
||||||
```csharp
|
```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
|
## Advanced Usage
|
||||||
|
|
||||||
Indicates the current status of the MeiliSearch process.
|
|
||||||
|
|
||||||
|
### Resource Monitoring
|
||||||
```csharp
|
```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
|
### Index Management
|
||||||
https://github.com/Mozilla-Ocho/llamafile
|
```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
|
## License
|
||||||
|
|
||||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
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
|
## 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
|
||||||
---
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user