#include <sqliteInt.h>
Inheritance diagram for Index:


Definition at line 831 of file sqliteInt.h.
Definition at line 60 of file index.cpp.
References alreadyHaveDocList, QObject::connect(), lastWindowClosed, qApp, setLastWinClosed(), SIGNAL, and SLOT.
00061 : QObject( 0 ), docPath( dp ) 00062 { 00063 Q_UNUSED(hp); 00064 00065 alreadyHaveDocList = false; 00066 lastWindowClosed = false; 00067 connect( qApp, SIGNAL(lastWindowClosed()), 00068 this, SLOT(setLastWinClosed()) ); 00069 }
Here is the call graph for this function:

| Index::Index | ( | const QStringList & | dl, | |
| const QString & | hp | |||
| ) |
Definition at line 71 of file index.cpp.
References alreadyHaveDocList, QObject::connect(), docList, lastWindowClosed, qApp, setLastWinClosed(), SIGNAL, and SLOT.
00072 : QObject( 0 ) 00073 { 00074 Q_UNUSED(hp); 00075 docList = dl; 00076 alreadyHaveDocList = true; 00077 lastWindowClosed = false; 00078 connect( qApp, SIGNAL(lastWindowClosed()), 00079 this, SLOT(setLastWinClosed()) ); 00080 }
Here is the call graph for this function:

| void Index::writeDict | ( | ) |
Definition at line 234 of file index.cpp.
References dict, dictFile, QFile::open(), s, writeDocumentList(), and QIODevice::WriteOnly.
Referenced by HelpDialog::setupFullTextIndex().
00235 { 00236 QFile f( dictFile ); 00237 if ( !f.open(QFile::WriteOnly ) ) 00238 return; 00239 QDataStream s( &f ); 00240 for(QHash<QString, Entry *>::Iterator it = dict.begin(); it != dict.end(); ++it) { 00241 s << it.key(); 00242 s << it.value()->documents.count(); 00243 s << it.value()->documents; 00244 } 00245 f.close(); 00246 writeDocumentList(); 00247 }
Here is the call graph for this function:

| void Index::readDict | ( | ) |
Definition at line 258 of file index.cpp.
References QFile::close(), dict, dictFile, key, QFile::open(), readDocumentList(), QIODevice::ReadOnly, QVector< T >::resize(), and s.
Referenced by HelpDialog::setupFullTextIndex().
00259 { 00260 QFile f( dictFile ); 00261 if ( !f.open(QFile::ReadOnly ) ) 00262 return; 00263 00264 dict.clear(); 00265 QDataStream s( &f ); 00266 QString key; 00267 int numOfDocs; 00268 QVector<Document> docs; 00269 while ( !s.atEnd() ) { 00270 s >> key; 00271 s >> numOfDocs; 00272 docs.resize(numOfDocs); 00273 s >> docs; 00274 dict.insert( key, new Entry( docs ) ); 00275 } 00276 f.close(); 00277 readDocumentList(); 00278 }
Here is the call graph for this function:

| int Index::makeIndex | ( | ) |
Definition at line 102 of file index.cpp.
References alreadyHaveDocList, QList< T >::begin(), QList< T >::count(), docList, emit, QList< T >::end(), i, indexingProgress(), QList< T >::isEmpty(), lastWindowClosed, parseDocument(), setupDocumentList(), and QUrl::toLocalFile().
Referenced by HelpDialog::setupFullTextIndex().
00103 { 00104 if ( !alreadyHaveDocList ) 00105 setupDocumentList(); 00106 if ( docList.isEmpty() ) 00107 return 1; 00108 QStringList::Iterator it = docList.begin(); 00109 int steps = docList.count() / 100; 00110 if ( !steps ) 00111 steps++; 00112 int prog = 0; 00113 for ( int i = 0; it != docList.end(); ++it, ++i ) { 00114 if ( lastWindowClosed ) { 00115 return -1; 00116 } 00117 QUrl url(*it); 00118 parseDocument( url.toLocalFile(), i ); 00119 if ( i%steps == 0 ) { 00120 prog++; 00121 emit indexingProgress( prog ); 00122 } 00123 } 00124 return 0; 00125 }
Here is the call graph for this function:

