本文整理汇总了C++中xapian::Document::add_value方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::add_value方法的具体用法?C++ Document::add_value怎么用?C++ Document::add_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xapian::Document
的用法示例。
在下文中一共展示了Document::add_value方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveMessage
void HistoryLogger::saveMessage(const Message* message)
{
if (message->flags() & MESSAGE_FLAG_ALARM)
return;
Xapian::Document doc;
quint32 flags = message->flags();
std::string plainText(message->plainText().toUtf8());
std::string confUser(message->getConfUser().constData());
std::string data;
if (flags & MESSAGE_FLAG_RTF)
data = message->rtfText().constData();
else
data = plainText;
std::cout << "HistoryLogger::saveMessage data = " << data << std::endl;
doc.set_data(data);
Xapian::TermGenerator termGen;
termGen.set_stemmer(Xapian::Stem("ru"));
termGen.set_document(doc);
termGen.index_text(plainText);
doc.add_value(0, message->dateTime().toString("yyyyMMdd").toStdString());
doc.add_value(1, message->dateTime().toString("hhmmss").toStdString());
doc.add_value(2, QString::number(flags, 16).toStdString());
doc.add_value(3, message->type() == Message::Outgoing? "o" : "i");
doc.add_value(4, confUser);
database->add_document(doc);
database->flush();
}
示例2: setDocumentData
void XapianIndex::setDocumentData(const DocumentInfo &info, Xapian::Document &doc,
const string &language) const
{
time_t timeT = TimeConverter::fromTimestamp(info.getTimestamp());
// Add this value to allow sorting by date
doc.add_value(0, StringManip::integerToBinaryString((uint32_t)timeT));
DocumentInfo docCopy(info);
docCopy.setLanguage(language);
doc.set_data(XapianDatabase::propsToRecord(&docCopy));
}
示例3: setDocumentData
void XapianIndex::setDocumentData(const DocumentInfo &info, Xapian::Document &doc,
const string &language) const
{
string title(info.getTitle());
string timestamp(info.getTimestamp());
char timeStr[64];
time_t timeT = TimeConverter::fromTimestamp(timestamp);
// Set the document data omindex-style
string record = "url=";
record += info.getLocation();
// The sample will be generated at query time
record += "\nsample=";
record += "\ncaption=";
if (badField(title) == true)
{
// Modify the title if necessary
string::size_type pos = title.find("=");
while (pos != string::npos)
{
title[pos] = ' ';
pos = title.find("=", pos + 1);
}
#ifdef DEBUG
cout << "XapianIndex::setDocumentData: modified title" << endl;
#endif
}
record += title;
record += "\ntype=";
record += info.getType();
// Append a timestamp, in a format compatible with Omega
record += "\nmodtime=";
snprintf(timeStr, 64, "%ld", timeT);
record += timeStr;
// ...and the language
record += "\nlanguage=";
record += StringManip::toLowerCase(language);
#ifdef DEBUG
cout << "XapianIndex::setDocumentData: document data is " << record << endl;
#endif
doc.set_data(record);
// Add this value to allow sorting by date
doc.add_value(0, StringManip::integerToBinaryString((uint32_t)timeT));
}
示例4: setDocumentData
void XapianIndex::setDocumentData(Xapian::Document &doc, const DocumentInfo &info,
const string &language) const
{
string title(info.getTitle());
string timestamp(info.getTimestamp());
char timeStr[64];
// Set the document data omindex-style
string record = "url=";
record += info.getLocation();
// The sample will be generated at query time
record += "\nsample=";
record += "\ncaption=";
if (badField(title) == true)
{
// Modify the title if necessary
string::size_type pos = title.find("=");
while (pos != string::npos)
{
title[pos] = ' ';
pos = title.find("=", pos + 1);
}
#ifdef DEBUG
cout << "XapianIndex::setDocumentData: modified title" << endl;
#endif
}
record += title;
record += "\ntype=";
record += info.getType();
// Append a timestamp
record += "\ntimestamp=";
record += timestamp;
// ...and the language
record += "\nlanguage=";
record += language;
#ifdef DEBUG
cout << "XapianIndex::setDocumentData: document data is " << record << endl;
#endif
doc.set_data(record);
// Add this value to allow sorting by date
snprintf(timeStr, 64, "%d", TimeConverter::fromTimestamp(timestamp));
doc.add_value(0, timeStr);
}
示例5: db
bool
DatabaseWrite::rebuild (GList *cpt_list)
{
string old_path = m_dbPath + "_old";
string rebuild_path = m_dbPath + "_rb";
string db_locale;
// Create the rebuild directory
if (g_mkdir_with_parents (rebuild_path.c_str (), 0755) != 0) {
g_warning ("Unable to create database rebuild directory.");
return false;
}
// check if old unrequired version of db still exists on filesystem
if (g_file_test (old_path.c_str (), G_FILE_TEST_EXISTS)) {
g_warning ("Existing xapian old db was not cleaned previously: '%s'.", old_path.c_str ());
as_utils_delete_dir_recursive (old_path.c_str ());
}
// check if old unrequired version of db still exists on filesystem
if (g_file_test (rebuild_path.c_str (), G_FILE_TEST_EXISTS)) {
g_debug ("Removing old rebuild-dir from previous database rebuild.");
as_utils_delete_dir_recursive (rebuild_path.c_str ());
}
Xapian::WritableDatabase db (rebuild_path, Xapian::DB_CREATE_OR_OVERWRITE);
Xapian::TermGenerator term_generator;
term_generator.set_database(db);
try {
/* this tests if we have spelling suggestions (there must be
* a better way?!?) - this is needed as inmemory does not have
* spelling corrections, but it allows setting the flag and will
* raise a exception much later
*/
db.add_spelling("test");
db.remove_spelling("test");
/* this enables the flag for it (we only reach this line if
* the db supports spelling suggestions)
*/
term_generator.set_flags(Xapian::TermGenerator::FLAG_SPELLING);
} catch (const Xapian::UnimplementedError &error) {
// Ignore
}
for (GList *list = cpt_list; list != NULL; list = list->next) {
AsComponent *cpt = (AsComponent*) list->data;
Xapian::Document doc;
term_generator.set_document (doc);
doc.set_data (as_component_get_name (cpt));
// Sanity check
if (!as_component_has_install_candidate (cpt)) {
g_warning ("Skipped component '%s' from inclusion into database: Does not have an installation candidate.",
as_component_get_id (cpt));
continue;
}
// Package name
gchar **pkgs = as_component_get_pkgnames (cpt);
if (pkgs != NULL) {
gchar *pkgs_cstr = g_strjoinv (";", pkgs);
string pkgs_str = pkgs_cstr;
doc.add_value (XapianValues::PKGNAMES, pkgs_str);
g_free (pkgs_cstr);
for (uint i = 0; pkgs[i] != NULL; i++) {
string pkgname = pkgs[i];
doc.add_term("AP" + pkgname);
if (pkgname.find ("-") != string::npos) {
// we need this to work around xapian oddness
string tmp = pkgname;
replace (tmp.begin (), tmp.end (), '-', '_');
doc.add_term (tmp);
}
// add packagename as meta-data too
term_generator.index_text_without_positions (pkgname, WEIGHT_PKGNAME);
}
}
// Source package name
const gchar *spkgname_cstr = as_component_get_source_pkgname (cpt);
if (spkgname_cstr != NULL) {
string spkgname = spkgname_cstr;
doc.add_value (XapianValues::SOURCE_PKGNAME, spkgname);
if (!spkgname.empty()) {
doc.add_term("AP" + spkgname);
if (spkgname.find ("-") != string::npos) {
// we need this to work around xapian oddness
string tmp = spkgname;
replace (tmp.begin (), tmp.end (), '-', '_');
doc.add_term (tmp);
}
// add packagename as meta-data too
term_generator.index_text_without_positions (spkgname, WEIGHT_PKGNAME);
}
}
//.........这里部分代码省略.........