MeiliSearch | Documentation | Slack | Roadmap | Website | FAQ
⚡ The MeiliSearch API client written for .NET
MeiliSearch .NET is the MeiliSearch API client for C# developers.
MeiliSearch is an open-source search engine. Discover what MeiliSearch is!
- 📖 Documentation
- 🔧 Installation
- 🚀 Getting Started
- 🤖 Compatibility with MeiliSearch
- 🎬 Examples
- 🧰 Use a Custom HTTP Client
- ⚙️ Development Workflow and Contributing
See our Documentation or our API References.
Using the .NET Core command-line interface (CLI) tools:
dotnet add package MeiliSearch
or with the Package Manager Console:
Install-Package MeiliSearch
There are many easy ways to download and run a MeiliSearch instance.
For example, if you use Docker:
docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
NB: you can also download MeiliSearch from Homebrew or APT.
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 string Genre {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 = await client.Index("movies");
var documents = new Movie[] {
new Movie { id = "1", Title = "Carol", Genre = ['Romance', 'Drama'] },
new Movie { Id = "2", Title = "Wonder Woman", Genre = ['Action', 'Adventure'] },
new Movie { Id = "3", Title = "Life of Pi", Genre = ['Adventure', 'Drama'] },
new Movie { Id = "4", Title = "Mad Max: Fury Road", Genre = ['Adventure', 'Science Fiction'] },
new Movie { Id = "5", Title = "Moana", Genre = ['Fantasy', 'Action']},
new Movie { Id = "6", Title = "Philadelphia", Genre = ['Drama'] }
};
// If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
var update = await index.AddDocuments<Movie>(documents); # => { "updateId": 0 }
}
}
}
With the updateId
(via update.UpdateId
), you can check the status (enqueued
, processing
, processed
or failed
) of your documents addition using the update endpoint.
# MeiliSearch is typo-tolerant:
SearchResult<Movie> movies = await index.Search<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"
}
All the supported options are described in the search parameters section of the documentation.
SearchResult<Movie> movies = await index.Search<Movie>(
"car",
new SearchQuery
{
AttributesToHighlight = new string[] { "title" },
}
);
foreach(var prop in movies.Hits) {
Console.WriteLine (movies.Title);
}
JSON Output:
{
"hits": [
{
"id": 1,
"title": "Carol",
"_formatted": {
"id": 1,
"title": "<em>Car</em>ol"
}
}
],
"offset": 0,
"limit": 20,
"processingTimeMs": 10,
"query": "car"
}
This package only guarantees the compatibility with the version v0.23.0 of MeiliSearch.
var index = client.CreateIndex("movies");
var index = client.CreateIndex("movies", "id");
var indexes = await client.GetAllIndexes();
var index = await client.GetIndex("movies");
var updateStatus = await index.AddDocuments(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );
var updateStatus = await index.UpdateDocuments(new Movie[] { new Movie { Id = "1", Title = "Carol" } } );
Update Status has a reference UpdateId
to get the status of the action.
var documents = await index.GetDocuments<Movie>(new DocumentQuery {Limit = 1});
var document = await index.GetDocument<Movie>("10");
var updateStatus = await index.DeleteOneDocument("11");
var updateStatus = await index.DeleteDocuments(new []{"12","13","14"});
var updateStatus = await indextoDelete.DeleteAllDocuments();
UpdateStatus individualStatus = await index.GetUpdateStatus(1);
var status = await index.GetAllUpdateStatus();
var movies = await this.index.Search<Movie>("prince");
var movies = await this.index.Search<Movie>("prince", new SearchQuery {Limit = 100});
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.
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!
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.