| QStringList Index::query | ( | const QStringList & | , | |
| const QStringList & | , | |||
| const QStringList & | ||||
| ) |
Definition at line 289 of file index.cpp.
References QList< T >::append(), QList< T >::at(), QList< T >::begin(), QVector< T >::begin(), QVector< T >::constBegin(), QVector< T >::constEnd(), QList< T >::count(), dict, docList, Term::documents, QList< T >::end(), QVector< T >::end(), QVector< T >::erase(), getWildcardTerms(), QList< T >::isEmpty(), qSort(), searchForPattern(), setupDummyTerm(), t, and QList< T >::takeFirst().
Referenced by HelpDialog::startSearch().
00290 { 00291 QList<Term> termList; 00292 for (QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it ) { 00293 Entry *e = 0; 00294 if ( (*it).contains(QLatin1Char('*')) ) { 00295 QVector<Document> wcts = setupDummyTerm( getWildcardTerms( *it ) ); 00296 termList.append( Term(QLatin1String("dummy"), wcts.count(), wcts ) ); 00297 } else if ( dict[ *it ] ) { 00298 e = dict[ *it ]; 00299 termList.append( Term( *it, e->documents.count(), e->documents ) ); 00300 } else { 00301 return QStringList(); 00302 } 00303 } 00304 if ( !termList.count() ) 00305 return QStringList(); 00306 qSort(termList); 00307 00308 QVector<Document> minDocs = termList.takeFirst().documents; 00309 for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it) { 00310 Term *t = &(*it); 00311 QVector<Document> docs = t->documents; 00312 for(QVector<Document>::Iterator minDoc_it = minDocs.begin(); minDoc_it != minDocs.end(); ) { 00313 bool found = false; 00314 for (QVector<Document>::ConstIterator doc_it = docs.constBegin(); doc_it != docs.constEnd(); ++doc_it ) { 00315 if ( (*minDoc_it).docNumber == (*doc_it).docNumber ) { 00316 (*minDoc_it).frequency += (*doc_it).frequency; 00317 found = true; 00318 break; 00319 } 00320 } 00321 if ( !found ) 00322 minDoc_it = minDocs.erase( minDoc_it ); 00323 else 00324 ++minDoc_it; 00325 } 00326 } 00327 00328 QStringList results; 00329 qSort( minDocs ); 00330 if ( termSeq.isEmpty() ) { 00331 for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it) 00332 results << docList.at((int)(*it).docNumber); 00333 return results; 00334 } 00335 00336 QString fileName; 00337 for(QVector<Document>::Iterator it = minDocs.begin(); it != minDocs.end(); ++it) { 00338 fileName = docList[ (int)(*it).docNumber ]; 00339 if ( searchForPattern( termSeq, seqWords, fileName ) ) 00340 results << fileName; 00341 } 00342 return results; 00343 }
Here is the call graph for this function:

Definition at line 345 of file index.cpp.
References Qt::CaseInsensitive, constData(), QString::indexOf(), QString::mid(), QFile::open(), qWarning(), QIODevice::ReadOnly, s, start, and QUrl::toLocalFile().
Referenced by HelpDialog::startSearch().
00346 { 00347 QUrl url(fullFileName); 00348 QString fileName = url.toLocalFile(); 00349 QFile file( fileName ); 00350 if ( !file.open( QFile::ReadOnly ) ) { 00351 qWarning( (QLatin1String("cannot open file ") + fileName).toAscii().constData() ); 00352 return fileName; 00353 } 00354 QTextStream s( &file ); 00355 QString text = s.readAll(); 00356 00357 int start = text.indexOf(QLatin1String("<title>"), 0, Qt::CaseInsensitive) + 7; 00358 int end = text.indexOf(QLatin1String("</title>"), 0, Qt::CaseInsensitive); 00359 00360 QString title = ( end - start <= 0 ? tr("Untitled") : text.mid( start, end - start ) ); 00361 return title; 00362 }
Here is the call graph for this function:

