Beispiel #1
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);
        }
Beispiel #2
0
        /// <summary>
        /// Return an Index instance
        /// </summary>
        public async Task <MeilisearchDotnet.Index> GetIndex(string indexUid)
        {
            if (Indexes.TryGetValue(indexUid, out MeilisearchDotnet.Index index))
            {
                return(index);
            }
            else
            {
                try
                {
                    string url = "/indexes/" + indexUid;
                    MeilisearchDotnet.Types.IndexResponse indexResponses = await Get <MeilisearchDotnet.Types.IndexResponse>(url);

                    index = new Index(HttpClient, indexUid);
                    Indexes.Add(indexUid, index);
                    return(index);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }