using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EchoNest.Artist; using Elasticsearch.Net; using MoreLinq; using Nest; using Sony.Filtr.Utility.Extensions; namespace Sony.Filtr.PlaylistGeneration.Autocomplete { //public class ElasticSearchAutocompleteFactory : IAutocompleteFactory //{ // public void IndexArtistAsync(string artistName) // { // return; // } // public async Task IndexArtists(IEnumerable artistAutocompleteEntries) // { // var client = GetElasticClient(); // await SetupIndexAsync(); // await artistAutocompleteEntries.Batch(2000).ForEachAsync(4, async artistsBatch => // { // await client.IndexManyAsync(artistsBatch); // }); // } // private async Task SetupIndexAsync() // { // var client = GetElasticClient(); // var deleteResponse = await client.DeleteIndexAsync("filtr-autocomplete", descriptor => descriptor); // var createIndexRequest = new CreateIndexRequest("filtr-autocomplete"); // createIndexRequest.IndexSettings = new IndexSettings() // { // Analysis = new AnalysisSettings() // { // Analyzers = new Dictionary() // { // { // "MyAnalyzer", new CustomAnalyzer() // { // Tokenizer = "standard", // Filter = new List() { "standard", "lowercase" }, // //CharFilter = new List() { }, // } // } // }, // } // }; // var indexResponse = await client.CreateIndexAsync(createIndexRequest); // await client.MapAsync( // map => // map.SearchAnalyzer("MyAnalyzer") // .IndexAnalyzer("MyAnalyzer")); // } // private static ElasticClient GetElasticClient() // { // var node = new Uri("http://ipv4.fiddler:9200"); // var settings = new ConnectionSettings( // node, // defaultIndex: "filtr-autocomplete" // ); // settings.DisableAutomaticProxyDetection(false); // var client = new ElasticClient(settings); // return client; // } // public IEnumerable SearchArtists(string search, int count) // { // var result = // GetElasticClient() // .Search( // s => s.Query(q=> // q.FunctionScore(descriptor => // descriptor. // Functions(fu=> fu.FieldValueFactor(a=> a.Field(ai=> ai.Familiarity).Factor(1)))) // && ( // q.Match(m=> m.Query(search + "*").Fuzziness(1).Boost(2).OnField(k=> k.Name)) // || q.Match(m=> m.Query(search).Fuzziness(1).OnField(k=> k.Name)) // || q.Match(m => m.Query(search).Fuzziness(1).OnField(k => k.Aliases)) // ) // )); // return result.Hits.Select(t => new ArtistAutocompleteResult() // { // Name = t.Source.Name, // Score = t.Score, // }); // } //} }