| void Index::setDictionaryFile | ( | const QString & | ) |
Definition at line 87 of file index.cpp.
References dictFile.
Referenced by HelpDialog::setupFullTextIndex().
00088 { 00089 dictFile = f; 00090 }
| void Index::setDocListFile | ( | const QString & | ) |
Definition at line 92 of file index.cpp.
References docListFile.
Referenced by HelpDialog::setupFullTextIndex().
00093 { 00094 docListFile = f; 00095 }
| void Index::setDocList | ( | const QStringList & | ) |
Definition at line 97 of file index.cpp.
References docList.
Referenced by HelpDialog::setupFullTextIndex().
00098 { 00099 docList = lst; 00100 }
| void Index::indexingProgress | ( | int | ) | [signal] |
Referenced by makeIndex().
| void Index::setLastWinClosed | ( | ) | [private, slot] |
Definition at line 82 of file index.cpp.
References lastWindowClosed.
Referenced by Index().
00083 { 00084 lastWindowClosed = true; 00085 }
| void Index::setupDocumentList | ( | ) | [private] |
Definition at line 127 of file index.cpp.
References QList< T >::append(), QList< T >::constBegin(), QList< T >::constEnd(), d, docList, docPath, and filters.
Referenced by makeIndex().
00128 { 00129 QDir d( docPath ); 00130 QStringList filters; 00131 filters.append(QLatin1String("*.html")); 00132 QStringList lst = d.entryList(filters); 00133 QStringList::ConstIterator it = lst.constBegin(); 00134 for ( ; it != lst.constEnd(); ++it ) 00135 docList.append( "file:" + docPath + QLatin1String("/") + *it ); 00136 }
Here is the call graph for this function:

| void Index::parseDocument | ( | const QString & | , | |
| int | ||||
| ) | [private] |
Definition at line 179 of file index.cpp.
References buf, c, QFile::close(), QTextCodec::codecForName(), constData(), QByteArray::constData(), getCharsetForDocument(), i, insertInDict(), QString::isNull(), j, QString::length(), QFile::open(), qWarning(), QIODevice::ReadOnly, s, QString::toLatin1(), and QString::unicode().
Referenced by makeIndex().
00180 { 00181 QFile file( filename ); 00182 if ( !file.open(QFile::ReadOnly) ) { 00183 qWarning( (QLatin1String("can not open file ") + filename).toAscii().constData() ); 00184 return; 00185 } 00186 00187 QTextStream s(&file); 00188 QString en = getCharsetForDocument(&file); 00189 s.setCodec(QTextCodec::codecForName(en.toLatin1().constData())); 00190 00191 QString text = s.readAll(); 00192 if (text.isNull()) 00193 return; 00194 00195 bool valid = true; 00196 const QChar *buf = text.unicode(); 00197 QChar str[64]; 00198 QChar c = buf[0]; 00199 int j = 0; 00200 int i = 0; 00201 while ( j < text.length() ) { 00202 if ( c == QLatin1Char('<') || c == QLatin1Char('&') ) { 00203 valid = false; 00204 if ( i > 1 ) 00205 insertInDict( QString(str,i), docNum ); 00206 i = 0; 00207 c = buf[++j]; 00208 continue; 00209 } 00210 if ( ( c == QLatin1Char('>') || c == QLatin1Char(';') ) && !valid ) { 00211 valid = true; 00212 c = buf[++j]; 00213 continue; 00214 } 00215 if ( !valid ) { 00216 c = buf[++j]; 00217 continue; 00218 } 00219 if ( ( c.isLetterOrNumber() || c == QLatin1Char('_') ) && i < 63 ) { 00220 str[i] = c.toLower(); 00221 ++i; 00222 } else { 00223 if ( i > 1 ) 00224 insertInDict( QString(str,i), docNum ); 00225 i = 0; 00226 } 00227 c = buf[++j]; 00228 } 00229 if ( i > 1 ) 00230 insertInDict( QString(str,i), docNum ); 00231 file.close(); 00232 }
Here is the call graph for this function:

