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
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.
2025-02-27 23:48:59 -05:00
`You can use the default SDK for everything, but indexs that are disabled through the SDK wont appear until reenabled with the SDK.`
2024-10-01 22:41:07 -04:00
## Features
2024-10-01 23:27:42 -04:00
- [x] **Embedded MeiliSearch** : Integrate MeiliSearch directly into your application.
2025-02-25 01:32:35 -05:00
- [x] **Manage Indexes** : Manage your indexs and documents through the SDK, you can still use the default Meilisearch SDK.
2025-02-25 03:11:59 -05:00
- [x] **Add Documents** : Ability to add documents and have validation on if the index is loaded.
2025-03-01 12:10:16 -05:00
- [x] **Document Batch System** : Automatic batch system for adding documents to indexes that will wait for configured threshold.
2024-10-01 23:27:42 -04:00
- [x] **Background Process Management** : Automatically handles the lifecycle of the MeiliSearch process.
2025-02-25 03:05:26 -05:00
- [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.
2025-03-01 03:13:42 -05:00
- [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.
2025-02-25 09:44:45 +00:00
- [ ] **Search Capabilities** : Ability to use the meilisearch native search capabilities with the index being loaded validation.
2025-02-25 10:12:11 +00:00
- [ ] **Embedded Ollama** : Intergated Ollama directly into your application with a configured model.
2025-02-25 09:44:45 +00:00
- [ ] **AI Search Capabilities** : Ability to use the meilisearch native AI search capabilities with the index being loaded validation.
2024-10-01 22:41:07 -04:00
## Installation
2025-02-25 01:32:35 -05:00
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:
2024-10-01 23:29:10 -04:00
### Package Manager Console
Open the Package Manager Console in Visual Studio and run the following command:
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
### .NET CLI
If you're using the .NET CLI, run the following command in your terminal:
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-02-25 01:32:35 -05:00
## AppSettings Options
- **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.
2024-10-01 23:29:10 -04:00
2025-02-25 01:32:35 -05:00
## Configuration
2024-10-01 23:29:10 -04:00
2025-02-25 01:32:35 -05:00
The MeiliSearch service can be configured using the `MeiliSearchConfiguration` class. The following options are available:
2024-10-01 22:41:07 -04:00
- **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.
2025-02-25 01:32:35 -05:00
You can configure these options in your `appsettings.json` file as follows:
```json
{
"MeiliSearch": {
"Port": 7700,
"UiEnabled": true,
"ApiKey": "your_api_key"
}
}
```
2024-10-01 22:41:07 -04:00
## Usage
2024-10-01 23:36:40 -04:00
To set up the MeiliSearch service in your application, configure dependency injection as shown below:
2024-10-01 22:41:07 -04:00
```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();
```
2024-10-01 23:36:40 -04:00
## MeiliSearchService Class Usage Guide
2024-10-01 22:59:24 -04:00
2024-10-01 23:36:40 -04:00
### Methods
2024-10-01 22:59:24 -04:00
2024-10-01 23:36:40 -04:00
#### Start
2024-10-01 22:59:24 -04:00
2024-10-01 23:36:40 -04:00
Starts the MeiliSearch process. Logs the start of the process, sets the status to **Starting** , and attempts to start the process.
2024-10-01 22:59:24 -04:00
```csharp
MeiliSearchService service = new MeiliSearchService();
service.Start();
```
2024-10-01 23:36:40 -04:00
#### Stop
Stops the MeiliSearch process. Logs the stop of the process, sets the status to **Stopping** , and attempts to stop the process.
2024-10-01 22:59:24 -04:00
```csharp
service.Stop();
```
2024-10-01 23:36:40 -04:00
#### Restart
Restarts the MeiliSearch process. Stops the process using the **Stop** method and starts it using the **Start** method.
2024-10-01 22:59:24 -04:00
```csharp
service.Restart();
```
2025-02-25 01:32:35 -05:00
#### 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 Title { get; set; }
}
var document = new MyDocument { Id = "1", Title = "My Document" };
service.AddDocument("my_index", document);
```
#### GetAllIndexes
Retrieves a list of all existing indexes.
```csharp
List< string > indexes = service.GetAllIndexes();
```
2024-10-01 23:36:40 -04:00
### Status
Indicates the current status of the MeiliSearch process.
2024-10-01 22:59:24 -04:00
```csharp
MeiliSearchStatus status = service.Status;
```
2025-02-25 09:57:13 +00:00
## Notes
https://github.com/Mozilla-Ocho/llamafile
2024-10-01 22:41:07 -04:00
## 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].
---
Feel free to customize this README as necessary for your package, especially regarding the project name and license details!
2024-10-01 23:36:40 -04:00
---