Example #1
0
bool Filters::FilterText(const Item& item) const {
  std::vector<std::wstring> words;
  Split(text, L" ", words);
  RemoveEmptyStrings(words);

  std::vector<std::wstring> titles;
  GetAllTitles(item.GetId(), titles);

  const auto& genres = item.GetGenres();

  for (const auto& word : words) {
    auto check_strings = [&word](const std::vector<std::wstring>& v) {
      for (const auto& str : v) {
        if (InStr(str, word, 0, true) > -1)
          return true;
      }
      return false;
    };
    if (!check_strings(titles) &&
        !check_strings(genres) &&
        InStr(item.GetMyTags(), word, 0, true) == -1)
      return false;
  }

  return true;
}
Example #2
0
bool Filters::CheckItem(Item& item) {
  // Filter my status
  for (size_t i = 0; i < my_status.size(); i++)
    if (!my_status.at(i) && item.GetMyStatus() == i)
      return false;

  // Filter airing status
  for (size_t i = 0; i < status.size(); i++)
    if (!status.at(i) && item.GetAiringStatus() == i + 1)
      return false;

  // Filter type
  for (size_t i = 0; i < type.size(); i++)
    if (!type.at(i) && item.GetType() == i + 1)
      return false;

  // Filter text
  vector<wstring> words;
  Split(text, L" ", words);
  RemoveEmptyStrings(words);
  for (auto it = words.begin(); it != words.end(); ++it) {
    if (InStr(item.GetTitle(), *it, 0, true) == -1 && 
        InStr(item.GetGenres(), *it, 0, true) == -1 && 
        InStr(item.GetMyTags(), *it, 0, true) == -1) {
      bool found = false;
      for (auto synonym = item.GetSynonyms().begin(); 
           !found && synonym != item.GetSynonyms().end(); ++synonym)
        if (InStr(*synonym, *it, 0, true) > -1) found = true;
      if (item.IsInList())
        for (auto synonym = item.GetUserSynonyms().begin(); 
             !found && synonym != item.GetUserSynonyms().end(); ++synonym)
          if (InStr(*synonym, *it, 0, true) > -1) found = true;
      if (!found) return false;
    }
  }

  // Item passed all filters
  return true;
}