<commit_before>using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Loggly.Config;
using Loggly.Responses;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Loggly
{
    internal class SearchTransport : ISearchTransport
    {
        private readonly ISearchConfiguration _config;
        private HttpClient _httpClient;

        public SearchTransport(ISearchConfiguration config)
        {
            _config = config;
            _httpClient=new HttpClient();
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                    "Basic",
                    Convert.ToBase64String(
                        Encoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", config.Username, config.Password))));
        }
        public SearchResponse Search(SearchQuery query)
        {
            var parameters = query.ToParameters();
            return Search<SearchResponse>("apiv2/search", parameters);
        }

        public SearchResponse<T> Search<T>(SearchQuery query)
        {
            var parameters = query.ToParameters();
            return Search<SearchResponse<T>>("apiv2/search", parameters);
        }

        public EntryJsonResponseBase Search(EventQuery query)
        {
            var parameters = query.ToParameters();
            return Search<EntryJsonResponse>("apiv2/events", parameters);
        }

        public FieldResponse Search(FieldQuery query)
        {
            var parameters = query.ToParameters();
            return Search<FieldResponse>("apiv2/fields", parameters);
        }

        private T Search<T>(string endPoint, IDictionary<string, object> parameters)
            where T : class
        {
            try
            {
                var searchPathAndQuery = GetUrl(endPoint, parameters);
                
                using (var response = _httpClient.GetAsync(searchPathAndQuery).Result)
                {
                    var isFieldResponseResultExpected = typeof(T) == typeof(FieldResponse);
                    var responseBody = response.Content.ReadAsStringAsync().Result;
                    if (response.IsSuccessStatusCode)
                    {
                        T responseObject = isFieldResponseResultExpected
                            ? new FieldResponse(JObject.Parse(responseBody), parameters["fieldname"].ToString()) as T
                            : JsonConvert.DeserializeObject<T>(responseBody);

                        var responseAsSearchResponseBase = responseObject as SearchResponseBase;
                        if (responseAsSearchResponseBase != null)
                        {
                            responseAsSearchResponseBase.Transport = this;
                        }

                        return responseObject;
                    }
                    LogglyException.Throw(responseBody);
                    return null;
                }

            }
            catch (Exception ex)
            {
                LogglyException.Throw(ex, ex.Message);
                return null;
            }
        }

        private string GetUrl(string endPoint, ICollection<KeyValuePair<string, object>> parameters)
        {
            var sb = new StringBuilder(100);
            sb.AppendFormat("https://{0}.loggly.com/", _config.Account);
            sb.Append(endPoint);

            if (parameters != null && parameters.Count > 0)
            {
                sb.Append('?');
                foreach (var kvp in parameters)
                {
                    if (kvp.Value == null)
                    {
                        continue;
                    }
                    sb.Append(kvp.Key);
                    sb.Append('=');
                    sb.Append(WebUtility.UrlEncode(kvp.Value.ToString()));
                    sb.Append("&");
                }
                sb.Remove(sb.Length - 1, 1);
            }

            return sb.ToString();
        }

    }
}<commit_msg>Add missing field name to search<commit_after>using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Loggly.Config;
using Loggly.Responses;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Loggly
{
    internal class SearchTransport : ISearchTransport
    {
        private readonly ISearchConfiguration _config;
        private HttpClient _httpClient;

        public SearchTransport(ISearchConfiguration config)
        {
            _config = config;
            _httpClient=new HttpClient();
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                    "Basic",
                    Convert.ToBase64String(
                        Encoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", config.Username, config.Password))));
        }
        public SearchResponse Search(SearchQuery query)
        {
            var parameters = query.ToParameters();
            return Search<SearchResponse>("apiv2/search", parameters);
        }

        public SearchResponse<T> Search<T>(SearchQuery query)
        {
            var parameters = query.ToParameters();
            return Search<SearchResponse<T>>("apiv2/search", parameters);
        }

        public EntryJsonResponseBase Search(EventQuery query)
        {
            var parameters = query.ToParameters();
            return Search<EntryJsonResponse>("apiv2/events", parameters);
        }

        public FieldResponse Search(FieldQuery query)
        {
            var parameters = query.ToParameters();
            return Search<FieldResponse>($"apiv2/fields/{query.FieldName}/", parameters);
        }

        private T Search<T>(string endPoint, IDictionary<string, object> parameters)
            where T : class
        {
            try
            {
                var searchPathAndQuery = GetUrl(endPoint, parameters);
                
                using (var response = _httpClient.GetAsync(searchPathAndQuery).Result)
                {
                    var isFieldResponseResultExpected = typeof(T) == typeof(FieldResponse);
                    var responseBody = response.Content.ReadAsStringAsync().Result;
                    if (response.IsSuccessStatusCode)
                    {
                        T responseObject = isFieldResponseResultExpected
                            ? new FieldResponse(JObject.Parse(responseBody), parameters["fieldname"].ToString()) as T
                            : JsonConvert.DeserializeObject<T>(responseBody);

                        var responseAsSearchResponseBase = responseObject as SearchResponseBase;
                        if (responseAsSearchResponseBase != null)
                        {
                            responseAsSearchResponseBase.Transport = this;
                        }

                        return responseObject;
                    }
                    LogglyException.Throw(responseBody);
                    return null;
                }

            }
            catch (Exception ex)
            {
                LogglyException.Throw(ex, ex.Message);
                return null;
            }
        }

        private string GetUrl(string endPoint, ICollection<KeyValuePair<string, object>> parameters)
        {
            var sb = new StringBuilder(100);
            sb.AppendFormat("https://{0}.loggly.com/", _config.Account);
            sb.Append(endPoint);

            if (parameters != null && parameters.Count > 0)
            {
                sb.Append('?');
                foreach (var kvp in parameters)
                {
                    if (kvp.Value == null)
                    {
                        continue;
                    }
                    sb.Append(kvp.Key);
                    sb.Append('=');
                    sb.Append(WebUtility.UrlEncode(kvp.Value.ToString()));
                    sb.Append("&");
                }
                sb.Remove(sb.Length - 1, 1);
            }

            return sb.ToString();
        }

    }
}
{'fraction_non_alphanumeric': 0.08677635588056064, 'fraction_numerical': 0.003656307129798903, 'mean_word_length': 1.5071799572257867, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3006898', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1827, 'n_words': 377}