Seredenko-V

FOR_EACH Parallel MatchDocument

Aug 2nd, 2022 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. tuple<vector<string>, DocumentStatus> SearchServer::MatchDocument(execution::parallel_policy policy,
  2.     const string& raw_query, int document_id) const {
  3.     if (!IsValidWord(raw_query)) {
  4.         throw invalid_argument("Некорректный поисковый запрос.");
  5.     }
  6.     if (document_id < 0) {
  7.         throw out_of_range("Документа с указанным id не существует.");
  8.     }
  9.     const Query query = ParseQuery(raw_query);
  10.     vector<string> matched_words;
  11.  
  12.     for_each(policy, query.plus_words.begin(), query.plus_words.end(),
  13.         [this, &matched_words, document_id](const string& plus_word) {
  14.             if (word_frequencies_in_document_.at(document_id).count(plus_word)) {
  15.                 matched_words.push_back(plus_word);
  16.             }
  17.         });
  18.  
  19.     for_each(policy, query.minus_words.begin(), query.minus_words.end(),
  20.         [this, &matched_words, document_id](const string& minus_word) {
  21.             if (word_frequencies_in_document_.at(document_id).count(minus_word)) {
  22.                 matched_words.clear();
  23.             }
  24.         });
  25.  
  26.  
  27.     return { matched_words, documents_.at(document_id).status };
  28. }
Advertisement
Add Comment
Please, Sign In to add comment