Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[nodiscard]] SearchServer::Query SearchServer::ParseQuery(string_view text) const {
- Query query;
- for (const auto &word: SplitIntoWords(text)) {
- const auto query_word = ParseQueryWord(string(word));
- if (!query_word.is_stop) {
- if (query_word.is_minus) {
- query.minus_words.insert(query_word.data);
- } else {
- query.plus_words.insert(query_word.data);
- }
- }
- }
- return query;
- }
- [[nodiscard]] SearchServer::QueryWord SearchServer::ParseQueryWord(string_view word) const {
- bool is_minus = false;
- // Word shouldn't be empty
- if (word[0] == '-') {
- is_minus = true;
- word = word.substr(1);
- }
- if (word.empty() || !IsValidWord(word)) {
- throw invalid_argument("Query has incorrect symbols in " + string(word) + ".");
- }
- if (is_minus && word[0] == '-') {
- throw invalid_argument("Query has incorrect minus-words:" + string(word) + ".");
- }
- return {word, is_minus, IsStopWord(word)};
- }
Advertisement
Add Comment
Please, Sign In to add comment