| void Index::insertInDict | ( | const QString & | , | |
| int | ||||
| ) | [private] |
Definition at line 138 of file index.cpp.
References dict.
Referenced by parseDocument().
00139 { 00140 if ( str == QLatin1String("amp") || str == QLatin1String("nbsp")) 00141 return; 00142 Entry *e = 0; 00143 if ( dict.count() ) 00144 e = dict[ str ]; 00145 00146 if ( e ) { 00147 if ( e->documents.last().docNumber != docNum ) 00148 e->documents.append( Document(docNum, 1 ) ); 00149 else 00150 e->documents.last().frequency++; 00151 } else { 00152 dict.insert( str, new Entry( docNum ) ); 00153 } 00154 }
| void Index::writeDocumentList | ( | ) | [private] |
Definition at line 249 of file index.cpp.
References docList, docListFile, QFile::open(), s, and QIODevice::WriteOnly.
Referenced by writeDict().
00250 { 00251 QFile f( docListFile ); 00252 if ( !f.open(QFile::WriteOnly ) ) 00253 return; 00254 QDataStream s( &f ); 00255 s << docList; 00256 }
Here is the call graph for this function:

| void Index::readDocumentList | ( | ) | [private] |
Definition at line 280 of file index.cpp.
References docList, docListFile, QFile::open(), QIODevice::ReadOnly, and s.
Referenced by readDict().
00281 { 00282 QFile f( docListFile ); 00283 if ( !f.open(QFile::ReadOnly ) ) 00284 return; 00285 QDataStream s( &f ); 00286 s >> docList; 00287 }
Here is the call graph for this function:

| QStringList Index::getWildcardTerms | ( | const QString & | ) | [private] |
Definition at line 364 of file index.cpp.
References QList< T >::begin(), dict, QList< T >::end(), index, int, QList< T >::last(), and split().
Referenced by query().
00365 { 00366 QStringList lst; 00367 QStringList terms = split( term ); 00368 QStringList::Iterator iter; 00369 00370 for(QHash<QString, Entry*>::Iterator it = dict.begin(); it != dict.end(); ++it) { 00371 int index = 0; 00372 bool found = false; 00373 QString text( it.key() ); 00374 for ( iter = terms.begin(); iter != terms.end(); ++iter ) { 00375 if ( *iter == QLatin1String("*") ) { 00376 found = true; 00377 continue; 00378 } 00379 if ( iter == terms.begin() && (*iter)[0] != text[0] ) { 00380 found = false; 00381 break; 00382 } 00383 index = text.indexOf( *iter, index ); 00384 if ( *iter == terms.last() && index != (int)text.length()-1 ) { 00385 index = text.lastIndexOf( *iter ); 00386 if ( index != (int)text.length() - (int)(*iter).length() ) { 00387 found = false; 00388 break; 00389 } 00390 } 00391 if ( index != -1 ) { 00392 found = true; 00393 index += (*iter).length(); 00394 continue; 00395 } else { 00396 found = false; 00397 break; 00398 } 00399 } 00400 if ( found ) 00401 lst << text; 00402 } 00403 00404 return lst; 00405 }
Here is the call graph for this function:

| QStringList Index::split | ( | const QString & | ) | [private] |
Definition at line 407 of file index.cpp.
References i, QString::indexOf(), j, l, QString::length(), QString::mid(), and QString::startsWith().
Referenced by getWildcardTerms().
00408 { 00409 QStringList lst; 00410 int j = 0; 00411 int i = str.indexOf(QLatin1Char('*'), j ); 00412 00413 if (str.startsWith(QLatin1String("*"))) 00414 lst << QLatin1String("*"); 00415 00416 while ( i != -1 ) { 00417 if ( i > j && i <= (int)str.length() ) { 00418 lst << str.mid( j, i - j ); 00419 lst << QLatin1String("*"); 00420 } 00421 j = i + 1; 00422 i = str.indexOf(QLatin1Char('*'), j ); 00423 } 00424 00425 int l = str.length() - 1; 00426 if ( str.mid( j, l - j + 1 ).length() > 0 ) 00427 lst << str.mid( j, l - j + 1 ); 00428 00429 return lst; 00430 }
Here is the call graph for this function:

