qcpix/tsrc/orbitsearch/searchhelper.cpp
changeset 14 8bd192d47aaa
parent 13 fcb2a58c181b
equal deleted inserted replaced
13:fcb2a58c181b 14:8bd192d47aaa
    16 */
    16 */
    17 
    17 
    18 #include "searchhelper.h"
    18 #include "searchhelper.h"
    19 #include <cpixdocument.h>
    19 #include <cpixdocument.h>
    20 
    20 
    21 SearchHelper::SearchHelper(HbLineEdit* searchBx, HbPushButton* searchBtn, HbTextEdit* searchRslt)
    21 SearchHelper::SearchHelper(HbLineEdit* searchBx, HbPushButton* searchBtn, HbTextEdit* searchRslt, HbLineEdit* indexBox, HbLineEdit* countBox, HbPushButton* getdocbutton)
    22     :searchBox( searchBx ), searchButton( searchBtn ), resultsBox( searchRslt )
    22     :searchBox( searchBx ), searchButton( searchBtn ), resultsBox( searchRslt ), indexBox(indexBox), countBox(countBox), getdocbutton(getdocbutton)
    23     {
    23     {
    24     searcher = CpixSearcher::newInstance("root","_aggregate");
    24     searcher = CpixSearcher::newInstance("root","_aggregate");
    25     resultsBox->setReadOnly( true );
    25     resultsBox->setReadOnly( true );
    26     resultsBox->setPlainText("Initialized");
    26     resultsBox->setPlainText("Initialized");
    27     searchTime.start();
    27     searchTime.start();
    33     }
    33     }
    34 
    34 
    35 void SearchHelper::doSearch()
    35 void SearchHelper::doSearch()
    36     {
    36     {
    37     resultsBox->setPlainText("Search button clicked!");
    37     resultsBox->setPlainText("Search button clicked!");
    38     
    38     resultString = "";
    39     int hits = 0;
       
    40     QString resultString("");
       
    41     resultsBox->setPlainText( resultString );
    39     resultsBox->setPlainText( resultString );
    42     searchTime.restart();
    40     searchTime.restart();
    43     QString searchString;
    41     QString searchString;
    44     
    42     
    45 #if PREFIX_SEARCH
    43 #if PREFIX_SEARCH
    49 
    47 
    50 #elif STAR_SEARCH
    48 #elif STAR_SEARCH
    51     searchString += searchBox->text();
    49     searchString += searchBox->text();
    52     searchString += "*";
    50     searchString += "*";
    53 #elif NO_STAR_SEARCH
    51 #elif NO_STAR_SEARCH
       
    52     searchString = searchBox->text();
    54         ;//do nothing
    53         ;//do nothing
    55 #endif
    54 #endif
    56     
    55     iHits = 0;
    57     hits = searcher->search( searchString );
    56     iHits = searcher->search( searchString );
    58 
    57 
    59     if (searchTime.elapsed() >= 0)
    58     if (searchTime.elapsed() >= 0)
    60         resultString = "SearchTime: " + QString().setNum( searchTime.elapsed() ) + " ms \r\n";
    59         resultString = "SearchTime: " + QString().setNum( searchTime.elapsed() ) + " ms \r\n";
    61     resultString += "Hits: " + QString().setNum( hits ) + "\r\n";
    60     resultString += "Hits: " + QString().setNum( iHits ) + "\r\n";
    62     resultsBox->setPlainText( resultString );
    61     resultsBox->setPlainText( resultString );
    63 
    62 
    64 #if !DONT_SHOW_RESULTS
    63 #if !DONT_SHOW_RESULTS
    65     if( hits > 0 )
    64     if( iHits > 0 )
    66         {
    65         {
    67         CpixDocument* temp = NULL;
    66         resultString += "Enter Index,count values and press GetDocs button to get the results";
    68         int docCount = 0;
    67         resultString +="\r\n";
    69         do{
    68         resultsBox->setPlainText( resultString );
    70           temp = searcher->document( docCount++ );
       
    71           resultString += temp->baseAppClass() + " " + temp->docId() + " " + temp->excerpt() + "\r\n\r\n";
       
    72           delete temp;
       
    73           }while( hits > docCount );
       
    74         }
    69         }
    75     resultsBox->setPlainText( resultString );
       
    76 #endif //DONT_SHOW_RESULTS
    70 #endif //DONT_SHOW_RESULTS
    77     }
    71     }
       
    72 
       
    73 void SearchHelper::showdocs()
       
    74     {
       
    75     QString indexstring = indexBox->text();
       
    76     bool ok = false;
       
    77     int index = indexstring.toInt(&ok);
       
    78     if (ok)
       
    79         {
       
    80         QString countstring = countBox->text();
       
    81         int count = countstring.toInt(&ok);
       
    82         if (ok)
       
    83             {
       
    84             if ( index <= iHits )
       
    85                 {
       
    86                 if ( count == 1)
       
    87                     {
       
    88                     //call the normal get doc API
       
    89                     CpixDocument* temp = NULL;
       
    90                     do{
       
    91                       temp = searcher->document( index++ );
       
    92                       resultString += temp->baseAppClass() + " " + temp->docId() + " " + temp->excerpt() + "\r\n\r\n";
       
    93                       delete temp;
       
    94                       }while( iHits > index );
       
    95                     }
       
    96                 else
       
    97                     {
       
    98                     //call batch doc API
       
    99                     CpixDocument** temp = NULL;
       
   100                     do{
       
   101                        int retdoccount = 0;
       
   102                        temp = searcher->batchdocument(index,retdoccount,count);
       
   103                        for (int i=0; i< retdoccount; i++)
       
   104                            {
       
   105                            resultString += temp[i]->baseAppClass() + " " + temp[i]->docId() + " " + temp[i]->excerpt() + "\r\n\r\n";
       
   106                            delete temp[i];
       
   107                            }
       
   108                         delete temp;
       
   109                         temp = NULL;
       
   110                         index += retdoccount;
       
   111                     }while (iHits > index);
       
   112                     }
       
   113                 }
       
   114             else resultString += " Requested document is out of range";
       
   115             resultsBox->setPlainText( resultString );
       
   116             }
       
   117         }
       
   118     }