Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tuple<vector<string>, DocumentStatus> SearchServer::MatchDocument(execution::parallel_policy policy,
- const string& raw_query, int document_id) const {
- if (!IsValidWord(raw_query)) {
- throw invalid_argument("Некорректный поисковый запрос.");
- }
- if (document_id < 0) {
- throw out_of_range("Документа с указанным id не существует.");
- }
- const Query query = ParseQuery(raw_query);
- vector<string> matched_words;
- for_each(policy, query.plus_words.begin(), query.plus_words.end(),
- [this, &matched_words, document_id](const string& plus_word) {
- if (word_frequencies_in_document_.at(document_id).count(plus_word)) {
- matched_words.push_back(plus_word);
- }
- });
- for_each(policy, query.minus_words.begin(), query.minus_words.end(),
- [this, &matched_words, document_id](const string& minus_word) {
- if (word_frequencies_in_document_.at(document_id).count(minus_word)) {
- matched_words.clear();
- }
- });
- return { matched_words, documents_.at(document_id).status };
- }
Advertisement
Add Comment
Please, Sign In to add comment