ukui-search/libsearch/index/document.cpp

66 lines
1.2 KiB
C++
Raw Normal View History

2020-12-30 15:31:36 +08:00
#include "document.h"
#include <QDebug>
Document::Document()
{
}
void Document::setData(QString data)
{
if(data.isEmpty())
return;
m_document.set_data(data.toStdString());
2020-12-30 15:31:36 +08:00
}
2021-01-13 11:02:15 +08:00
void Document::addPosting(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
}
2021-01-13 11:02:15 +08:00
void Document::addTerm(QString term)
{
if(term.isEmpty())
return;
m_document.add_term(term.toStdString());
2021-01-13 11:02:15 +08:00
}
2020-12-30 15:31:36 +08:00
void Document::addValue(QString value)
{
m_document.add_value(1,value.toStdString());
2020-12-30 15:31:36 +08:00
}
void Document::setUniqueTerm(QString term)
{
if(term.isEmpty())
return;
m_document.add_term(term.toStdString());
m_unique_term = std::move(term);
2020-12-30 15:31:36 +08:00
}
std::string Document::getUniqueTerm()
{
return m_unique_term.toStdString();
2020-12-30 15:31:36 +08:00
}
void Document::setIndexText(QStringList indexText)
{
m_index_text = std::move(indexText);
2020-12-30 15:31:36 +08:00
}
QStringList Document::getIndexText()
{
return m_index_text;
2020-12-30 15:31:36 +08:00
}
Xapian::Document Document::getXapianDocument()
{
return m_document;
2020-12-30 15:31:36 +08:00
}