public async Task <IEnumerable <SearchResult> > HashedSearch(HashedSearchQuery query) { var client = new RestClient(_aggregatorUrl); var request = new RestRequest(_paths["search"]); request.AddJsonBody(query); request.Method = Method.POST; var response = await client.ExecuteAsync <IEnumerable <SearchResult> >(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(response.Data); } else { if (response.ErrorException != null) { throw response.ErrorException; } else { throw new Exception(response.StatusDescription); } } }
public List <SearchResult> Search(HashedSearchQuery search) { var minHasher = new MinHasher <Guid>(_db.LSHConfig.LSHHashSeed); var lshSearcher = new LSHSearch <Guid>(minHasher, SimilarityMeasures.Jaccard); var searchSpace = _db.HashedProducts .ToDictionary(p => p.Id, p => (IWeightedHashed)p); var res = lshSearcher.GetClosest(searchSpace, search.SearchTerm, search.MaxResults, search.MinimumSimilarity); var results = res.Select(r => new SearchResult { Product = new ProductBase() { Id = r.Id }, Similarity = r.Similarity, Store = _db.HashedProducts .Include(p => p.Store) .FirstOrDefault(p => p.Id == r.Id).Store } ).ToList(); return(results); }