public void TestInitialize()
 {
     _testApiKey = Environment.GetEnvironmentVariable("ALGOLIA_API_KEY");
     _testApplicationID = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID");
     _client = new AlgoliaClient(_testApplicationID, _testApiKey);
     _index = _client.InitIndex(safe_name("àlgol?à-csharp"));
 }
Exemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;

            algoliaClient = new AlgoliaClient("<APPLICATION_ID>", "<SEARCH_ONLY_API_KEY>");
            algoliaIndex = algoliaClient.InitIndex("packages");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Indexes all objects using a temporary index that is then atomically moved to the destination index.
        /// All previous content will be overwritten. You must supply all objects to this method that need to
        /// exist within the index.
        /// </summary>
        /// <param name="objects">An enumerable list of objects to override the index with.</param>
        /// <param name="maxObjectsPerCall">Maximum number of objects per indexing call. Should be between 1,000 and 10,000 depending on size of objects.</param>
        async public Task <JObject> OverwriteIndexAsync(IEnumerable <T> objects, int maxObjectsPerCall = 1000)
        {
            // Build list for Tasks
            var taskList = new List <Task <JObject> >();

            //Index names
            var tempIndexName = _indexName + "_temp";

            // Use the temp index
            var tempIndex = _client.InitIndex(tempIndexName);

            // Setup array to store objects to index
            var toIndex = new List <JObject>();

            // Process each object
            foreach (var obj in objects)
            {
                // Convert obj to a JObject
                var jObject = JObject.FromObject(obj);

                // Get value used for objectID
                var id = jObject.GetValue(_objectIdField).ToString();

                // Override Algolia object ID with the object Id
                jObject.Add("objectID", id);

                // Save object for indexing
                toIndex.Add(jObject);

                // See if we have reached our limit
                if (toIndex.Count >= maxObjectsPerCall)
                {
                    // Add or update indices
                    taskList.Add(tempIndex.SaveObjectsAsync(toIndex));

                    // Reset array
                    toIndex.Clear();
                }
            }

            // Add or update indices for last batch
            if (toIndex.Count > 0)
            {
                taskList.Add(tempIndex.SaveObjectsAsync(toIndex));
            }

            // Wait for all tasks to be done
            Task.WaitAll(taskList.ToArray());

            // Overwrite main index with temp index
            return(await _client.MoveIndexAsync(tempIndexName, _indexName));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Check to see if the asynchronous server task is complete.
 /// </summary>
 /// <param name="indexName">The index associated with the task.</param>
 /// <param name="taskID">The id of the task returned by server.</param>
 /// <param name="requestOptions"></param>
 /// <param name="timeToWait"></param>
 /// <param name="token"></param>
 async public Task WaitTaskAsync(string indexName, string taskID, RequestOptions requestOptions = null, int timeToWait = 100, CancellationToken token = default(CancellationToken))
 {
     await _client.InitIndex(indexName).WaitTaskAsync(taskID, requestOptions, timeToWait, token);
 }
 public void TestClientWithMock()
 {
     var client = new AlgoliaClient("test", "test", null, getEmptyHandler());
     Assert.AreEqual(JObject.Parse("{\"items\":[]}").ToString(), client.ListIndexes().ToString());
     Assert.AreEqual(JObject.Parse("{\"results\":[]}").ToString(), client.InitIndex("{indexName}").GetObjects(new string[] { "myID" }).ToString());
 }