PageRenderTime 123ms CodeModel.GetById 60ms app.highlight 6ms RepoModel.GetById 54ms app.codeStats 0ms

/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
20#include "DatabaseCommand_UpdateSearchIndex.h"
21
22#include <QSqlRecord>
23
24#include "DatabaseImpl.h"
25#include "Source.h"
26#include "TomahawkSqlQuery.h"
27
28#include "fuzzyindex/DatabaseFuzzyIndex.h"
29#include "utils/Logger.h"
30
31namespace Tomahawk
32{
33
34DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex()
35    : DatabaseCommand()
36{
37    tDebug() << Q_FUNC_INFO << "Updating index.";
38}
39
40
41DatabaseCommand_UpdateSearchIndex::~DatabaseCommand_UpdateSearchIndex()
42{
43    tDebug() << Q_FUNC_INFO;
44}
45
46
47void
48DatabaseCommand_UpdateSearchIndex::exec( DatabaseImpl* db )
49{
50    db->m_fuzzyIndex->beginIndexing();
51
52    TomahawkSqlQuery q = db->newquery();
53    q.exec( "SELECT track.id, track.name, artist.name, artist.id FROM track, artist WHERE artist.id = track.artist" );
54    while ( q.next() )
55    {
56        IndexData ida;
57        ida.id = q.value( 0 ).toUInt();
58        ida.artistId = q.value( 3 ).toUInt();
59        ida.track = q.value( 1 ).toString();
60        ida.artist = q.value( 2 ).toString();
61
62        db->m_fuzzyIndex->appendFields( ida );
63    }
64
65    q.exec( "SELECT album.id, album.name FROM album" );
66    while ( q.next() )
67    {
68        IndexData ida;
69        ida.id = q.value( 0 ).toUInt();
70        ida.album = q.value( 1 ).toString();
71
72        db->m_fuzzyIndex->appendFields( ida );
73    }
74
75    tDebug( LOGVERBOSE ) << "Building index finished.";
76
77    db->m_fuzzyIndex->endIndexing();
78}
79
80}