2021-01-29 11:43:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2020-12-30 15:31:36 +08:00
|
|
|
#include "document.h"
|
|
|
|
#include <QDebug>
|
2021-12-14 14:43:35 +08:00
|
|
|
using namespace UkuiSearch;
|
2021-05-17 14:47:39 +08:00
|
|
|
void Document::setData(QString &data) {
|
2020-12-30 15:31:36 +08:00
|
|
|
if(data.isEmpty())
|
|
|
|
return;
|
2021-01-19 10:44:28 +08:00
|
|
|
m_document.set_data(data.toStdString());
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void Document::addPosting(std::string term, QVector<size_t> offset, int weight) {
|
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();
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
for(size_t i : offset) {
|
|
|
|
m_document.add_posting(term, i, weight);
|
2021-01-02 17:21:38 +08:00
|
|
|
}
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 15:50:19 +08:00
|
|
|
void Document::addPosting(std::string &term, std::vector<size_t> &offset, int weight) {
|
2021-05-22 09:18:35 +08:00
|
|
|
if(term == "")
|
|
|
|
return;
|
|
|
|
if(term.length() > 240)
|
|
|
|
term = QString::fromStdString(term).left(30).toStdString();
|
|
|
|
|
|
|
|
for(size_t i : offset) {
|
|
|
|
m_document.add_posting(term, i, weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void Document::addPosting(std::string term, unsigned int offset, int weight) {
|
2021-02-20 16:56:30 +08:00
|
|
|
if(term == "")
|
|
|
|
return;
|
|
|
|
if(term.length() > 240)
|
|
|
|
term = QString::fromStdString(term).left(30).toStdString();
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
m_document.add_posting(term, offset, weight);
|
2021-02-20 16:56:30 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void Document::addTerm(QString term) {
|
2021-01-13 11:02:15 +08:00
|
|
|
if(term.isEmpty())
|
|
|
|
return;
|
2021-01-19 10:44:28 +08:00
|
|
|
m_document.add_term(term.toStdString());
|
2021-01-13 11:02:15 +08:00
|
|
|
}
|
|
|
|
|
2021-06-23 15:50:19 +08:00
|
|
|
void Document::addTerm(std::string term) {
|
|
|
|
if(term.empty())
|
|
|
|
return;
|
|
|
|
m_document.add_term(term);
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:20:16 +08:00
|
|
|
void Document::addValue(unsigned slot, QString value)
|
|
|
|
{
|
|
|
|
m_document.add_value(slot, value.toStdString());
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2022-04-19 09:16:20 +08:00
|
|
|
void Document::addSortableSerialiseValue(unsigned slot, QString value)
|
|
|
|
{
|
|
|
|
m_document.add_value(slot, Xapian::sortable_serialise(value.toDouble()));
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void Document::setUniqueTerm(QString term) {
|
2020-12-30 15:31:36 +08:00
|
|
|
if(term.isEmpty())
|
|
|
|
return;
|
2021-01-19 10:44:28 +08:00
|
|
|
m_document.add_term(term.toStdString());
|
2021-01-19 19:26:39 +08:00
|
|
|
|
|
|
|
// m_unique_term = new QString(term);
|
2021-06-23 15:50:19 +08:00
|
|
|
m_unique_term = std::move(term.toStdString());
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
2021-06-23 15:50:19 +08:00
|
|
|
|
|
|
|
void Document::setUniqueTerm(std::string term) {
|
|
|
|
if(term.empty())
|
|
|
|
return;
|
|
|
|
m_document.add_term(term);
|
|
|
|
m_unique_term = term;
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
std::string Document::getUniqueTerm() {
|
2021-01-19 19:26:39 +08:00
|
|
|
// qDebug()<<"m_unique_term!"<<*m_unique_term;
|
|
|
|
// qDebug() << QString::fromStdString(m_unique_term.toStdString());
|
2021-06-23 15:50:19 +08:00
|
|
|
return m_unique_term;//.toStdString();
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void Document::setIndexText(QStringList indexText) {
|
2021-01-19 19:26:39 +08:00
|
|
|
// QStringList indexTextList = indexText;
|
|
|
|
// m_index_text = new QStringList(indexText);
|
2021-01-19 10:44:28 +08:00
|
|
|
m_index_text = std::move(indexText);
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
QStringList Document::getIndexText() {
|
2021-01-19 10:44:28 +08:00
|
|
|
return m_index_text;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Document Document::getXapianDocument() {
|
2021-01-19 10:44:28 +08:00
|
|
|
return m_document;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
2021-11-02 15:44:12 +08:00
|
|
|
|
|
|
|
void Document::reuireDeleted()
|
|
|
|
{
|
|
|
|
m_shouldDelete = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Document::isRequiredDeleted()
|
|
|
|
{
|
|
|
|
return m_shouldDelete;
|
|
|
|
}
|