/src/libtomahawk/database/DatabaseCommand_UpdateSearchIndex.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 80 lines · 45 code · 17 blank · 18 comment · 2 complexity · ec8d284f8eb7c9b8c3e2d44836dd2590 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2012 Leo Franchi <lfranchi@kde.org>
  5. *
  6. * Tomahawk is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Tomahawk is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "DatabaseCommand_UpdateSearchIndex.h"
  20. #include <QSqlRecord>
  21. #include "DatabaseImpl.h"
  22. #include "Source.h"
  23. #include "TomahawkSqlQuery.h"
  24. #include "fuzzyindex/DatabaseFuzzyIndex.h"
  25. #include "utils/Logger.h"
  26. namespace Tomahawk
  27. {
  28. DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex()
  29. : DatabaseCommand()
  30. {
  31. tDebug() << Q_FUNC_INFO << "Updating index.";
  32. }
  33. DatabaseCommand_UpdateSearchIndex::~DatabaseCommand_UpdateSearchIndex()
  34. {
  35. tDebug() << Q_FUNC_INFO;
  36. }
  37. void
  38. DatabaseCommand_UpdateSearchIndex::exec( DatabaseImpl* db )
  39. {
  40. db->m_fuzzyIndex->beginIndexing();
  41. TomahawkSqlQuery q = db->newquery();
  42. q.exec( "SELECT track.id, track.name, artist.name, artist.id FROM track, artist WHERE artist.id = track.artist" );
  43. while ( q.next() )
  44. {
  45. IndexData ida;
  46. ida.id = q.value( 0 ).toUInt();
  47. ida.artistId = q.value( 3 ).toUInt();
  48. ida.track = q.value( 1 ).toString();
  49. ida.artist = q.value( 2 ).toString();
  50. db->m_fuzzyIndex->appendFields( ida );
  51. }
  52. q.exec( "SELECT album.id, album.name FROM album" );
  53. while ( q.next() )
  54. {
  55. IndexData ida;
  56. ida.id = q.value( 0 ).toUInt();
  57. ida.album = q.value( 1 ).toString();
  58. db->m_fuzzyIndex->appendFields( ida );
  59. }
  60. tDebug( LOGVERBOSE ) << "Building index finished.";
  61. db->m_fuzzyIndex->endIndexing();
  62. }
  63. }