MeiliSearch 0.13.0
See the version list below for details.
dotnet add package MeiliSearch --version 0.13.0
NuGet\Install-Package MeiliSearch -Version 0.13.0
<PackageReference Include="MeiliSearch" Version="0.13.0" />
paket add MeiliSearch --version 0.13.0
#r "nuget: MeiliSearch, 0.13.0"
// Install MeiliSearch as a Cake Addin #addin nuget:?package=MeiliSearch&version=0.13.0 // Install MeiliSearch as a Cake Tool #tool nuget:?package=MeiliSearch&version=0.13.0
⚡ The Meilisearch API client written for .NET
Meilisearch .NET is the Meilisearch API client for C# developers.
Meilisearch is an open-source search engine. Learn more about Meilisearch.
Table of Contents
- 📖 Documentation
- 🔧 Installation
- 🚀 Getting started
- 🤖 Compatibility with Meilisearch
- 🎬 Examples
- 🧰 Use a Custom HTTP Client
- ⚙️ Contributing
📖 Documentation
This readme contains all the documentation you need to start using this Meilisearch SDK.
For general information on how to use Meilisearch—such as our API reference, tutorials, guides, and in-depth articles—refer to our main documentation website.
🔧 Installation
This package targets .NET Standard 2.1.
Using the .NET Core command-line interface (CLI) tools:
dotnet add package MeiliSearch
or with the Package Manager Console:
Install-Package MeiliSearch
Run Meilisearch
There are many easy ways to download and run a Meilisearch instance.
For example, using the curl
command in your Terminal:
# Install Meilisearch
curl -L https://install.meilisearch.com | sh
# Launch Meilisearch
./meilisearch --master-key=masterKey
NB: you can also download Meilisearch from Homebrew or APT or even run it using Docker.
🚀 Getting started
Add Documents
using System;
using System.Threading.Tasks;
using Meilisearch;
namespace GettingStarted
{
class Program
{
public class Movie
{
public string Id { get; set; }
public string Title { get; set; }
public IEnumerable<string> Genres { get; set; }
}
static async Task Main(string[] args)
{
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
// An index is where the documents are stored.
var index = client.Index("movies");
var documents = new Movie[] {
new Movie { Id = "1", Title = "Carol", Genres = new string[] { "Romance", "Drama" } },
new Movie { Id = "2", Title = "Wonder Woman", Genres = new string[] { "Action", "Adventure" } },
new Movie { Id = "3", Title = "Life of Pi", Genres = new string[] { "Adventure", "Drama" } },
new Movie { Id = "4", Title = "Mad Max: Fury Road", Genres = new string[] { "Adventure", "Science Fiction"} },
new Movie { Id = "5", Title = "Moana", Genres = new string[] { "Fantasy", "Action" } },
new Movie { Id = "6", Title = "Philadelphia", Genres = new string[] { "Drama" } }
};
// If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
var task = await index.AddDocumentsAsync<Movie>(documents); // # => { "uid": 0 }
}
}
}
With the uid
, you can check the status (enqueued
, processing
, succeeded
or failed
) of your documents addition using the task.
Basic Search
# Meilisearch is typo-tolerant:
SearchResult<Movie> movies = await index.SearchAsync<Movie>("philadalphia");
foreach(var prop in movies.Hits) {
Console.WriteLine (prop.Title);
}
JSON Output:
{
"hits": [
{
"id": 6,
"title": "Philadelphia",
}
],
"offset": 0,
"limit": 20,
"processingTimeMs": 10,
"query": "philadalphia"
}
Custom Search
All the supported options are described in the search parameters section of the documentation.
SearchResult<Movie> movies = await index.SearchAsync<Movie>(
"car",
new SearchQuery
{
AttributesToHighlight = new string[] { "title" },
}
);
foreach(var prop in movies.Hits) {
Console.WriteLine (prop.Title);
}
JSON Output:
{
"hits": [
{
"id": 1,
"title": "Carol",
"_formatted": {
"id": 1,
"title": "<em>Car</em>ol"
}
}
],
"offset": 0,
"limit": 20,
"processingTimeMs": 10,
"query": "car"
}
Custom Search With Filters
If you want to enable filtering, you must add your attributes to the FilterableAttributes
index setting.
TaskInfo task = await index.UpdateFilterableAttributesAsync(
new string[] { "id", "genres" }
);
You only need to perform this operation once.
Note that MeiliSearch will rebuild your index whenever you update FilterableAttributes
. Depending on the size of your dataset, this might take time. You can track the process using the update status.
Then, you can perform the search:
SearchResult<Movie> movies = await index.SearchAsync<Movie>(
"wonder",
new SearchQuery
{
Filter = "id > 1 AND genres = Action",
}
);
JSON Output:
{
"hits": [
{
"id": 2,
"title": "Wonder Woman",
"genres": ["Action","Adventure"]
}
],
"offset": 0,
"limit": 20,
"estimatedTotalHits": 1,
"processingTimeMs": 0,
"query": "wonder"
}
🤖 Compatibility with Meilisearch
This package only guarantees the compatibility with the version v0.30.0 of Meilisearch.
🎬 Examples
Indexes
Create an index
var index = await client.CreateIndexAsync("movies");
Create an index and give the primary-key
var index = await client.CreateIndexAsync("movies", "id");
List all an index
var indexes = await client.GetAllIndexesAsync();
Get an Index object
var index = await client.GetIndexAsync("movies");
Documents
Add or Update Documents
var task = await index.AddDocumentsAsync(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );
var task = await index.UpdateDocumentsAsync(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );
The returned task
is a TaskInfo
that can access to Uid
to get the status of the task.
Get Documents
var documents = await index.GetDocumentsAsync<Movie>(new DocumentsQuery { Limit = 1 });
Get Document by Id
var document = await index.GetDocumentAsync<Movie>("10");
Delete documents
var task = await index.DeleteOneDocumentAsync("11");
Delete in Batch
var task = await index.DeleteDocumentsAsync(new [] {"12","13","14"});
Delete all documents
var task = await indextoDelete.DeleteAllDocumentsAsync();
Get Task information
Get one Task By Uid
TaskInfo task = await index.GetTaskAsync(1);
// Or
TaskInfo task = await client.GetTaskAsync(1);
Get All Tasks
var task = await index.GetTasksAsync();
// Or
var task = await client.GetTasksAsync();
Search
Basic Search
var movies = await this.index.SearchAsync<Movie>("prince");
Custom Search
var movies = await this.index.SearchAsync<Movie>("prince", new SearchQuery { Limit = 100 });
🧰 Use a Custom HTTP Client
You can replace the default client used in this package by the one you want.
For example:
var _httpClient = ClientFactory.Instance.CreateClient<MeilisearchClient>();
var client = new MeilisearchClient(_httpClient);
Where ClientFactory
is declared like this.
⚙️ Contributing
Any new contribution is more than welcome in this project!
If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!
<hr>
Meilisearch provides and maintains many SDKs and Integration tools like this one. We want to provide everyone with an amazing search experience for any kind of project. If you want to contribute, make suggestions, or just know what's going on right now, visit us in the integration-guides repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.IdentityModel.Tokens.Jwt (>= 6.25.0)
- System.Net.Http.Json (>= 6.0.0)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on MeiliSearch:
Package | Downloads |
---|---|
Pina.MeiliSearch
Package Description |
|
CommunityToolkit.Aspire.Meilisearch
A Meilisearch client that integrates with Aspire, including health checks, logging, and telemetry. |
|
CommunityToolkit.Aspire.Hosting.Meilisearch
Meilisearch support for .NET Aspire. |
|
FluentSearchEngine
Fluent API that works as a wrapper for MeiliSearch, providing fluent filtration, sorting and pagination |
|
Chaosage.Core.Search.Meili
Chaosage开发平台MeiliSearch操作库 |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on MeiliSearch:
Repository | Stars |
---|---|
zoriya/Kyoo
A portable and vast media library solution.
|
|
CommunityToolkit/Aspire
A community project with additional components and extensions for .NET Aspire
|
Version | Downloads | Last updated |
---|---|---|
0.15.4 | 1,250 | 11/14/2024 |
0.15.3 | 27,826 | 8/6/2024 |
0.15.2 | 350 | 8/5/2024 |
0.15.1 | 2,907 | 7/10/2024 |
0.15.0 | 36,124 | 3/11/2024 |
0.14.7 | 13,948 | 1/17/2024 |
0.14.6 | 12,301 | 10/25/2023 |
0.14.5 | 936 | 10/12/2023 |
0.14.4 | 1,568 | 9/25/2023 |
0.14.3 | 17,192 | 7/11/2023 |
0.14.2 | 15,581 | 5/8/2023 |
0.14.1 | 18,991 | 4/3/2023 |
0.14.0 | 3,727 | 3/16/2023 |
0.13.1 | 5,348 | 2/6/2023 |
0.13.0 | 14,243 | 12/5/2022 |
0.12.1 | 10,442 | 11/8/2022 |
0.12.0 | 4,140 | 10/3/2022 |
0.11.0 | 6,879 | 8/1/2022 |
0.10.2 | 5,416 | 5/18/2022 |
0.10.1 | 3,115 | 3/14/2022 |
0.10.0 | 2,101 | 2/16/2022 |
0.9.0 | 999 | 1/25/2022 |
0.8.0 | 2,063 | 11/18/2021 |
0.7.2 | 663 | 10/13/2021 |
0.7.1 | 1,959 | 9/13/2021 |
0.7.0 | 630 | 8/23/2021 |
0.6.1 | 993 | 6/11/2021 |
0.6.0 | 2,281 | 5/25/2021 |
0.5.0 | 379 | 5/24/2021 |
0.4.2 | 7,345 | 4/14/2021 |
0.4.1 | 1,061 | 12/8/2020 |
0.4.0 | 880 | 11/4/2020 |
0.3.2 | 311 | 10/14/2020 |
0.3.1 | 398 | 9/30/2020 |
0.3.0 | 384 | 8/13/2020 |
0.2.2 | 304 | 8/3/2020 |
0.2.1 | 297 | 7/7/2020 |
0.2.0 | 308 | 7/3/2020 |
0.1.0 | 432 | 6/24/2020 |