tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp
changeset 30 5dc02b23752f
parent 19 fcece45ef507
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 
    41 
       
    42 #include "qclucenefieldnames_p.h"
    42 #include "qhelpenginecore.h"
    43 #include "qhelpenginecore.h"
    43 #include "qhelp_global.h"
    44 #include "qhelp_global.h"
    44 #include "fulltextsearch/qhits_p.h"
    45 #include "fulltextsearch/qhits_p.h"
    45 #include "fulltextsearch/qquery_p.h"
    46 #include "fulltextsearch/qquery_p.h"
    46 #include "fulltextsearch/qanalyzer_p.h"
    47 #include "fulltextsearch/qanalyzer_p.h"
   404         if(!data.isEmpty()) {
   405         if(!data.isEmpty()) {
   405             QString parsedData = parseData();
   406             QString parsedData = parseData();
   406             QString parsedTitle = QHelpGlobal::documentTitle(data);
   407             QString parsedTitle = QHelpGlobal::documentTitle(data);
   407 
   408 
   408             if(!parsedData.isEmpty()) {
   409             if(!parsedData.isEmpty()) {
   409                 document->add(new QCLuceneField(QLatin1String("content"),
   410                 document->add(new QCLuceneField(ContentField,
   410                     parsedData,QCLuceneField::INDEX_TOKENIZED));
   411                     parsedData,QCLuceneField::INDEX_TOKENIZED));
   411                 document->add(new QCLuceneField(QLatin1String("path"), fileName,
   412                 document->add(new QCLuceneField(PathField, fileName,
   412                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   413                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   413                 document->add(new QCLuceneField(QLatin1String("title"), parsedTitle,
   414                 document->add(new QCLuceneField(TitleField, parsedTitle,
   414                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   415                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   415                 document->add(new QCLuceneField(QLatin1String("titleTokenized"), parsedTitle,
   416                 document->add(new QCLuceneField(TitleTokenizedField, parsedTitle,
   416                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
   417                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
   417                 document->add(new QCLuceneField(QLatin1String("namespace"), namespaceName,
   418                 document->add(new QCLuceneField(NamespaceField, namespaceName,
   418                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   419                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_UNTOKENIZED));
   419                 document->add(new QCLuceneField(QLatin1String("attribute"), attributes,
   420                 document->add(new QCLuceneField(AttributeField, attributes,
   420                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
   421                     QCLuceneField::STORE_YES | QCLuceneField::INDEX_TOKENIZED));
   421                 return true;
   422                 return true;
   422             }
   423             }
   423         }
   424         }
   424 
   425 
   713                         removeDocuments(indexPath, namespaceName);
   714                         removeDocuments(indexPath, namespaceName);
   714                     }
   715                     }
   715 
   716 
   716                     if (indexMap.contains(namespaceName)) {
   717                     if (indexMap.contains(namespaceName)) {
   717                         // make sure we really have content indexed for namespace
   718                         // make sure we really have content indexed for namespace
   718                         // NOTE: Extra variable just for GCC 3.3.5
   719                         QCLuceneTermQuery query(QCLuceneTerm(NamespaceField, namespaceName));
   719                         QLatin1String key("namespace");
       
   720                         QCLuceneTermQuery query(QCLuceneTerm(key, namespaceName));
       
   721                         QCLuceneIndexSearcher indexSearcher(indexPath);
   720                         QCLuceneIndexSearcher indexSearcher(indexPath);
   722                         QCLuceneHits hits = indexSearcher.search(query);
   721                         QCLuceneHits hits = indexSearcher.search(query);
   723                         if (hits.length() <= 0)
   722                         if (hits.length() <= 0)
   724                             indexMap.remove(namespaceName);
   723                             indexMap.remove(namespaceName);
   725                     }
   724                     }
   849 {
   848 {
   850     if (namespaceName.isEmpty() || QCLuceneIndexReader::isLocked(indexPath))
   849     if (namespaceName.isEmpty() || QCLuceneIndexReader::isLocked(indexPath))
   851         return;
   850         return;
   852 
   851 
   853     QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath);
   852     QCLuceneIndexReader reader = QCLuceneIndexReader::open(indexPath);
   854     reader.deleteDocuments(QCLuceneTerm(QLatin1String("namespace"),
   853     reader.deleteDocuments(QCLuceneTerm(NamespaceField, namespaceName));
   855         namespaceName));
       
   856 
   854 
   857     reader.close();
   855     reader.close();
   858 }
   856 }
   859 
   857 
   860 bool QHelpSearchIndexWriter::writeIndexMap(QHelpEngineCore &engine,
   858 bool QHelpSearchIndexWriter::writeIndexMap(QHelpEngineCore &engine,