Merge pull request #73 from iaom/0112-dev

[Fix] Delete folder won't success.
This commit is contained in:
张佳萍 2021-01-13 11:05:19 +08:00 committed by GitHub
commit 2e025cfdd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -23,7 +23,7 @@ void Document::setData(QString data)
m_document->set_data(data.toStdString()); m_document->set_data(data.toStdString());
} }
void Document::addterm(std::string term,QVector<size_t> offset, int weight) void Document::addPosting(std::string term,QVector<size_t> offset, int weight)
{ {
if(term == "") if(term == "")
return; return;
@ -36,6 +36,13 @@ void Document::addterm(std::string term,QVector<size_t> offset, int weight)
} }
} }
void Document::addTerm(QString term)
{
if(term.isEmpty())
return;
m_document->add_term(term.toStdString());
}
void Document::addValue(QString value) void Document::addValue(QString value)
{ {
m_document->add_value(1,value.toStdString()); m_document->add_value(1,value.toStdString());
@ -49,7 +56,6 @@ void Document::setUniqueTerm(QString term)
m_unique_term = new QString(term); m_unique_term = new QString(term);
} }
std::string Document::getUniqueTerm() std::string Document::getUniqueTerm()
{ {
// qDebug()<<"m_unique_term!"<<*m_unique_term; // qDebug()<<"m_unique_term!"<<*m_unique_term;

View File

@ -12,7 +12,8 @@ public:
Document(); Document();
~Document(); ~Document();
void setData(QString data); void setData(QString data);
void addterm(std::string term, QVector<size_t> offset, int weight =1); void addPosting(std::string term, QVector<size_t> offset, int weight =1);
void addTerm(QString term);
void addValue(QString value); void addValue(QString value);
void setUniqueTerm(QString term); void setUniqueTerm(QString term);
std::string getUniqueTerm(); std::string getUniqueTerm();

View File

@ -216,6 +216,7 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
} }
QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath)); 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()); // QString uniqueterm1 = QString::fromStdString(QCryptographicHash::hash(sourcePath.toUtf8(),QCryptographicHash::Md5).toStdString());
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
//QByteArray 和 QString 之间会进行隐式转换,造成字符串被截断等意想不到的后果!!!!!!! zpf //QByteArray 和 QString 之间会进行隐式转换,造成字符串被截断等意想不到的后果!!!!!!! zpf
@ -229,6 +230,7 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
Document doc; Document doc;
doc.setData(sourcePath); doc.setData(sourcePath);
doc.setUniqueTerm(uniqueterm); doc.setUniqueTerm(uniqueterm);
doc.addTerm(upTerm);
doc.addValue(list.at(2)); doc.addValue(list.at(2));
QStringList temp; QStringList temp;
temp.append(index_text); temp.append(index_text);
@ -244,14 +246,17 @@ Document IndexGenerator::GenerateContentDocument(const QString &path)
QString content; QString content;
FileReader::getTextContent(path,content); FileReader::getTextContent(path,content);
QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path)); QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(path));
QString upTerm = QString::fromStdString(FileUtils::makeDocUterm(path.section("/",0,-2,QString::SectionIncludeLeadingSep)));
QVector<SKeyWord> term = ChineseSegmentation::getInstance()->callSegement(&content); QVector<SKeyWord> term = ChineseSegmentation::getInstance()->callSegement(&content);
Document doc; Document doc;
doc.setData(content); doc.setData(content);
doc.setUniqueTerm(uniqueterm); doc.setUniqueTerm(uniqueterm);
doc.addTerm(upTerm);
doc.addValue(path); doc.addValue(path);
for(int i = 0;i<term.size();++i) for(int i = 0;i<term.size();++i)
{ {
doc.addterm(term.at(i).word,term.at(i).offsets,static_cast<int>(term.at(i).weight)); doc.addPosting(term.at(i).word,term.at(i).offsets,static_cast<int>(term.at(i).weight));
} }
return doc; return doc;