diff --git a/libsearch/index/document.cpp b/libsearch/index/document.cpp index 92cb446..9dbf7fe 100644 --- a/libsearch/index/document.cpp +++ b/libsearch/index/document.cpp @@ -23,7 +23,7 @@ void Document::setData(QString data) m_document->set_data(data.toStdString()); } -void Document::addterm(std::string term,QVector offset, int weight) +void Document::addPosting(std::string term,QVector offset, int weight) { if(term == "") return; @@ -36,6 +36,13 @@ void Document::addterm(std::string term,QVector offset, int weight) } } +void Document::addTerm(QString term) +{ + if(term.isEmpty()) + return; + m_document->add_term(term.toStdString()); +} + void Document::addValue(QString value) { m_document->add_value(1,value.toStdString()); @@ -49,7 +56,6 @@ void Document::setUniqueTerm(QString term) m_unique_term = new QString(term); } - std::string Document::getUniqueTerm() { // qDebug()<<"m_unique_term!"<<*m_unique_term; diff --git a/libsearch/index/document.h b/libsearch/index/document.h index 96d5ee1..319c209 100644 --- a/libsearch/index/document.h +++ b/libsearch/index/document.h @@ -12,7 +12,8 @@ public: Document(); ~Document(); void setData(QString data); - void addterm(std::string term, QVector offset, int weight =1); + void addPosting(std::string term, QVector offset, int weight =1); + void addTerm(QString term); void addValue(QString value); void setUniqueTerm(QString term); std::string getUniqueTerm(); diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 488b13a..2dfe68d 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -216,6 +216,7 @@ Document IndexGenerator::GenerateDocument(const QVector &list) } QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath)); + QString upTerm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath.section("/",0,-2,QString::SectionIncludeLeadingSep))); // QString uniqueterm1 = QString::fromStdString(QCryptographicHash::hash(sourcePath.toUtf8(),QCryptographicHash::Md5).toStdString()); /*--------------------------------------------------------------------*/ //QByteArray 和 QString 之间会进行隐式转换,造成字符串被截断等意想不到的后果!!!!!!! zpf @@ -229,6 +230,7 @@ Document IndexGenerator::GenerateDocument(const QVector &list) Document doc; doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); + doc.addTerm(upTerm); doc.addValue(list.at(2)); QStringList temp; temp.append(index_text); @@ -244,14 +246,17 @@ Document IndexGenerator::GenerateContentDocument(const QString &path) QString content; FileReader::getTextContent(path,content); QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path)); + QString upTerm = QString::fromStdString(FileUtils::makeDocUterm(path.section("/",0,-2,QString::SectionIncludeLeadingSep))); + QVector term = ChineseSegmentation::getInstance()->callSegement(&content); Document doc; doc.setData(content); doc.setUniqueTerm(uniqueterm); + doc.addTerm(upTerm); doc.addValue(path); for(int i = 0;i(term.at(i).weight)); + doc.addPosting(term.at(i).word,term.at(i).offsets,static_cast(term.at(i).weight)); } return doc;