ukui-search/libsearch/index/document.cpp

74 lines
1.4 KiB
C++
Raw Normal View History

2020-12-30 15:31:36 +08:00
#include "document.h"
#include <QDebug>
Document::Document()
{
m_document = new Xapian::Document;
}
Document::~Document()
{
// if(m_document)
// delete m_document;
// if(m_index_text)
// delete m_index_text;
// if(m_unique_term)
// delete m_unique_term;
}
void Document::setData(QString data)
{
if(data.isEmpty())
return;
m_document->set_data(data.toStdString());
}
void Document::addterm(std::string term,QVector<size_t> offset, int weight)
2020-12-30 15:31:36 +08:00
{
2021-01-03 16:01:35 +08:00
if(term == "")
2020-12-30 15:31:36 +08:00
return;
2021-01-03 16:01:35 +08:00
if(term.length() > 240)
term = QString::fromStdString(term).left(30).toStdString();
for(size_t i : offset)
{
m_document->add_posting(term,i,weight);
}
2020-12-30 15:31:36 +08:00
}
void Document::addValue(QString value)
{
m_document->add_value(1,value.toStdString());
}
void Document::setUniqueTerm(QString term)
{
if(term.isEmpty())
return;
m_document->add_term(term.toStdString());
2020-12-30 15:31:36 +08:00
m_unique_term = new QString(term);
}
std::string Document::getUniqueTerm()
{
// qDebug()<<"m_unique_term!"<<*m_unique_term;
return m_unique_term->toStdString();
}
void Document::setIndexText(QStringList indexText)
{
// QStringList indexTextList = indexText;
m_index_text = new QStringList(indexText);
}
QStringList Document::getIndexText()
{
return *m_index_text;
}
Xapian::Document Document::getXapianDocument()
{
return *m_document;
}