- 安装
MeiliSearch 0.15.5 0.15.5
- demo code
using Meilisearch;
using System.Data;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace MeiliSearchAPI
{
public class MeilisearchHelper
{
public MeilisearchHelper()
{
DefaultClient = new MeilisearchClient(MeilisearchAddress(), ApiKey);
var httpClient = new HttpClient(new MeilisearchMessageHandler(new HttpClientHandler())) {
BaseAddress = new Uri(MeilisearchAddress()) };
ClientWithCustomHttpClient = new MeilisearchClient(httpClient, ApiKey);
}
private const string ApiKey = "ellisniubitesthahaha";
private static readonly string BasePath = Path.Combine(Directory.GetCurrentDirectory(), "Datasets");
public static readonly string SmallMoviesJsonPath = Path.Combine(BasePath, "small_movies.json");
public virtual string MeilisearchAddress()
{
return "http://192.168.214.133:31170";
}
public MeilisearchClient DefaultClient {
get; private set; }
public MeilisearchClient ClientWithCustomHttpClient {
get; private set; }
public async Task InitIndexWithValue(string indexName)
{
var index = DefaultClient.Index(indexName);
var jsonDocuments = await File.ReadAllTextAsync(SmallMoviesJsonPath);
var task = await index.AddDocumentsJsonAsync(jsonDocuments);
await index.WaitForTaskAsync(task.TaskUid);