Exemple #1
0
 public GlobalTests()
 {
     ms    = new Meilisearch("http://localhost:7700", "masterKey");
     index = ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest
     {
         Uid        = Uid,
         PrimaryKey = PrimaryKey
     }).Result;
 }
Exemple #2
0
 public SearchWithParamTests()
 {
     ms    = new Meilisearch("http://localhost:7700", "masterKey");
     index = ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest
     {
         Uid        = "search_with_param_tests",
         PrimaryKey = "Id"
     }).Result;
     MeilisearchDotnet.Types.EnqueuedUpdate e = index.AddDocuments(docs).Result;
     MeilisearchDotnet.Types.Update         u = index.WaitForPendingUpdate(e.UpdateId).Result;
 }
        static async Task Main(string[] args)
        {
            await Task.Delay(3000);

            Meilisearch ms = new Meilisearch("http://meili:7700", "masterKey");

            MeilisearchDotnet.Index index = await ms.GetOrCreateIndex(new MeilisearchDotnet.Types.IndexRequest
            {
                Uid        = "city",
                PrimaryKey = "code"
            });

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("https://geo.api.gouv.fr");
            client.DefaultRequestHeaders.Add("accept", "application/json");

            HttpResponseMessage res = await client.GetAsync("/departements?fields=code");

            List <Region> departements = await res.Content.ReadAsAsync <List <Region> >();

            while (true)
            {
                int n = 0;
                for (int d = 0; d < departements.Count; d++)
                {
                    res = await client.GetAsync("/departements/" + departements[d].code + "/communes?fields=nom,code,codesPostaux&format=json&geometry=centre");

                    List <City> cities = await res.Content.ReadAsAsync <List <City> >();

                    Console.WriteLine(string.Format("Found {0} cities for region ({1}), start adding documents", cities.Count, departements[d].code));
                    int i = 0;
                    MeilisearchDotnet.Types.EnqueuedUpdate q;
                    for (; i + 5000 < cities.Count; i += 5000)
                    {
                        Console.WriteLine(string.Format("Adding 1000 cities [\"{0}\" .. \"{1}\"]", cities[i].nom, cities[i + 4999].nom));
                        q = await index.AddDocuments <City>(cities.GetRange(i, i + 4999));

                        await index.WaitForPendingUpdate(q.UpdateId, 30000);

                        n += 5000;
                    }
                    Console.WriteLine(string.Format("Adding {2} cities [\"{0}\" .. \"{1}\"]", cities[i].nom, cities[cities.Count - 1].nom, cities.Count - i));
                    q = await index.AddDocuments <City>(cities.GetRange(i, cities.Count - 1));

                    await index.WaitForPendingUpdate(q.UpdateId, 30000);

                    n += cities.Count - i;
                }
                Console.WriteLine(string.Format("{0} documents added, waiting 300 seconds ...", n));
                await Task.Delay(300000);
            }
        }
Exemple #4
0
        public async Task <object> GetNumberOfDoc()
        {
            Meilisearch ms = new Meilisearch(_config["MeilisearchEndpoint"], _config["MeilisearchMasterKey"]);

            MeilisearchDotnet.Index index = await ms.GetOrCreateIndex(new MeilisearchDotnet.Types.IndexRequest {
                Uid = "city"
            });

            MeilisearchDotnet.Types.IndexStats stats = await index.GetStats();

            return(new { numberOfDocuments = stats.NumberOfDocuments });
        }
Exemple #5
0
 public DeleteDocumentsTests()
 {
     if (index == null)
     {
         ms    = new Meilisearch("http://localhost:7700", "masterKey");
         index = ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest
         {
             Uid        = "delete_document_tests",
             PrimaryKey = "Id"
         }).Result;
         MeilisearchDotnet.Types.EnqueuedUpdate e = index.AddDocuments(docs).Result;
         MeilisearchDotnet.Types.Update         u = index.WaitForPendingUpdate(e.UpdateId).Result;
     }
 }
        public async void CreateIndex()
        {
            string uid = "kero";

            MeilisearchDotnet.Index index = await ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest
            {
                Uid = uid
            });

            Assert.Equal(uid, index.Uid);
            await Assert.ThrowsAsync <MeilisearchDotnet.Exceptions.BadRequestException>(async() => await ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest
            {
                Uid = uid
            }));

            await ms.DeleteIndex(uid);
        }
        public async void GetOrCreateIndex()
        {
            string uid = "lalalalalalalalalala";

            MeilisearchDotnet.Index index1 = await ms.GetOrCreateIndex(new MeilisearchDotnet.Types.IndexRequest
            {
                Uid = uid
            });

            MeilisearchDotnet.Index index2 = await ms.GetOrCreateIndex(new MeilisearchDotnet.Types.IndexRequest
            {
                Uid = uid
            });

            Assert.Equal(uid, index1.Uid);
            Assert.Equal(uid, index2.Uid);
            Assert.Same(index1, index2);
            await ms.DeleteIndex(uid);
        }
        public async void GetIndexesList()
        {
            int n = 3;
            int i = 0;

            for (; i < n; i++)
            {
                MeilisearchDotnet.Index index = await ms.CreateIndex(new MeilisearchDotnet.Types.IndexRequest {
                    Uid = i.ToString()
                });

                Assert.NotNull(index);
                Assert.Equal(index.Uid, i.ToString());
            }
            IEnumerable <MeilisearchDotnet.Types.IndexResponse> responses = await ms.ListIndexes();

            Assert.Equal(n, ms.Indexes.Keys.Count());
            Assert.Equal(n, responses.Count());
            i = 0;
            for (; i < n; i++)
            {
                await ms.DeleteIndex(i.ToString());
            }
        }