/// <summary> /// Search ElasticSearch for containting the given search term. /// </summary> /// <param name="query">The search query.</param> /// <param name="sort">The sort selector.</param> /// <param name="pageNumber">The starting page number of the search results from which to take.</param> /// <param name="pageSize">The number of items to take.</param> protected virtual async Task <SearchResultsDto <T> > Search( Func <QueryContainerDescriptor <T>, QueryContainer> query, Func <SortDescriptor <T>, IPromise <IList <ISort> > > sort, int?pageNumber, int?pageSize) { var searchResults = await _client.SearchAsync <T>(s => s .Query(query) .Sort(sort) .From((pageNumber.Value - 1) * pageSize.Value).Take(pageSize.Value) ); if (!searchResults.IsValid) { throw new Exception($"Unable to execute search due to errors in query: {JsonConvert.SerializeObject(searchResults.ServerError)}"); } var resultsDto = new SearchResultsDto <T> { Docs = searchResults.Documents.ToList(), TotalCount = await GetTotalCount(practiceId), FilteredCount = searchResults.HitsMetaData.Total }; return(resultsDto); }
public SearchResultsDto GetSearchResultsDetails(string searchString) { var details = new SearchResultsDto(); details.SearchString = searchString; details.SearchPosts = GetSearchResult(searchString); details.Subcategories = details.SearchPosts.Select(x => x.Subcategory).Distinct().ToList(); return(details); }
private void StoreSearchResults(SearchParametersDto parameters, List <ProteinDto> candidateProteins, ExecutionTimeDto executionTimes, int fileNumber) { if (candidateProteins.Count > Constants.NumberOfResultsToStore) { candidateProteins = candidateProteins.Take(Constants.NumberOfResultsToStore).ToList <ProteinDto>(); } var final = new SearchResultsDto(parameters.Queryid, candidateProteins, executionTimes); _dataLayer.StoreResults(final, parameters.PeakListFileName[fileNumber], fileNumber); }
private ExecutionTime GetExecutionTimeModel(SearchResultsDto res, string fileName) { var executionTime = new ExecutionTime { QueryId = res.QueryId, FileName = fileName, InsilicoTime = res.Times.InsilicoTime, MwFilterTime = res.Times.MwFilterTime, PstTime = res.Times.PstTime, PtmTime = res.Times.PtmTime, TotalTime = res.Times.TotalTime, TunerTime = res.Times.TunerTime }; return(executionTime); }
//public string GetEmailFromUserId(string id) //{ // string email; // using (var db = new PerceptronContext()) // { // var query = from b in db.SearchQueryTable // where b.UserId == id // select b.Email; // email = query.Any() ? query.First() : Constants.EmailNotFound; // } // return email; //} public string StoreResults(SearchResultsDto res, string fileName, int fileId) { string message = Constants.ResultsSotredSuccessfully; //Spelling mistake?#PROBLEM_DETECTED using (var db = new PerceptronDatabaseEntities()) { var executionTime = GetExecutionTimeModel(res, fileName); db.ExecutionTimes.Add(executionTime); //db.SaveChanges(); foreach (ProteinDto protein in res.FinalProt) { var resId = Guid.NewGuid(); var headerTag = GetHeaderTag(protein.Header); var searchResult = GetSearchResultModel(res.QueryId, fileId, headerTag, protein, resId); db.SearchResults.Add(searchResult); //db.SaveChanges(); if (protein.PtmParticulars == null) { continue; } foreach (var ptmSite in protein.PtmParticulars) { var resultPtmSites = GetResultPtmSitesModel(resId, ptmSite); db.ResultPtmSites.Add(resultPtmSites); //db.SaveChanges(); } var resultInsilicoMatchLeft = GetResultInsilicoMatchLeftModel(resId, protein.InsilicoDetails.PeaklistMassLeft); db.ResultInsilicoMatchLefts.Add(resultInsilicoMatchLeft); //db.SaveChanges(); var resultInsilicoMatchRight = GetResultInsilicoMatchLeftModel(resId, protein.InsilicoDetails.PeaklistMassRight); db.ResultInsilicoMatchLefts.Add(resultInsilicoMatchRight); //#PROBLEM_DETECTED??? Why this-->ResultInsilicoMatchLeftTable WHy not ResultInsilicoMatchRights //db.SaveChanges(); } db.SaveChanges(); } return(message); }
//Store results public string StoreResults(SearchResultsDto res, string abcd, int fileId) { var resultString = "You are Registered!"; if (OpenConnection()) { var query0 = "INSERT INTO timings VALUES('" + res.QueryId + "','" + res.Times.InsilicoTime + "','" + res.Times.PtmTime + "','" + res.Times.TunerTime + "','" + res.Times.MwFilterTime + "','" + res.Times.PstTime + "','" + res.Times.TotalTime + "','" + abcd + "');"; var cmd1 = new MySqlCommand(query0, _connection); try { cmd1.ExecuteNonQuery(); foreach (ProteinDto protein in res.FinalProt) { var resId = Guid.NewGuid(); string headerTag; if (protein.Header[0] == '>') { headerTag = protein.Header.Contains('|') ? protein.Header.Substring(4, 6) : protein.Header.Substring(1, protein.Header.Length - 1); } else { headerTag = protein.Header; } var query = "INSERT INTO results VALUES('" + resId + "','" + res.QueryId + "','" + headerTag + "','" + protein.Sequence + "'," + protein.PstScore + "," + protein.InsilicoScore + "," + protein.PtmScore + "," + protein.Score + "," + protein.MwScore + "," + protein.Mw + "," + fileId + ")"; var cmd = new MySqlCommand(query, _connection); cmd.ExecuteNonQuery(); MySqlCommand cmd2; var temp = ""; string query3; if (protein.PtmParticulars != null) { foreach (var ptmSite in protein.PtmParticulars) { temp = ptmSite.AminoAcid.Aggregate(temp, (current, t) => current + t); query3 = "INSERT INTO ptm_sites VALUES('" + resId + "'," + ptmSite.Index + "," + ptmSite.Score + "," + ptmSite.ModWeight + ",'" + ptmSite.ModName + "','" + ptmSite.Site + "','" + temp + "');"; //string query2 = "update logindata set guid ='" + g + "'where id ='" + id + "';"; cmd2 = new MySqlCommand(query3, _connection); cmd2.ExecuteNonQuery(); } } ////////////////////////////////////// var matchLeft = String.Join(",", protein.InsilicoDetails.PeaklistMassLeft.Select( x => x.ToString(CultureInfo.InvariantCulture)).ToArray()); query3 = "INSERT INTO insilico_matches_left VALUES ('" + resId + "','" + matchLeft + "')"; cmd2 = new MySqlCommand(query3, _connection); cmd2.ExecuteNonQuery(); var matchRight = String.Join(",", protein.InsilicoDetails.PeaklistMassRight.Select( x => x.ToString(CultureInfo.InvariantCulture)).ToArray()); query3 = "INSERT INTO insilico_matches_right VALUES ('" + resId + "','" + matchRight + "')"; cmd2 = new MySqlCommand(query3, _connection); cmd2.ExecuteNonQuery(); } } catch (MySqlException e) { resultString = e.Message; } CloseConnection(); } else { resultString = "Unfortunatenly you can not register."; } return(resultString); }
/// <summary> /// /// </summary> /// <param name="userSessionId"></param> /// <param name="searchText"></param> /// <returns></returns> /// <remarks> /// I should update parameter for GetSessionDetailByUserSessionId to be a string and decouple dependency from MongoDb ObjectId Model /// I should also create my own "OcrResult" to decouple dependency from Microsoft Azure Models /// </remarks> public async Task <SearchResultsDto> SearchUserSession(string userSessionId, string searchText) { var result = new SearchResultsDto(); var sessionDetailsFound = await _sessionDetailRepo.GetSessionDetailByUserSessionId(ObjectId.Parse(userSessionId)).ConfigureAwait(false); //var rawText = String.Empty; try { var detail = sessionDetailsFound.PrintedTextResult; var regions = detail.Regions; foreach (OcrRegion region in regions) { var lines = region.Lines; foreach (OcrLine line in lines) { var words = line.Words; foreach (OcrWord word in words) { if (word.Text.ToLower().Contains(searchText.ToLower())) //Searh for match { //find how many regions to exclude var regionFoundIndex = regions.IndexOf(region); var skipLastCount = regions.Count - regionFoundIndex; if (skipLastCount < 0) { skipLastCount = 0; } //find haw many lines of text there are to find the word var reg = regions.SkipLast(skipLastCount); var linesInPriorRegions = 0; if (reg.Any()) { linesInPriorRegions = reg.Sum(x => x.Lines.Count()); } var lineNumber = linesInPriorRegions + region.Lines.IndexOf(line) + 1; //find how many words to exclude var wordsFoundIndex = words.IndexOf(word); var skipLastWordCount = words.Count - wordsFoundIndex; if (skipLastWordCount < 0) { skipLastWordCount = 0; } //find how many characters to find the word in the line var filteredWords = words.SkipLast(skipLastWordCount); var charInPriorWords = 0; if (filteredWords.Any()) { charInPriorWords = filteredWords.Sum(w => w.Text.Length); } var intPosition = charInPriorWords + filteredWords.Count(); //count number of words and spaces. will not include special characters. //Map from Ocr classes to custom classes (to reduce dependency on Ocr classes var resultText = new SearchResultText() { BoundingBox = word.BoundingBox, Text = word.Text }; var resultLine = new SearchResultLine() { BoundingBox = line.BoundingBox, Text = words.Select(w => new SearchResultText() { BoundingBox = w.BoundingBox, Text = w.Text }).ToList() }; var resultRegion = new SearchResultRegion() { BoundingBox = region.BoundingBox, Lines = new List <SearchResultLine>() { resultLine } }; var resultDetail = new SearchResultDetail() { Language = detail.Language, TextAngle = detail.TextAngle, Orientation = detail.Orientation, Regions = new List <SearchResultRegion>() { resultRegion } }; //build result details var resultDetails = new SearchResultDetails(resultText, resultLine, resultRegion, resultDetail, lineNumber, intPosition); //add to results result.ResultDetails.Add(resultDetails); } } } } } finally { if (sessionDetailsFound != null) { sessionDetailsFound = null; } } return(result); }