diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2009-02-05 18:33:56 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2009-02-05 18:33:56 +0100 |
commit | edeb2fa37dcf677ca601e4302aa3f65a96a6b53e (patch) | |
tree | 2b36d49ce3270cfb531a54e323803c14b7e67615 /src/search_engine.cpp | |
parent | 7be920b6ad968e19321f7da0fefb442d28d360bc (diff) |
add field 'Any' to search engine
Diffstat (limited to 'src/search_engine.cpp')
-rw-r--r-- | src/search_engine.cpp | 77 |
1 files changed, 54 insertions, 23 deletions
diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 5230d7b3..3350e488 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -68,7 +68,7 @@ void UpdateFoundList() } } -void PrepareSearchEngine(Song &s) +void PrepareSearchEngine(SearchPattern &s) { for (size_t i = 0; i < mSearcher->Size(); i++) { @@ -84,12 +84,12 @@ void PrepareSearchEngine(Song &s) mSearcher->SetTitle(""); mSearcher->Clear(); mSearcher->Reset(); - mSearcher->ResizeBuffer(16); + mSearcher->ResizeBuffer(17); - mSearcher->IntoSeparator(9); - mSearcher->IntoSeparator(13); + mSearcher->IntoSeparator(10); + mSearcher->IntoSeparator(14); - for (size_t i = 0; i < 16; i++) + for (size_t i = 0; i < 17; i++) { try { @@ -98,25 +98,26 @@ void PrepareSearchEngine(Song &s) catch (List::InvalidItem) { } } - *mSearcher->at(0).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist()); - *mSearcher->at(1).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle()); - *mSearcher->at(2).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum()); - *mSearcher->at(3).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName()); - *mSearcher->at(4).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer()); - *mSearcher->at(5).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer()); - *mSearcher->at(6).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre()); - *mSearcher->at(7).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(s.GetYear()); - *mSearcher->at(8).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(s.GetComment()); + *mSearcher->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(s.Any()); + *mSearcher->at(1).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(s.GetArtist()); + *mSearcher->at(2).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(s.GetTitle()); + *mSearcher->at(3).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum()); + *mSearcher->at(4).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(s.GetName()); + *mSearcher->at(5).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(s.GetComposer()); + *mSearcher->at(6).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer()); + *mSearcher->at(7).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(s.GetGenre()); + *mSearcher->at(8).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(s.GetYear()); + *mSearcher->at(9).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(s.GetComment()); - *mSearcher->at(10).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); - *mSearcher->at(11).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (search_match_to_pattern ? search_mode_normal : search_mode_strict); - *mSearcher->at(12).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (search_case_sensitive ? "Yes" : "No"); + *mSearcher->at(11).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); + *mSearcher->at(12).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (search_match_to_pattern ? search_mode_normal : search_mode_strict); + *mSearcher->at(13).first << fmtBold << "Case sensitive:" << fmtBoldEnd << ' ' << (search_case_sensitive ? "Yes" : "No"); - *mSearcher->at(14).first << "Search"; - *mSearcher->at(15).first << "Reset"; + *mSearcher->at(15).first << "Search"; + *mSearcher->at(16).first << "Reset"; } -void Search(Song &s) +void Search(SearchPattern &s) { if (s.Empty()) return; @@ -131,11 +132,16 @@ void Search(Song &s) list.push_back(&(*mPlaylist)[i]); } + bool any_found = 1; bool found = 1; if (!search_case_sensitive) { string t; + t = s.Any(); + ToLower(t); + s.Any(t); + t = s.GetArtist(); ToLower(t); s.SetArtist(t); @@ -213,6 +219,18 @@ void Search(Song &s) if (search_match_to_pattern) { + if (!s.Any().empty()) + any_found = + copy.GetArtist().find(s.Any()) != string::npos + || copy.GetTitle().find(s.Any()) != string::npos + || copy.GetAlbum().find(s.Any()) != string::npos + || copy.GetFile().find(s.Any()) != string::npos + || copy.GetComposer().find(s.Any()) != string::npos + || copy.GetPerformer().find(s.Any()) != string::npos + || copy.GetGenre().find(s.Any()) != string::npos + || copy.GetYear().find(s.Any()) != string::npos + || copy.GetComment().find(s.Any()) != string::npos; + if (found && !s.GetArtist().empty()) found = copy.GetArtist().find(s.GetArtist()) != string::npos; if (found && !s.GetTitle().empty()) @@ -228,12 +246,24 @@ void Search(Song &s) if (found && !s.GetGenre().empty()) found = copy.GetGenre().find(s.GetGenre()) != string::npos; if (found && !s.GetYear().empty()) - found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear()); + found = copy.GetYear().find(s.GetYear()) != string::npos; if (found && !s.GetComment().empty()) found = copy.GetComment().find(s.GetComment()) != string::npos; } else { + if (!s.Any().empty()) + any_found = + copy.GetArtist() == s.Any() + || copy.GetTitle() == s.Any() + || copy.GetAlbum() == s.Any() + || copy.GetFile() == s.Any() + || copy.GetComposer() == s.Any() + || copy.GetPerformer() == s.Any() + || copy.GetGenre() == s.Any() + || copy.GetYear() == s.Any() + || copy.GetComment() == s.Any(); + if (found && !s.GetArtist().empty()) found = copy.GetArtist() == s.GetArtist(); if (found && !s.GetTitle().empty()) @@ -249,17 +279,18 @@ void Search(Song &s) if (found && !s.GetGenre().empty()) found = copy.GetGenre() == s.GetGenre(); if (found && !s.GetYear().empty()) - found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear()); + found = copy.GetYear() == s.GetYear(); if (found && !s.GetComment().empty()) found = copy.GetComment() == s.GetComment(); } - if (found) + if (found && any_found) { mSearcher->AddOption(make_pair((Buffer *)0, *it)); list[it-list.begin()] = 0; } found = 1; + any_found = 1; } if (Config.search_in_db) // free song list only if it's database FreeSongList(list); |