qcpix/tsrc/orbitsearch/searchhelper.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 14 May 2010 16:57:37 +0300
changeset 2 6c1a2771f4b7
parent 1 6f2c1c46032b
child 7 a5fbfefd615f
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/

#include "searchhelper.h"
#include <qcpixdocument.h>

SearchHelper::SearchHelper(HbLineEdit* searchBx, HbPushButton* searchBtn, HbTextEdit* searchRslt)
    :searchBox( searchBx ), searchButton( searchBtn ), resultsBox( searchRslt )
    {
    searcher = QCPixSearcher::newInstance("root","_aggregate");
    resultsBox->setReadOnly( true );
    resultsBox->setPlainText("Initialized");
    searchTime.start();
    }

SearchHelper::~SearchHelper()
    {
    delete searcher;
    }

void SearchHelper::doSearch()
    {
    resultsBox->setPlainText("Search button clicked!");
    
    int hits = 0;
    QString resultString("");
    resultsBox->setPlainText( resultString );
    searchTime.restart();
    QString searchString;
    
#if PREFIX_SEARCH
    searchString = "$prefix(\""; 
    searchString += searchBox->text();
    searchString += "\")";

#elif STAR_SEARCH
    searchString += searchBox->text();
    searchString += "*";
#elif NO_STAR_SEARCH
        ;//do nothing
#endif
    
    hits = searcher->search( searchString );

    if (searchTime.elapsed() >= 0)
        resultString = "SearchTime: " + QString().setNum( searchTime.elapsed() ) + " ms \r\n";
    resultString += "Hits: " + QString().setNum( hits ) + "\r\n";
    resultsBox->setPlainText( resultString );

#if !DONT_SHOW_RESULTS
    if( hits > 0 )
        {
        QCPixDocument* temp = NULL;
        int docCount = 0;
        do{
          temp = searcher->getDocument( docCount++ );
          resultString += temp->baseAppClass() + " " + temp->docId() + " " + temp->excerpt() + "\r\n\r\n";
          delete temp;
          }while( hits > docCount );
        }
    resultsBox->setPlainText( resultString );
#endif //DONT_SHOW_RESULTS
    }