forked from markus/S_New4
fix levinshtein
This commit is contained in:
parent
25fe37e647
commit
08a4b054e1
@ -877,7 +877,6 @@ int ProgramManager::directLinkModus(Settings *settings)
|
||||
}
|
||||
|
||||
|
||||
|
||||
int levenshtein_distance(const std::string& str1, const std::string& str2) {
|
||||
|
||||
int m = str1.length();
|
||||
@ -1015,6 +1014,8 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
std::cout << " <DEBUG> FiNDS: '" << finds << "'" << std::endl;
|
||||
|
||||
|
||||
//Wenn normale Suche kein ergebnis findet - levinshtein suche...
|
||||
|
||||
if(finds == "" ) {
|
||||
if(settings->debugMode)
|
||||
std::cout << " NICHTS GEFUNDEN -> Levenshtein Suche..." << std::endl;
|
||||
@ -1023,6 +1024,11 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
std::istringstream stream(serienListe + "\n");
|
||||
std::string line;
|
||||
|
||||
//info falls auf nicht aktivierten seiten etwas gefunden worden wäre
|
||||
bool on_other_sites = false;
|
||||
//alles in upper-string
|
||||
std::string upper_name = pageManager.upper_string(settings->name);
|
||||
|
||||
while (std::getline(stream, line)) {
|
||||
if(line == "") continue;
|
||||
size_t ind_1 = line.find("|");
|
||||
@ -1034,13 +1040,22 @@ int ProgramManager::searchModus(Settings *settings, std::string *saveTo, bool no
|
||||
size_t ind_3 = line.find("|", ind_2 + 1);
|
||||
if(ind_3 == std::string::npos)
|
||||
continue;
|
||||
// if(allUrlsInUSe.find( line.substr(ind_3 + 1) ) == std::string::npos)
|
||||
// continue;
|
||||
if(levenshtein_distance(line.substr(ind_2 + 1, ind_3 - ind_2 - 1), settings->name) <= 2)
|
||||
if(allUrlsInUSe.find( line.substr(ind_3 + 1) ) == std::string::npos) {
|
||||
on_other_sites = true;
|
||||
continue;
|
||||
}
|
||||
std::string name_correct_upper = pageManager.upper_string( line.substr(ind_2 + 1, ind_3 - ind_2 - 1));
|
||||
|
||||
// Mindestens erlaubte Entfernung: 2, wenn name länger als 12: length / 5, ab l=20: max 5;
|
||||
if(levenshtein_distance(name_correct_upper, upper_name) <= std::min( std::max( (int)(name_correct_upper.length() / 5), 2),
|
||||
5))
|
||||
finds += line + "\n";
|
||||
}
|
||||
if(finds.size() >= 1)
|
||||
finds.pop_back();
|
||||
if(finds == "" && on_other_sites) {
|
||||
std::cout << " [!] Auf anderen Seiten wurde zu ihrer Suche etwas gefunden! Verwenden sie z.b. '-i all' für weitere Infos!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
serienListe.clear(); // Speicher freigeben
|
||||
|
Loading…
Reference in New Issue
Block a user