Ejemplo n.º 1
0
        private static Task <IEnumerable <Tweet> > SearchTweetsAsync(ElasticConnection connection, JsonNetSerializer serializer)
        {
            string searchCommand = Commands.Search("twitter", "tweet").Pretty();

            string query = new QueryBuilder <Tweet>()
                           .Query(qry => qry
                                  .Term(term => term
                                        .Field(tweet => tweet.User)
                                        .Value("testUser".ToLower()) // by default terms query requires lowercased values.
                                        .Boost(5)
                                        )
                                  ).BuildBeautified();


            return(connection.PostAsync(searchCommand, query)
                   // process search results asynchronously
                   .ContinueWith(searchTask => {
                OperationResult results = searchTask.Result;
                var searchResult = serializer.ToSearchResult <Tweet>(results);

                Console.WriteLine("ASYNC Search Results: \r\n");
                PrintSearchResults(searchResult, searchCommand, query, results);

                return searchResult.Documents;
            }));
        }