mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
Epurate this branch from channels deep search changes
This commit is contained in:
parent
9c38eed648
commit
dcb2bee8cc
@ -1,8 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* RetroShare full text indexing and search implementation based on Xapian *
|
||||
* *
|
||||
* Copyright (C) 2018-2021 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019-2021 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License version 3 as *
|
||||
@ -20,23 +20,16 @@
|
||||
|
||||
#include "deep_search/channelsindex.hpp"
|
||||
#include "deep_search/commonutils.hpp"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "util/rsdebuglevel3.h"
|
||||
|
||||
/*static*/ std::string DeepChannelsIndex::dbDefaultPath()
|
||||
{ return RsAccounts::AccountDirectory() + "/deep_channels_xapian_db"; }
|
||||
|
||||
std::error_condition DeepChannelsIndex::search(
|
||||
uint32_t DeepChannelsIndex::search(
|
||||
const std::string& queryStr,
|
||||
std::vector<DeepChannelsSearchResult>& results, uint32_t maxResults )
|
||||
{
|
||||
RS_DBG3(queryStr);
|
||||
|
||||
results.clear();
|
||||
|
||||
std::unique_ptr<Xapian::Database> dbPtr(
|
||||
DeepSearch::openReadOnlyDatabase(mDbPath) );
|
||||
if(!dbPtr) return std::errc::bad_file_descriptor;
|
||||
DeepSearch::openReadOnlyDatabase(dbPath()) );
|
||||
if(!dbPtr) return 0;
|
||||
|
||||
Xapian::Database& db(*dbPtr);
|
||||
|
||||
@ -70,13 +63,17 @@ std::error_condition DeepChannelsIndex::search(
|
||||
results.push_back(s);
|
||||
}
|
||||
|
||||
return std::error_condition();
|
||||
return static_cast<uint32_t>(results.size());
|
||||
}
|
||||
|
||||
std::error_condition DeepChannelsIndex::indexChannelGroup(
|
||||
const RsGxsChannelGroup& chan )
|
||||
void DeepChannelsIndex::indexChannelGroup(const RsGxsChannelGroup& chan)
|
||||
{
|
||||
RS_DBG4(chan);
|
||||
std::unique_ptr<Xapian::WritableDatabase> dbPtr(
|
||||
DeepSearch::openWritableDatabase(
|
||||
dbPath(), Xapian::DB_CREATE_OR_OPEN ) );
|
||||
if(!dbPtr) return;
|
||||
|
||||
Xapian::WritableDatabase& db(*dbPtr);
|
||||
|
||||
// Set up a TermGenerator that we'll use in indexing.
|
||||
Xapian::TermGenerator termgenerator;
|
||||
@ -97,8 +94,21 @@ std::error_condition DeepChannelsIndex::indexChannelGroup(
|
||||
termgenerator.increase_termpos();
|
||||
termgenerator.index_text(chan.mDescription);
|
||||
|
||||
RsUrl chanUrl; chanUrl
|
||||
.setScheme("retroshare").setPath("/channel")
|
||||
.setQueryKV("id", chan.mMeta.mGroupId.toStdString());
|
||||
const std::string idTerm("Q" + chanUrl.toString());
|
||||
|
||||
chanUrl.setQueryKV("publishTs", std::to_string(chan.mMeta.mPublishTs));
|
||||
chanUrl.setQueryKV("name", chan.mMeta.mGroupName);
|
||||
if(!chan.mMeta.mAuthorId.isNull())
|
||||
chanUrl.setQueryKV("authorId", chan.mMeta.mAuthorId.toStdString());
|
||||
if(chan.mMeta.mSignFlags)
|
||||
chanUrl.setQueryKV( "signFlags",
|
||||
std::to_string(chan.mMeta.mSignFlags) );
|
||||
std::string rsLink(chanUrl.toString());
|
||||
|
||||
// store the RS link so we are able to retrive it on matching search
|
||||
const std::string rsLink(channelIndexId(chan.mMeta.mGroupId));
|
||||
doc.add_value(URL_VALUENO, rsLink);
|
||||
|
||||
// Store some fields for display purposes.
|
||||
@ -107,32 +117,35 @@ std::error_condition DeepChannelsIndex::indexChannelGroup(
|
||||
// We use the identifier to ensure each object ends up in the
|
||||
// database only once no matter how many times we run the
|
||||
// indexer. "Q" prefix is a Xapian convention for unique id term.
|
||||
const std::string idTerm("Q" + rsLink);
|
||||
doc.add_boolean_term(idTerm);
|
||||
|
||||
mWriteQueue.push( [idTerm, doc](Xapian::WritableDatabase& db)
|
||||
{ db.replace_document(idTerm, doc); } );
|
||||
|
||||
return std::error_condition();
|
||||
db.replace_document(idTerm, doc);
|
||||
}
|
||||
|
||||
std::error_condition DeepChannelsIndex::removeChannelFromIndex(
|
||||
const RsGxsGroupId& grpId )
|
||||
void DeepChannelsIndex::removeChannelFromIndex(RsGxsGroupId grpId)
|
||||
{
|
||||
RS_DBG3(grpId);
|
||||
|
||||
// "Q" prefix is a Xapian convention for unique id term.
|
||||
const std::string idTerm("Q" + channelIndexId(grpId));
|
||||
mWriteQueue.push( [idTerm](Xapian::WritableDatabase& db)
|
||||
{ db.delete_document(idTerm); } );
|
||||
RsUrl chanUrl; chanUrl
|
||||
.setScheme("retroshare").setPath("/channel")
|
||||
.setQueryKV("id", grpId.toStdString());
|
||||
std::string idTerm("Q" + chanUrl.toString());
|
||||
|
||||
return std::error_condition();
|
||||
std::unique_ptr<Xapian::WritableDatabase> dbPtr(
|
||||
DeepSearch::openWritableDatabase(
|
||||
dbPath(), Xapian::DB_CREATE_OR_OPEN ) );
|
||||
if(!dbPtr) return;
|
||||
|
||||
Xapian::WritableDatabase& db(*dbPtr);
|
||||
db.delete_document(idTerm);
|
||||
}
|
||||
|
||||
std::error_condition DeepChannelsIndex::indexChannelPost(
|
||||
const RsGxsChannelPost& post )
|
||||
void DeepChannelsIndex::indexChannelPost(const RsGxsChannelPost& post)
|
||||
{
|
||||
RS_DBG4(post);
|
||||
std::unique_ptr<Xapian::WritableDatabase> dbPtr(
|
||||
DeepSearch::openWritableDatabase(
|
||||
dbPath(), Xapian::DB_CREATE_OR_OPEN ) );
|
||||
if(!dbPtr) return;
|
||||
|
||||
Xapian::WritableDatabase& db(*dbPtr);
|
||||
|
||||
// Set up a TermGenerator that we'll use in indexing.
|
||||
Xapian::TermGenerator termgenerator;
|
||||
@ -147,16 +160,21 @@ std::error_condition DeepChannelsIndex::indexChannelPost(
|
||||
termgenerator.index_text(
|
||||
DeepSearch::timetToXapianDate(post.mMeta.mPublishTs), 1, "D" );
|
||||
|
||||
// Avoid indexing RetroShare-gui HTML tags
|
||||
const std::string cleanMsg = DeepSearch::simpleTextHtmlExtract(post.mMsg);
|
||||
termgenerator.index_text(
|
||||
DeepSearch::simpleTextHtmlExtract(post.mMsg), 1, "XD" );
|
||||
// TODO: we should strip out HTML tags instead of skipping indexing
|
||||
// Avoid indexing HTML
|
||||
bool isPlainMsg =
|
||||
post.mMsg[0] != '<' || post.mMsg[post.mMsg.size() - 1] != '>';
|
||||
|
||||
if(isPlainMsg)
|
||||
termgenerator.index_text(post.mMsg, 1, "XD");
|
||||
|
||||
// Index fields without prefixes for general search.
|
||||
termgenerator.index_text(post.mMeta.mMsgName);
|
||||
|
||||
termgenerator.increase_termpos();
|
||||
termgenerator.index_text(cleanMsg);
|
||||
if(isPlainMsg)
|
||||
{
|
||||
termgenerator.increase_termpos();
|
||||
termgenerator.index_text(post.mMsg);
|
||||
}
|
||||
|
||||
for(const RsGxsFile& attachment : post.mFiles)
|
||||
{
|
||||
@ -166,50 +184,47 @@ std::error_condition DeepChannelsIndex::indexChannelPost(
|
||||
termgenerator.index_text(attachment.mName);
|
||||
}
|
||||
|
||||
// store the RS link so we are able to retrive it on matching search
|
||||
const std::string rsLink(postIndexId(post.mMeta.mGroupId, post.mMeta.mMsgId));
|
||||
doc.add_value(URL_VALUENO, rsLink);
|
||||
|
||||
// Store some fields for display purposes.
|
||||
doc.set_data(post.mMeta.mMsgName + "\n" + cleanMsg);
|
||||
|
||||
// We use the identifier to ensure each object ends up in the
|
||||
// database only once no matter how many times we run the
|
||||
// indexer.
|
||||
const std::string idTerm("Q" + rsLink);
|
||||
RsUrl postUrl; postUrl
|
||||
.setScheme("retroshare").setPath("/channel")
|
||||
.setQueryKV("id", post.mMeta.mGroupId.toStdString())
|
||||
.setQueryKV("msgid", post.mMeta.mMsgId.toStdString());
|
||||
std::string idTerm("Q" + postUrl.toString());
|
||||
|
||||
postUrl.setQueryKV("publishTs", std::to_string(post.mMeta.mPublishTs));
|
||||
postUrl.setQueryKV("name", post.mMeta.mMsgName);
|
||||
postUrl.setQueryKV("authorId", post.mMeta.mAuthorId.toStdString());
|
||||
std::string rsLink(postUrl.toString());
|
||||
|
||||
// store the RS link so we are able to retrive it on matching search
|
||||
doc.add_value(URL_VALUENO, rsLink);
|
||||
|
||||
// Store some fields for display purposes.
|
||||
if(isPlainMsg)
|
||||
doc.set_data(post.mMeta.mMsgName + "\n" + post.mMsg);
|
||||
else doc.set_data(post.mMeta.mMsgName);
|
||||
|
||||
doc.add_boolean_term(idTerm);
|
||||
|
||||
mWriteQueue.push( [idTerm, doc](Xapian::WritableDatabase& db)
|
||||
{ db.replace_document(idTerm, doc); } );
|
||||
|
||||
return std::error_condition();
|
||||
db.replace_document(idTerm, doc);
|
||||
}
|
||||
|
||||
std::error_condition DeepChannelsIndex::removeChannelPostFromIndex(
|
||||
const RsGxsGroupId& grpId, const RsGxsMessageId& msgId )
|
||||
{
|
||||
RS_DBG3(grpId, msgId);
|
||||
|
||||
std::string idTerm("Q" + postIndexId(grpId, msgId));
|
||||
mWriteQueue.push( [idTerm](Xapian::WritableDatabase& db)
|
||||
{ db.delete_document(idTerm); } );
|
||||
|
||||
return std::error_condition();
|
||||
}
|
||||
|
||||
/*static*/ std::string DeepChannelsIndex::channelIndexId(RsGxsGroupId grpId)
|
||||
{
|
||||
RsUrl channelIndexId(RsGxsChannels::DEFAULT_CHANNEL_BASE_URL);
|
||||
channelIndexId.setQueryKV(
|
||||
RsGxsChannels::CHANNEL_URL_ID_FIELD, grpId.toStdString() );
|
||||
return channelIndexId.toString();
|
||||
}
|
||||
|
||||
/*static*/ std::string DeepChannelsIndex::postIndexId(
|
||||
void DeepChannelsIndex::removeChannelPostFromIndex(
|
||||
RsGxsGroupId grpId, RsGxsMessageId msgId )
|
||||
{
|
||||
RsUrl postIndexId(RsGxsChannels::DEFAULT_CHANNEL_BASE_URL);
|
||||
postIndexId.setQueryKV(RsGxsChannels::CHANNEL_URL_ID_FIELD, grpId.toStdString());
|
||||
postIndexId.setQueryKV(RsGxsChannels::CHANNEL_URL_MSG_ID_FIELD, msgId.toStdString());
|
||||
return postIndexId.toString();
|
||||
RsUrl postUrl; postUrl
|
||||
.setScheme("retroshare").setPath("/channel")
|
||||
.setQueryKV("id", grpId.toStdString())
|
||||
.setQueryKV("msgid", msgId.toStdString());
|
||||
// "Q" prefix is a Xapian convention for unique id term.
|
||||
std::string idTerm("Q" + postUrl.toString());
|
||||
|
||||
std::unique_ptr<Xapian::WritableDatabase> dbPtr(
|
||||
DeepSearch::openWritableDatabase(
|
||||
dbPath(), Xapian::DB_CREATE_OR_OPEN ) );
|
||||
if(!dbPtr) return;
|
||||
|
||||
Xapian::WritableDatabase& db(*dbPtr);
|
||||
db.delete_document(idTerm);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*******************************************************************************
|
||||
* RetroShare full text indexing and search implementation based on Xapian *
|
||||
* *
|
||||
* Copyright (C) 2018-2021 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019-2021 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License version 3 as *
|
||||
@ -24,8 +24,8 @@
|
||||
|
||||
#include "util/rstime.h"
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
#include "util/rsurl.h"
|
||||
#include "deep_search/commonutils.hpp"
|
||||
|
||||
struct DeepChannelsSearchResult
|
||||
{
|
||||
@ -36,34 +36,28 @@ struct DeepChannelsSearchResult
|
||||
|
||||
struct DeepChannelsIndex
|
||||
{
|
||||
explicit DeepChannelsIndex(const std::string& dbPath) :
|
||||
mDbPath(dbPath), mWriteQueue(dbPath) {}
|
||||
|
||||
/**
|
||||
* @brief Search indexed GXS groups and messages
|
||||
* @param[in] maxResults maximum number of acceptable search results, 0 for
|
||||
* no limits
|
||||
* @return search results count
|
||||
*/
|
||||
std::error_condition search(
|
||||
const std::string& queryStr,
|
||||
std::vector<DeepChannelsSearchResult>& results,
|
||||
uint32_t maxResults = 100 );
|
||||
static uint32_t search( const std::string& queryStr,
|
||||
std::vector<DeepChannelsSearchResult>& results,
|
||||
uint32_t maxResults = 100 );
|
||||
|
||||
std::error_condition indexChannelGroup(const RsGxsChannelGroup& chan);
|
||||
static void indexChannelGroup(const RsGxsChannelGroup& chan);
|
||||
|
||||
std::error_condition removeChannelFromIndex(const RsGxsGroupId& grpId);
|
||||
static void removeChannelFromIndex(RsGxsGroupId grpId);
|
||||
|
||||
std::error_condition indexChannelPost(const RsGxsChannelPost& post);
|
||||
static void indexChannelPost(const RsGxsChannelPost& post);
|
||||
|
||||
std::error_condition removeChannelPostFromIndex(
|
||||
const RsGxsGroupId& grpId, const RsGxsMessageId& msgId );
|
||||
static void removeChannelPostFromIndex(
|
||||
RsGxsGroupId grpId, RsGxsMessageId msgId );
|
||||
|
||||
static std::string dbDefaultPath();
|
||||
static uint32_t indexFile(const std::string& path);
|
||||
|
||||
private:
|
||||
static std::string channelIndexId(RsGxsGroupId grpId);
|
||||
static std::string postIndexId(RsGxsGroupId grpId, RsGxsMessageId msgId);
|
||||
|
||||
enum : Xapian::valueno
|
||||
{
|
||||
@ -74,7 +68,10 @@ private:
|
||||
BAD_VALUENO = Xapian::BAD_VALUENO
|
||||
};
|
||||
|
||||
const std::string mDbPath;
|
||||
|
||||
DeepSearch::StubbornWriteOpQueue mWriteQueue;
|
||||
static const std::string& dbPath()
|
||||
{
|
||||
static const std::string dbDir =
|
||||
RsAccounts::AccountDirectory() + "/deep_channels_xapian_db";
|
||||
return dbDir;
|
||||
}
|
||||
};
|
||||
|
@ -4,8 +4,8 @@
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2021 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019-2021 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* Copyright (C) 2018-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019-2020 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -46,11 +46,6 @@ class RsGxsChannels;
|
||||
extern RsGxsChannels* rsGxsChannels;
|
||||
|
||||
|
||||
/* TODO: At this abstraction level that turtle is used for distant searches
|
||||
* should be an hidden implementation detail. As of today a bit of those
|
||||
* implementation details leaks around because we use TurtleRequestId in this
|
||||
* interface */
|
||||
|
||||
struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData
|
||||
{
|
||||
RsGxsChannelGroup() : mAutoDownload(false) {}
|
||||
@ -113,38 +108,29 @@ struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
|
||||
enum class RsChannelEventCode: uint8_t
|
||||
{
|
||||
UNKNOWN = 0x00,
|
||||
NEW_CHANNEL = 0x01, /// emitted when new channel is received
|
||||
UPDATED_CHANNEL = 0x02, /// emitted when existing channel is updated
|
||||
NEW_MESSAGE = 0x03, /// new message reeived in a particular channel (group and msg id)
|
||||
UPDATED_MESSAGE = 0x04, /// existing message has been updated in a particular channel
|
||||
RECEIVED_PUBLISH_KEY = 0x05, /// publish key for this channel has been received
|
||||
SUBSCRIBE_STATUS_CHANGED = 0x06, /// subscription for channel mChannelGroupId changed.
|
||||
READ_STATUS_CHANGED = 0x07, /// existing message has been read or set to unread
|
||||
|
||||
/** Result for the given group id available for the given turtle request id
|
||||
* @deprecated kept for retrocompatibility with old search system new code
|
||||
* should use @see DISTANT_SEARCH_RESULT instead */
|
||||
RECEIVED_TURTLE_SEARCH_RESULT = 0x08,
|
||||
|
||||
STATISTICS_CHANGED = 0x09, /// stats (nb of supplier friends, how many msgs they have etc) has changed
|
||||
SYNC_PARAMETERS_UPDATED = 0x0a, /// sync and storage times have changed
|
||||
NEW_COMMENT = 0x0b, /// new comment arrived/published. mChannelThreadId gives the ID of the commented message
|
||||
NEW_VOTE = 0x0c, /// new vote arrived/published. mChannelThreadId gives the ID of the votes message comment
|
||||
DELETED_CHANNEL = 0x0d, /// channel was deleted by auto-cleaning system
|
||||
DELETED_POST = 0x0e, /// Post deleted (usually by cleaning)
|
||||
DISTANT_SEARCH_RESULT = 0x0f /// Distant search result received
|
||||
NEW_CHANNEL = 0x01, // emitted when new channel is received
|
||||
UPDATED_CHANNEL = 0x02, // emitted when existing channel is updated
|
||||
NEW_MESSAGE = 0x03, // new message reeived in a particular channel (group and msg id)
|
||||
UPDATED_MESSAGE = 0x04, // existing message has been updated in a particular channel
|
||||
RECEIVED_PUBLISH_KEY = 0x05, // publish key for this channel has been received
|
||||
SUBSCRIBE_STATUS_CHANGED = 0x06, // subscription for channel mChannelGroupId changed.
|
||||
READ_STATUS_CHANGED = 0x07, // existing message has been read or set to unread
|
||||
RECEIVED_DISTANT_SEARCH_RESULT = 0x08, // result for the given group id available for the given turtle request id
|
||||
STATISTICS_CHANGED = 0x09, // stats (nb of supplier friends, how many msgs they have etc) has changed
|
||||
SYNC_PARAMETERS_UPDATED = 0x0a, // sync and storage times have changed
|
||||
NEW_COMMENT = 0x0b, // new comment arrived/published. mChannelThreadId gives the ID of the commented message
|
||||
NEW_VOTE = 0x0c, // new vote arrived/published. mChannelThreadId gives the ID of the votes message comment
|
||||
DELETED_CHANNEL = 0x0d, // channel was deleted by auto-cleaning system
|
||||
};
|
||||
|
||||
struct RsGxsChannelEvent: RsEvent
|
||||
{
|
||||
RsGxsChannelEvent():
|
||||
RsEvent(RsEventType::GXS_CHANNELS),
|
||||
mChannelEventCode(RsChannelEventCode::UNKNOWN) {}
|
||||
RsGxsChannelEvent(): RsEvent(RsEventType::GXS_CHANNELS), mChannelEventCode(RsChannelEventCode::UNKNOWN) {}
|
||||
|
||||
RsChannelEventCode mChannelEventCode;
|
||||
RsGxsGroupId mChannelGroupId;
|
||||
RsGxsMessageId mChannelMsgId;
|
||||
RsGxsMessageId mChannelThreadId;
|
||||
RsGxsMessageId mChannelThreadId;
|
||||
|
||||
///* @see RsEvent @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
|
||||
@ -157,14 +143,13 @@ struct RsGxsChannelEvent: RsEvent
|
||||
}
|
||||
};
|
||||
|
||||
/** This event is used to factor multiple search results notifications in a
|
||||
* single event.*/
|
||||
struct RS_DEPRECATED_FOR(RsGxsChannelDistantSearchResultEvent)
|
||||
RsGxsChannelSearchResultEvent: RsEvent
|
||||
// This event is used to factor multiple search results notifications in a single event.
|
||||
|
||||
struct RsGxsChannelSearchResultEvent: RsEvent
|
||||
{
|
||||
RsGxsChannelSearchResultEvent():
|
||||
RsEvent(RsEventType::GXS_CHANNELS),
|
||||
mChannelEventCode(RsChannelEventCode::RECEIVED_TURTLE_SEARCH_RESULT) {}
|
||||
mChannelEventCode(RsChannelEventCode::RECEIVED_DISTANT_SEARCH_RESULT) {}
|
||||
|
||||
RsChannelEventCode mChannelEventCode;
|
||||
std::map<TurtleRequestId,std::set<RsGxsGroupId> > mSearchResultsMap;
|
||||
@ -179,29 +164,6 @@ RsGxsChannelSearchResultEvent: RsEvent
|
||||
}
|
||||
};
|
||||
|
||||
/** This event is fired once distant search results are received */
|
||||
struct RsGxsChannelDistantSearchResultEvent: RsEvent
|
||||
{
|
||||
RsGxsChannelDistantSearchResultEvent():
|
||||
RsEvent(RsEventType::GXS_CHANNELS),
|
||||
mChannelEventCode(RsChannelEventCode::DISTANT_SEARCH_RESULT) {}
|
||||
|
||||
RsChannelEventCode mChannelEventCode;
|
||||
TurtleRequestId mSearchId;
|
||||
std::vector<RsGxsSearchResult> mSearchResults;
|
||||
|
||||
///* @see RsEvent @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RsEvent::serial_process(j, ctx);
|
||||
|
||||
RS_SERIAL_PROCESS(mChannelEventCode);
|
||||
RS_SERIAL_PROCESS(mSearchId);
|
||||
RS_SERIAL_PROCESS(mSearchResults);
|
||||
}
|
||||
};
|
||||
|
||||
class RsGxsChannels: public RsGxsIfaceHelper, public RsGxsCommentService
|
||||
{
|
||||
public:
|
||||
@ -424,15 +386,11 @@ public:
|
||||
* @brief Get channel content summaries
|
||||
* @jsonapi{development}
|
||||
* @param[in] channelId id of the channel of which the content is requested
|
||||
* @param[in] contentIds ids of requested contents, if empty summaries of
|
||||
* all messages are reqeusted
|
||||
* @param[out] summaries storage for summaries
|
||||
* @return success or error details if something failed
|
||||
* @return false if something failed, true otherwhise
|
||||
*/
|
||||
virtual std::error_condition getContentSummaries(
|
||||
const RsGxsGroupId& channelId,
|
||||
const std::set<RsGxsMessageId>& contentIds,
|
||||
std::vector<RsMsgMetaData>& summaries ) = 0;
|
||||
virtual bool getContentSummaries( const RsGxsGroupId& channelId,
|
||||
std::vector<RsMsgMetaData>& summaries ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Toggle post read status. Blocking API.
|
||||
@ -464,23 +422,22 @@ public:
|
||||
virtual bool subscribeToChannel( const RsGxsGroupId& channelId,
|
||||
bool subscribe ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Retrieve statistics about the channel service
|
||||
/**
|
||||
* \brief Retrieve statistics about the channel service
|
||||
* @jsonapi{development}
|
||||
* @param[out] stat storage for statistics
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getChannelServiceStatistics(GxsServiceStatistic& stat) =0;
|
||||
* \param[out] stat Statistics structure
|
||||
* \return
|
||||
*/
|
||||
virtual bool getChannelServiceStatistics(GxsServiceStatistic& stat) =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieve statistics about the given channel
|
||||
/**
|
||||
* \brief Retrieve statistics about the given channel
|
||||
* @jsonapi{development}
|
||||
* @param[in] channelId Id of the channel group
|
||||
* @param[out] stat storage for statistics
|
||||
* @return true on success false otherwise
|
||||
*/
|
||||
virtual bool getChannelStatistics(
|
||||
const RsGxsGroupId& channelId, GxsGroupStatistic& stat ) =0;
|
||||
* \param[in] channelId Id of the channel group
|
||||
* \param[out] stat Statistics structure
|
||||
* \return
|
||||
*/
|
||||
virtual bool getChannelStatistics(const RsGxsGroupId& channelId,GxsGroupStatistic& stat) =0;
|
||||
|
||||
/// default base URL used for channels links @see exportChannelLink
|
||||
static const std::string DEFAULT_CHANNEL_BASE_URL;
|
||||
@ -539,18 +496,14 @@ public:
|
||||
std::string& errMsg = RS_DEFAULT_STORAGE_PARAM(std::string) ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Search the whole reachable network for matching channels and
|
||||
* contents
|
||||
* @brief Search the turtle reachable network for matching channels
|
||||
* @jsonapi{development}
|
||||
* An @see RsGxsChannelSearchResultEvent is emitted when matching results
|
||||
* arrives from the network
|
||||
* An @see RsGxsChannelSearchResultEvent is emitted when matching channels
|
||||
* arrives from the network
|
||||
* @param[in] matchString string to search into the channels
|
||||
* @param[out] searchId storage for search id, useful to track search events
|
||||
* and retrieve search results
|
||||
* @return success or error details
|
||||
* @return search id
|
||||
*/
|
||||
virtual std::error_condition distantSearchRequest(
|
||||
const std::string& matchString, TurtleRequestId& searchId ) = 0;
|
||||
virtual TurtleRequestId turtleSearchRequest(const std::string& matchString)=0;
|
||||
|
||||
/**
|
||||
* @brief Retrieve available search results
|
||||
@ -580,18 +533,16 @@ public:
|
||||
* @param[out] distantGroup storage for group data
|
||||
* @return false on error, true otherwise
|
||||
*/
|
||||
virtual bool getDistantSearchResultGroupData(
|
||||
const RsGxsGroupId& groupId, RsGxsChannelGroup& distantGroup ) = 0;
|
||||
virtual bool getDistantSearchResultGroupData(const RsGxsGroupId& groupId, RsGxsChannelGroup& distantGroup ) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the status of ongoing search
|
||||
* @return unknown (probably not even searched), known as a search result,
|
||||
* data request ongoing and data available
|
||||
*/
|
||||
virtual DistantSearchGroupStatus getDistantSearchStatus(
|
||||
const RsGxsGroupId& group_id ) =0;
|
||||
/**
|
||||
* @brief getDistantSearchStatus
|
||||
* Returns the status of ongoing search: unknown (probably not even searched), known as a search result,
|
||||
* data request ongoing and data available
|
||||
*/
|
||||
virtual DistantSearchGroupStatus getDistantSearchStatus(const RsGxsGroupId& group_id) =0;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Clear accumulated search results
|
||||
* @jsonapi{development}
|
||||
* @param[in] reqId search id
|
||||
|
@ -3,9 +3,7 @@
|
||||
* *
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2021 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2021 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -21,7 +19,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
#ifndef RS_GXS_CHANNEL_ITEMS_H
|
||||
#define RS_GXS_CHANNEL_ITEMS_H
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -31,23 +30,14 @@
|
||||
|
||||
#include "serialiser/rstlvfileitem.h"
|
||||
#include "serialiser/rstlvimage.h"
|
||||
#include "serialiser/rsserializable.h"
|
||||
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
|
||||
#include "serialiser/rsserializer.h"
|
||||
|
||||
#include "util/rsdir.h"
|
||||
|
||||
enum class RsGxsChannelItems : uint8_t
|
||||
{
|
||||
GROUP_ITEM = 0x02,
|
||||
POST_ITEM = 0x03,
|
||||
SEARCH_REQUEST = 0x04,
|
||||
SEARCH_REPLY = 0x05,
|
||||
};
|
||||
|
||||
RS_DEPRECATED_FOR(RsGxsChannelItems)
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_GROUP_ITEM = 0x02;
|
||||
|
||||
RS_DEPRECATED_FOR(RsGxsChannelItems)
|
||||
const uint8_t RS_PKT_SUBTYPE_GXSCHANNEL_POST_ITEM = 0x03;
|
||||
|
||||
class RsGxsChannelGroupItem : public RsGxsGrpItem
|
||||
@ -89,47 +79,6 @@ public:
|
||||
RsTlvImage mThumbnail;
|
||||
};
|
||||
|
||||
struct RsGxsChannelsSearchRequest : RsSerializable
|
||||
{
|
||||
RsGxsChannelsSearchRequest() : mType(RsGxsChannelItems::SEARCH_REQUEST) {}
|
||||
|
||||
/// Just for easier back and forward compatibility
|
||||
RsGxsChannelItems mType;
|
||||
|
||||
/// Store search match string
|
||||
std::string mQuery;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mType);
|
||||
RS_SERIAL_PROCESS(mQuery);
|
||||
}
|
||||
|
||||
~RsGxsChannelsSearchRequest() override = default;
|
||||
};
|
||||
|
||||
struct RsGxsChannelsSearchReply : RsSerializable
|
||||
{
|
||||
RsGxsChannelsSearchReply() : mType(RsGxsChannelItems::SEARCH_REPLY) {}
|
||||
|
||||
/// Just for easier back and forward compatibility
|
||||
RsGxsChannelItems mType;
|
||||
|
||||
/// Results storage
|
||||
std::vector<RsGxsSearchResult> mResults;
|
||||
|
||||
/// @see RsSerializable
|
||||
void serial_process( RsGenericSerializer::SerializeJob j,
|
||||
RsGenericSerializer::SerializeContext& ctx ) override
|
||||
{
|
||||
RS_SERIAL_PROCESS(mType);
|
||||
RS_SERIAL_PROCESS(mResults);
|
||||
}
|
||||
|
||||
~RsGxsChannelsSearchReply() override = default;
|
||||
};
|
||||
|
||||
class RsGxsChannelSerialiser : public RsGxsCommentSerialiser
|
||||
{
|
||||
@ -140,3 +89,5 @@ public:
|
||||
|
||||
virtual RsItem *create_item(uint16_t service_id,uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_GXS_CHANNEL_ITEMS_H */
|
||||
|
@ -4,8 +4,7 @@
|
||||
* libretroshare: retroshare core library *
|
||||
* *
|
||||
* Copyright (C) 2012 Robert Fernie <retroshare@lunamutt.com> *
|
||||
* Copyright (C) 2018-2021 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* Copyright (C) 2019-2021 Asociación Civil Altermundi <info@altermundi.net> *
|
||||
* Copyright (C) 2018-2019 Gioacchino Mazzurco <gio@eigenlab.org> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License as *
|
||||
@ -23,8 +22,6 @@
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
#include "services/p3gxscommon.h"
|
||||
@ -33,7 +30,9 @@
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rstickevent.h"
|
||||
#include "deep_search/channelsindex.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
|
||||
// This class is only a helper to parse the channel group service string.
|
||||
@ -57,11 +56,6 @@ class p3GxsChannels: public RsGenExchange, public RsGxsChannels,
|
||||
public:
|
||||
p3GxsChannels( RsGeneralDataService* gds, RsNetworkExchangeService* nes,
|
||||
RsGixs* gixs );
|
||||
|
||||
/// @see RsGxsChannels
|
||||
std::error_condition distantSearchRequest(
|
||||
const std::string& matchString, TurtleRequestId& searchId ) override;
|
||||
|
||||
virtual RsServiceInfo getServiceInfo() override;
|
||||
|
||||
virtual void service_tick() override;
|
||||
@ -75,7 +69,7 @@ protected:
|
||||
virtual bool loadList(std::list<RsItem *>& loadList) override; // @see p3Config::loadList(std::list<RsItem *>&)
|
||||
|
||||
virtual TurtleRequestId turtleGroupRequest(const RsGxsGroupId& group_id) override;
|
||||
|
||||
virtual TurtleRequestId turtleSearchRequest(const std::string& match_string) override;
|
||||
virtual bool retrieveDistantSearchResults(TurtleRequestId req, std::map<RsGxsGroupId, RsGxsGroupSearchResults> &results) override;
|
||||
virtual bool clearDistantSearchResults(TurtleRequestId req) override;
|
||||
virtual bool getDistantSearchResultGroupData(const RsGxsGroupId& group_id,RsGxsChannelGroup& distant_group) override;
|
||||
@ -118,6 +112,24 @@ virtual bool getChannelAutoDownload(const RsGxsGroupId &groupid, bool& enabled)
|
||||
virtual bool setChannelDownloadDirectory(const RsGxsGroupId &groupId, const std::string& directory) override;
|
||||
virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::string& directory) override;
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
/// @see RsGxsChannels::turtleSearchRequest
|
||||
virtual bool turtleSearchRequest(const std::string& matchString,
|
||||
const std::function<void (const RsGxsGroupSummary&)>& multiCallback,
|
||||
rstime_t maxWait = 300 ) override;
|
||||
|
||||
/// @see RsGxsChannels::turtleChannelRequest
|
||||
virtual bool turtleChannelRequest(
|
||||
const RsGxsGroupId& channelId,
|
||||
const std::function<void (const RsGxsChannelGroup& result)>& multiCallback,
|
||||
rstime_t maxWait = 300 ) override;
|
||||
|
||||
/// @see RsGxsChannels::localSearchRequest
|
||||
virtual bool localSearchRequest(const std::string& matchString,
|
||||
const std::function<void (const RsGxsGroupSummary& result)>& multiCallback,
|
||||
rstime_t maxWait = 30 ) override;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Receive results from turtle search @see RsGenExchange @see RsNxsObserver
|
||||
* @see RsGxsNetService::receiveTurtleSearchResults
|
||||
@ -203,10 +215,9 @@ virtual bool ExtraFileRemove(const RsFileHash &hash) override;
|
||||
const std::set<RsGxsMessageId> &contentIds,
|
||||
std::vector<RsGxsComment> &comments) override;
|
||||
|
||||
/// @see RsGxsChannels
|
||||
std::error_condition getContentSummaries(
|
||||
/// Implementation of @see RsGxsChannels::getContentSummaries
|
||||
bool getContentSummaries(
|
||||
const RsGxsGroupId& channelId,
|
||||
const std::set<RsGxsMessageId>& contentIds,
|
||||
std::vector<RsMsgMetaData>& summaries ) override;
|
||||
|
||||
/// Implementation of @see RsGxsChannels::getChannelStatistics
|
||||
@ -286,17 +297,6 @@ virtual bool ExtraFileRemove(const RsFileHash &hash) override;
|
||||
virtual bool shareChannelKeys(
|
||||
const RsGxsGroupId& channelId, const std::set<RsPeerId>& peers ) override;
|
||||
|
||||
#ifdef RS_DEEP_CHANNEL_INDEX
|
||||
/// @see RsNxsObserver
|
||||
std::error_condition handleDistantSearchRequest(
|
||||
rs_view_ptr<uint8_t> requestData, uint32_t requestSize,
|
||||
rs_owner_ptr<uint8_t>& resultData, uint32_t& resultSize ) override;
|
||||
|
||||
std::error_condition receiveDistantSearchResult(
|
||||
const TurtleRequestId requestId,
|
||||
rs_owner_ptr<uint8_t>& resultData, uint32_t& resultSize ) override;
|
||||
#endif
|
||||
|
||||
/// Implementation of @see RsGxsChannels::createChannel
|
||||
RS_DEPRECATED_FOR(createChannelV2)
|
||||
bool createChannel(RsGxsChannelGroup& channel) override;
|
||||
@ -313,6 +313,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash) override;
|
||||
RS_DEPRECATED_FOR(createVoteV2)
|
||||
bool createVote(RsGxsVote& vote) override;
|
||||
|
||||
|
||||
protected:
|
||||
// Overloaded from GxsTokenQueue for Request callbacks.
|
||||
virtual void handleResponse(uint32_t token, uint32_t req_type
|
||||
@ -328,6 +329,7 @@ static uint32_t channelsAuthenPolicy();
|
||||
void request_SpecificSubscribedGroups(const std::list<RsGxsGroupId> &groups);
|
||||
void load_SubscribedGroups(const uint32_t &token);
|
||||
|
||||
void request_SpecificUnprocessedPosts(std::list<std::pair<RsGxsGroupId, RsGxsMessageId> > &ids);
|
||||
void request_GroupUnprocessedPosts(const std::list<RsGxsGroupId> &grouplist);
|
||||
void load_unprocessedPosts(uint32_t token);
|
||||
|
||||
@ -388,8 +390,26 @@ bool generateGroup(uint32_t &token, std::string groupName);
|
||||
rstime_t mLastDistantSearchNotificationTS;
|
||||
|
||||
std::map<TurtleRequestId,std::set<RsGxsGroupId> > mSearchResultsToNotify;
|
||||
#ifdef TO_REMOVE
|
||||
/** Store search callbacks with timeout*/
|
||||
std::map<
|
||||
TurtleRequestId,
|
||||
std::pair<
|
||||
std::function<void (const RsGxsGroupSummary&)>,
|
||||
std::chrono::system_clock::time_point >
|
||||
> mSearchCallbacksMap;
|
||||
RsMutex mSearchCallbacksMapMutex;
|
||||
|
||||
#ifdef RS_DEEP_CHANNEL_INDEX
|
||||
DeepChannelsIndex mDeepIndex;
|
||||
/** Store distant channels requests callbacks with timeout*/
|
||||
std::map<
|
||||
TurtleRequestId,
|
||||
std::pair<
|
||||
std::function<void (const RsGxsChannelGroup&)>,
|
||||
std::chrono::system_clock::time_point >
|
||||
> mDistantChannelsCallbacksMap;
|
||||
RsMutex mDistantChannelsCallbacksMapMutex;
|
||||
|
||||
/// Cleanup mSearchCallbacksMap and mDistantChannelsCallbacksMap
|
||||
void cleanTimedOutCallbacks();
|
||||
#endif
|
||||
};
|
||||
|
@ -411,9 +411,7 @@ void GxsChannelDialog::clearDistantSearchResults(TurtleRequestId id)
|
||||
|
||||
TurtleRequestId GxsChannelDialog::distantSearch(const QString& search_string)
|
||||
{
|
||||
TurtleRequestId searchId;
|
||||
rsGxsChannels->distantSearchRequest(search_string.toStdString(), searchId);
|
||||
return searchId;
|
||||
return rsGxsChannels->turtleSearchRequest(search_string.toStdString()) ;
|
||||
}
|
||||
|
||||
bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSearchResults>& group_infos)
|
||||
|
Loading…
Reference in New Issue
Block a user