| QVector< Document > Index::setupDummyTerm | ( | const QStringList & | ) | [private] |
Definition at line 432 of file index.cpp.
References QVector< T >::append(), QList< T >::append(), QList< T >::begin(), QVector< T >::begin(), QList< T >::count(), dict, QVector< T >::end(), QList< T >::end(), QVector< T >::indexOf(), qSort(), and t.
Referenced by query().
00433 { 00434 QList<Term> termList; 00435 for (QStringList::ConstIterator it = terms.begin(); it != terms.end(); ++it) { 00436 Entry *e = 0; 00437 if ( dict[ *it ] ) { 00438 e = dict[ *it ]; 00439 termList.append( Term( *it, e->documents.count(), e->documents ) ); 00440 } 00441 } 00442 QVector<Document> maxList(0); 00443 if ( !termList.count() ) 00444 return maxList; 00445 qSort(termList); 00446 00447 maxList = termList.takeLast().documents; 00448 for(QList<Term>::Iterator it = termList.begin(); it != termList.end(); ++it) { 00449 Term *t = &(*it); 00450 QVector<Document> docs = t->documents; 00451 for (QVector<Document>::iterator docIt = docs.begin(); docIt != docs.end(); ++docIt ) { 00452 if ( maxList.indexOf( *docIt ) == -1 ) 00453 maxList.append( *docIt ); 00454 } 00455 } 00456 return maxList; 00457 }
Here is the call graph for this function:

| bool Index::searchForPattern | ( | const QStringList & | , | |
| const QStringList & | , | |||
| const QString & | ||||
| ) | [private] |
Definition at line 466 of file index.cpp.
References a, b, QList< T >::begin(), buf, buildMiniDict(), c, QFile::close(), constData(), QList< T >::count(), QList< T >::end(), i, int, j, QString::length(), miniDict, QFile::open(), positions, qWarning(), QIODevice::ReadOnly, s, QUrl::toLocalFile(), QString::unicode(), and wordNum.
Referenced by query().
00467 { 00468 QUrl url(fileName); 00469 QString fName = url.toLocalFile(); 00470 QFile file( fName ); 00471 if ( !file.open( QFile::ReadOnly ) ) { 00472 qWarning( (QLatin1String("cannot open file ") + fName).toAscii().constData() ); 00473 return false; 00474 } 00475 00476 wordNum = 3; 00477 miniDict.clear(); 00478 QStringList::ConstIterator cIt = words.begin(); 00479 for ( ; cIt != words.end(); ++cIt ) 00480 miniDict.insert( *cIt, new PosEntry( 0 ) ); 00481 00482 QTextStream s( &file ); 00483 QString text = s.readAll(); 00484 bool valid = true; 00485 const QChar *buf = text.unicode(); 00486 QChar str[64]; 00487 QChar c = buf[0]; 00488 int j = 0; 00489 int i = 0; 00490 while ( j < text.length() ) { 00491 if ( c == QLatin1Char('<') || c == QLatin1Char('&') ) { 00492 valid = false; 00493 if ( i > 1 ) 00494 buildMiniDict( QString(str,i) ); 00495 i = 0; 00496 c = buf[++j]; 00497 continue; 00498 } 00499 if ( ( c == QLatin1Char('>') || c == QLatin1Char(';') ) && !valid ) { 00500 valid = true; 00501 c = buf[++j]; 00502 continue; 00503 } 00504 if ( !valid ) { 00505 c = buf[++j]; 00506 continue; 00507 } 00508 if ( ( c.isLetterOrNumber() || c == QLatin1Char('_') ) && i < 63 ) { 00509 str[i] = c.toLower(); 00510 ++i; 00511 } else { 00512 if ( i > 1 ) 00513 buildMiniDict( QString(str,i) ); 00514 i = 0; 00515 } 00516 c = buf[++j]; 00517 } 00518 if ( i > 1 ) 00519 buildMiniDict( QString(str,i) ); 00520 file.close(); 00521 00522 QStringList::ConstIterator patIt = patterns.begin(); 00523 QStringList wordLst; 00524 QList<uint> a, b; 00525 QList<uint>::iterator aIt; 00526 for ( ; patIt != patterns.end(); ++patIt ) { 00527 wordLst = (*patIt).split(QLatin1Char(' ')); 00528 a = miniDict[ wordLst[0] ]->positions; 00529 for ( int j = 1; j < (int)wordLst.count(); ++j ) { 00530 b = miniDict[ wordLst[j] ]->positions; 00531 aIt = a.begin(); 00532 while ( aIt != a.end() ) { 00533 if ( b.contains( *aIt + 1 )) { 00534 (*aIt)++; 00535 ++aIt; 00536 } else { 00537 aIt = a.erase( aIt ); 00538 } 00539 } 00540 } 00541 } 00542 if ( a.count() ) 00543 return true; 00544 return false; 00545 }
Here is the call graph for this function:

