14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include "searchhelper.h" |
18 #include "searchhelper.h" |
19 #include <qcpixdocument.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 = QCPixSearcher::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(); |
28 } |
28 } |
29 |
29 |
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 |
|
41 QString resultString(""); |
|
42 resultsBox->setPlainText( resultString ); |
39 resultsBox->setPlainText( resultString ); |
43 searchTime.restart(); |
40 searchTime.restart(); |
44 QString searchString; |
41 QString searchString; |
|
42 |
|
43 #if PREFIX_SEARCH |
45 searchString = "$prefix(\""; |
44 searchString = "$prefix(\""; |
46 searchString += searchBox->text(); |
45 searchString += searchBox->text(); |
47 searchString += "\")"; |
46 searchString += "\")"; |
48 |
47 |
49 #if STAR_SEARCH |
48 #elif STAR_SEARCH |
50 searchString += searchBox->text(); |
49 searchString += searchBox->text(); |
51 searchString += "*"; |
50 searchString += "*"; |
52 #elif NO_STAR_SEARCH |
51 #elif NO_STAR_SEARCH |
|
52 searchString = searchBox->text(); |
53 ;//do nothing |
53 ;//do nothing |
54 #endif |
54 #endif |
55 |
55 iHits = 0; |
56 hits = searcher->search( searchString ); |
56 iHits = searcher->search( searchString ); |
57 |
57 |
58 if (searchTime.elapsed() >= 0) |
58 if (searchTime.elapsed() >= 0) |
59 resultString = "SearchTime: " + QString().setNum( searchTime.elapsed() ) + " ms \r\n"; |
59 resultString = "SearchTime: " + QString().setNum( searchTime.elapsed() ) + " ms \r\n"; |
60 resultString += "Hits: " + QString().setNum( hits ) + "\r\n"; |
60 resultString += "Hits: " + QString().setNum( iHits ) + "\r\n"; |
61 resultsBox->setPlainText( resultString ); |
61 resultsBox->setPlainText( resultString ); |
62 |
62 |
63 #if !DONT_SHOW_RESULTS |
63 #if !DONT_SHOW_RESULTS |
64 if( hits > 0 ) |
64 if( iHits > 0 ) |
65 { |
65 { |
66 QCPixDocument* temp = NULL; |
66 resultString += "Enter Index,count values and press GetDocs button to get the results"; |
67 int docCount = 0; |
67 resultString +="\r\n"; |
68 do{ |
68 resultsBox->setPlainText( resultString ); |
69 temp = searcher->getDocument( docCount++ ); |
|
70 resultString += temp->baseAppClass() + " " + temp->docId() + " " + temp->excerpt() + "\r\n\r\n"; |
|
71 delete temp; |
|
72 }while( hits > docCount ); |
|
73 } |
69 } |
74 resultsBox->setPlainText( resultString ); |
|
75 #endif //DONT_SHOW_RESULTS |
70 #endif //DONT_SHOW_RESULTS |
76 } |
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 } |