private static void PushToSource(List <PushDocument> documents) { string apiKey = "xxf658e848-24d4-4424-8830-edb1b82637da"; string organizationId = "coveopokemonchallengepcm0rz3k"; string sourceId = "coveopokemonchallengepcm0rz3k-steno3qxuvfyenkroqzvxikot4"; //string apiKey = "xxfe408680-a663-41f1-a351-e5ec3e8d09ba"; //string organizationId = "coveopokemonchallengepcm0rz3k"; //string sourceId = "coveopokemonchallengepcm0rz3k-vs73qz3k5fu432ktvy7a65knxm"; ICoveoPlatformConfig config = new CoveoPlatformConfig(apiKey, organizationId); ICoveoPlatformClient client = new CoveoPlatformClient(config); client.DocumentManager.AddOrUpdateDocuments(sourceId, documents, null); }
/// <summary> /// Indexes the files located in the specified folder. /// </summary> /// <param name="p_Args">Parsed command-line arguments.</param> private static void IndexFiles(ProgramArguments p_Args) { string folder = Path.GetFullPath(p_Args.folder); if (!folder.EndsWith(Path.DirectorySeparatorChar)) { folder += Path.DirectorySeparatorChar; } Console.WriteLine($"Pushing files \"{p_Args.include}\" from folder \"{folder}\"..."); ulong orderingId = RequestOrderingUtilities.CreateOrderingId(); ICoveoPlatformConfig platformConfig = new CoveoPlatformConfig(GetPushApiUrl(p_Args), GetPlatformApiUrl(p_Args), p_Args.apikey, p_Args.organizationid); using (ICoveoPlatformClient platformClient = new CoveoPlatformClient(platformConfig)) { IList <PushDocument> documentBatch = new List <PushDocument>(); foreach (FileInfo fileInfo in new DirectoryInfo(folder).EnumerateFiles(p_Args.include, p_Args.recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { if (!fileInfo.FullName.StartsWith(folder)) { throw new Exception("Unexpected file gathered from outside the source folder."); } Console.WriteLine(fileInfo.FullName.Substring(folder.Length)); PushDocument document = new PushDocument(new Uri(fileInfo.FullName).AbsoluteUri) { ModifiedDate = fileInfo.LastWriteTimeUtc }; document.AddMetadata("title", fileInfo.Name); document.AddMetadata("fileextension", fileInfo.Extension); if (fileInfo.Length > 0) { PushDocumentHelper.SetBinaryContentFromFileAndCompress(document, fileInfo.FullName); } documentBatch.Add(document); if (documentBatch.Count >= p_Args.batchSize) { // Push this batch of documents. SendBatch(platformClient, documentBatch, p_Args.sourceid, orderingId); } } // Send the (partial) final batch of documents. SendBatch(platformClient, documentBatch, p_Args.sourceid, orderingId); // Delete the already indexed files that no longer exist. platformClient.DocumentManager.DeleteDocumentsOlderThan(p_Args.sourceid, orderingId, null); } }