| void Index::buildMiniDict | ( | const QString & | ) | [private] |
Definition at line 156 of file index.cpp.
References QRegExp::cap(), Qt::CaseInsensitive, QRegExp::indexIn(), QString::indexOf(), QString::isEmpty(), QString::mid(), s, QFile::seek(), start, and QString::toLower().
Referenced by parseDocument().
00157 { 00158 QTextStream s(file); 00159 QString contents = s.readAll(); 00160 00161 QString encoding; 00162 int start = contents.indexOf("<meta", 0, Qt::CaseInsensitive); 00163 if (start > 0) { 00164 int end = contents.indexOf(">", start); 00165 QString meta = contents.mid(start+5, end-start); 00166 meta = meta.toLower(); 00167 QRegExp r("charset=([^\"\\s]+)"); 00168 if (r.indexIn(meta) != -1) { 00169 encoding = r.cap(1); 00170 } 00171 } 00172 00173 file->seek(0); 00174 if (encoding.isEmpty()) 00175 return "utf-8"; 00176 return encoding; 00177 }
Here is the call graph for this function:

| char* Index::zName |
Definition at line 832 of file sqliteInt.h.
| int Index::nColumn |
Definition at line 833 of file sqliteInt.h.
| int* Index::aiColumn |
Definition at line 834 of file sqliteInt.h.
| unsigned* Index::aiRowEst |
Definition at line 835 of file sqliteInt.h.
Definition at line 836 of file sqliteInt.h.
| int Index::tnum |
Definition at line 837 of file sqliteInt.h.
Definition at line 838 of file sqliteInt.h.
Definition at line 839 of file sqliteInt.h.
| char* Index::zColAff |
Definition at line 840 of file sqliteInt.h.
Definition at line 841 of file sqliteInt.h.
Definition at line 842 of file sqliteInt.h.
Definition at line 843 of file sqliteInt.h.
| char** Index::azColl |
Definition at line 844 of file sqliteInt.h.
QStringList Index::docList [private] |
Definition at line 100 of file index.h.
Referenced by Index(), makeIndex(), query(), readDocumentList(), setDocList(), setupDocumentList(), and writeDocumentList().
QHash<QString, Entry*> Index::dict [private] |
Definition at line 101 of file index.h.
Referenced by getWildcardTerms(), insertInDict(), query(), readDict(), setupDummyTerm(), and writeDict().
QHash<QString, PosEntry*> Index::miniDict [private] |
uint Index::wordNum [private] |
QString Index::docPath [private] |
QString Index::dictFile [private] |
Definition at line 105 of file index.h.
Referenced by readDict(), setDictionaryFile(), and writeDict().
QString Index::docListFile [private] |
Definition at line 105 of file index.h.
Referenced by readDocumentList(), setDocListFile(), and writeDocumentList().
bool Index::alreadyHaveDocList [private] |
bool Index::lastWindowClosed [private] |
1.5.1