Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

.NET wrapper for the Meilisearch API

License

NotificationsYou must be signed in to change notification settings

meilisearch/meilisearch-dotnet

Repository files navigation

Meilisearch-Dotnet

Meilisearch .NET

NuGetGitHub Workflow StatusLicenseBors enabled

⚡ 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

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 ourmain 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 thePackage Manager Console:

Install-Package MeiliSearch

Run Meilisearch

⚡️Launch, scale, and streamline in minutes with Meilisearch Cloud—no maintenance, no commitment, cancel anytime.Try it free now.

🪨 Prefer to self-host?Download and deploy our fast, open-source search engine on your own infrastructure.

🚀 Getting started

Add Documents

usingSystem;usingSystem.Threading.Tasks;usingMeilisearch;namespaceGettingStarted{classProgram{publicclassMovie{publicstringId{get;set;}publicstringTitle{get;set;}publicIEnumerable<string>Genres{get;set;}}staticasyncTaskMain(string[]args){MeilisearchClientclient=newMeilisearchClient("http://localhost:7700","masterKey");// An index is where the documents are stored.varindex=client.Index("movies");vardocuments=newMovie[]{newMovie{Id="1",Title="Carol",Genres=newstring[]{"Romance","Drama"}},newMovie{Id="2",Title="Wonder Woman",Genres=newstring[]{"Action","Adventure"}},newMovie{Id="3",Title="Life of Pi",Genres=newstring[]{"Adventure","Drama"}},newMovie{Id="4",Title="Mad Max: Fury Road",Genres=newstring[]{"Adventure","Science Fiction"}},newMovie{Id="5",Title="Moana",Genres=newstring[]{"Fantasy","Action"}},newMovie{Id="6",Title="Philadelphia",Genres=newstring[]{"Drama"}}};// If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.vartask=awaitindex.AddDocumentsAsync<Movie>(documents);// # => { "uid": 0 }}}}

With theuid, you can check the status (enqueued,canceled,processing,succeeded orfailed) of your documents addition using thetask.

Basic Search

//Meilisearch is typo-tolerant:SearchResult<Movie>movies=awaitindex.SearchAsync<Movie>("philadalphia");foreach(varpropinmovies.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 thesearch parameters section of the documentation.

varmovies=awaitindex.SearchAsync<Movie>("car",newSearchQuery{AttributesToHighlight=newstring[]{"title"},});foreach(varpropinmovies.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 theFilterableAttributes index setting.

TaskInfotask=awaitindex.UpdateFilterableAttributesAsync(newstring[]{"id","genres"});

You only need to perform this operation once.

Note that MeiliSearch will rebuild your index whenever you updateFilterableAttributes. Depending on the size of your dataset, this might take time. You can track the process using theupdate status.

Then, you can perform the search:

varmovies=awaitindex.SearchAsync<Movie>("wonder",newSearchQuery{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"}

Search with Limit and Offset

You can paginate search results by making queries combining bothoffset andlimit.

varresults=awaitindex.SearchAsync<T>(query,newSearchQuery(){Limit=5,Offset=0});if(resultsisSearchResult<T>limitedResults){varestimatedTotalHits=limitedResults.EstimatedTotalHits;}

Search with defined number of results per page

To get paginated results with page numbers, theHitsPerPage andPage properties must be defined.

varresults=awaitindex.SearchAsync<T>(query,newSearchQuery(){HitsPerPage=pageSize,Page=pageNumber,});if(resultsisPaginatedSearchResult<T>paginatedResults){vartotalHits=paginatedResults.TotalHits;vartotalPages=paginatedResults.TotalPages;}

Search with sort

To get results sorted by attributes and preferred sorting order, theSort property must be defined.

varresults=awaitindex.SearchAsync<T>(query,newSearchQuery(){Sort=newList<string>{"genre:asc","name:desc"}});

🤖 Compatibility with Meilisearch

This package guarantees compatibility withversion v1.x of Meilisearch, but some features may not be present. Please check theissues for more info.

🎬 Examples

Indexes

Create an index

varindex=awaitclient.CreateIndexAsync("movies");

Create an index and give the primary-key

varindex=awaitclient.CreateIndexAsync("movies","id");

List all an index

varindexes=awaitclient.GetAllIndexesAsync();

Get an Index object

varindex=awaitclient.GetIndexAsync("movies");

Documents

Add or Update Documents

vartask=awaitindex.AddDocumentsAsync(newMovie[]{newMovie{Id="1",Title="Carol"}});vartask=awaitindex.UpdateDocumentsAsync(newMovie[]{newMovie{Id="1",Title="Carol"}});

The returnedtask is aTaskInfo that can access toUid to get the status of the task.

Get Documents

vardocuments=awaitindex.GetDocumentsAsync<Movie>(newDocumentsQuery{Limit=1});

Get Document by Id

vardocument=awaitindex.GetDocumentAsync<Movie>("10");

Delete documents

vartask=awaitindex.DeleteOneDocumentAsync("11");

Delete in Batch

vartask=awaitindex.DeleteDocumentsAsync(new[]{"12","13","14"});

Delete all documents

vartask=awaitindextoDelete.DeleteAllDocumentsAsync();

Get Task information

Get one Task By Uid

TaskInfotask=awaitindex.GetTaskAsync(1);// OrTaskInfotask=awaitclient.GetTaskAsync(1);

Get All Tasks

vartask=awaitindex.GetTasksAsync();// Orvartask=awaitclient.GetTasksAsync();

Search

Basic Search

varmovies=awaitthis.index.SearchAsync<Movie>("prince");

Custom Search

varmovies=awaitthis.index.SearchAsync<Movie>("prince",newSearchQuery{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>();varclient=newMeilisearchClient(_httpClient);

WhereClientFactory is declaredlike 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 ourcontributing guidelines for detailed instructions!


Meilisearch provides and maintains manySDKs and Integration tools like this one. We want to provide everyone with anamazing 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 theintegration-guides repository.

About

.NET wrapper for the Meilisearch API

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Contributors48

Languages


[8]ページ先頭

©2009-2025 Movatter.jp