Пример #1
0
 /// <summary>
 /// Try to get an index instance, create it if it does not exist and return it
 /// </summary>
 public async Task <MeilisearchDotnet.Index> GetOrCreateIndex(MeilisearchDotnet.Types.IndexRequest data)
 {
     try
     {
         return(await GetIndex(data.Uid));
     }
     catch (MeilisearchDotnet.Exceptions.NotFoundException e)
     {
         return(await CreateIndex(data));
     }
 }
Пример #2
0
        /// <summary>
        /// Create a new index
        /// </summary>
        public async Task <Index> CreateIndex(MeilisearchDotnet.Types.IndexRequest data)
        {
            string        url        = "/indexes";
            string        dataString = JsonSerializer.Serialize(data);
            StringContent payload    = new StringContent(dataString, Encoding.UTF8, "application/json");

            MeilisearchDotnet.Types.IndexResponse indexResponse = await Post <MeilisearchDotnet.Types.IndexResponse>(url, payload);

            MeilisearchDotnet.Index index = new Index(HttpClient, indexResponse.Uid);

            Indexes.Add(index.Uid, index);
            return(index);
        }