public static async Task <string> CosmosSearch([ActivityTrigger] string request, [CosmosDB(
                                                                                              ConnectionStringSetting = "CosmosDbConnection")] DocumentClient client, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");
            Model.RootObject requestData = JsonConvert.DeserializeObject <Model.RootObject>(request);

            Uri collectionUri = UriFactory.CreateDocumentCollectionUri(databaseId: "entities", collectionId: "func");
            var options       = new FeedOptions {
                EnableCrossPartitionQuery = true
            };                                                                  // Enable cross partition query

            List <KeyValuePair <string, int> > hits = new List <KeyValuePair <string, int> >();

            foreach (var item in requestData.documents[0].keyPhrases)
            {
                IDocumentQuery <document> query = client.CreateDocumentQuery <document>(collectionUri, options)
                                                  .Where(document => document.KeyPhrase == item.ToLowerInvariant())
                                                  .AsDocumentQuery();

                List <dynamic> documents = new List <dynamic>();

                while (query.HasMoreResults)
                {
                    foreach (var queryItem in await query.ExecuteNextAsync())
                    {
                        documents.Add(queryItem);
                    }
                }

                hits.Add(new KeyValuePair <string, int>(item.ToLowerInvariant(), documents.Count));
            }

            return(JsonConvert.SerializeObject(hits));
        }
        public static async Task <string> GetTwitter([ActivityTrigger] string request,
                                                     ILogger log)
        {
            client = new RestSharp.RestClient("https://we-factsearch-fa.azurewebsites.net");

            RestSharp.RestRequest restRequest = new RestSharp.RestRequest("/api/SearchTwitter", RestSharp.Method.POST);

            restRequest.AddHeader("Content-Type", "application/json");
            Model.RootObject requestData = JsonConvert.DeserializeObject <Model.RootObject>(request);

            string query = string.Empty;

            foreach (var item in requestData.documents[0].keyPhrases)
            {
                query += item + " ";
            }

            Model.SearchQuery searchQuery = new Model.SearchQuery()
            {
                query = query
            };

            restRequest.AddJsonBody(searchQuery);

            var response = await client.ExecuteAsync(restRequest).ConfigureAwait(false);

            return(response.Content);
        }
        public static async Task CosmosOutput([ActivityTrigger] string request, [CosmosDB(
                                                                                     databaseName: "entities",
                                                                                     collectionName: "func",
                                                                                     ConnectionStringSetting = "CosmosDbConnection")] IAsyncCollector <document> documents, ILogger log)
        {
            Model.RootObject requestData = JsonConvert.DeserializeObject <Model.RootObject>(request);
            string           time        = DateTime.UtcNow.ToString();

            foreach (var item in requestData.documents[0].keyPhrases)
            {
                await documents.AddAsync(new document { DataTime = time, KeyPhrase = item.ToLowerInvariant() });
            }

            log.LogInformation($"C# Queue trigger function inserted one row");
        }