From 5699d81ae72b329e1a4ae66b05147dada3a3fea4 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sat, 20 Oct 2018 13:39:13 +0200 Subject: [PATCH] GXS deep search notify results also of known groups --- libretroshare/src/gxs/rsdataservice.cc | 2 +- libretroshare/src/gxs/rsgenexchange.cc | 5 +- libretroshare/src/gxs/rsgxsnetservice.cc | 62 ++++++++++++---------- libretroshare/src/services/p3gxschannels.h | 3 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 602e43fe0..ca83a2b19 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -1373,7 +1373,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp) std::cerr << std::endl; #endif - RsStackMutex stack(mDbMutex); + RS_STACK_MUTEX(mDbMutex); #ifdef RS_DATA_SERVICE_DEBUG_TIME rstime::RsScopeTimer timer(""); diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 287ac9964..55b37d517 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1639,12 +1639,13 @@ void RsGenExchange::receiveNewMessages(std::vector& messages) void RsGenExchange::receiveDistantSearchResults(TurtleRequestId id,const RsGxsGroupId &grpId) { + std::cerr << __PRETTY_FUNCTION__ << " received result for request " + << std::hex << id << std::dec << std::endl; + RS_STACK_MUTEX(mGenMtx); RsGxsDistantSearchResultChange* gc = new RsGxsDistantSearchResultChange(id,grpId); mNotifications.push_back(gc); - - std::cerr << "RsGenExchange::receiveDistantSearchResults(): received result for request " << std::hex << id << std::dec << std::endl; } void RsGenExchange::notifyReceivePublishKey(const RsGxsGroupId &grpId) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index cb73e06a7..65d5d19b8 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -5181,7 +5181,9 @@ bool RsGxsNetService::clearDistantSearchResults(const TurtleRequestId& id) mDistantSearchResults.erase(id); return true ; } -void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std::list& group_infos) + +void RsGxsNetService::receiveTurtleSearchResults( + TurtleRequestId req, const std::list& group_infos ) { std::set groupsToNotifyResults; @@ -5192,38 +5194,42 @@ void RsGxsNetService::receiveTurtleSearchResults(TurtleRequestId req, const std: std::map& search_results_map(mDistantSearchResults[req]); - for(auto it(group_infos.begin());it!=group_infos.end();++it) - if(search_results_map.find((*it).mGroupId) == search_results_map.end()) - grpMeta[(*it).mGroupId] = NULL; - + for(const RsGxsGroupSummary& gps : group_infos) + if(search_results_map.find(gps.mGroupId) == search_results_map.end()) + grpMeta[gps.mGroupId] = nullptr; mDataStore->retrieveGxsGrpMetaData(grpMeta); - // only keep groups that are not locally known, and groups that are not already in the mDistantSearchResults structure + for (const RsGxsGroupSummary& gps : group_infos) + { +#ifndef RS_DEEP_SEARCH + /* Only keep groups that are not locally known, and groups that are + * not already in the mDistantSearchResults structure. */ + if(grpMeta[gps.mGroupId]) continue; +#else // ndef RS_DEEP_SEARCH + /* When deep search is enabled search results may bring more info + * then we already have also about post that are indexed by xapian, + * so we don't apply this filter in this case. */ +#endif + const RsGxsGroupId& grpId(gps.mGroupId); - for(auto it(group_infos.begin());it!=group_infos.end();++it) - if(grpMeta[(*it).mGroupId] == NULL) + groupsToNotifyResults.insert(grpId); + auto it2 = search_results_map.find(grpId); + if(it2 != search_results_map.end()) { - const RsGxsGroupId& grpId((*it).mGroupId); - - groupsToNotifyResults.insert(grpId); - - auto it2 = search_results_map.find(grpId); - - if(it2 != search_results_map.end()) - { - // update existing data - - it2->second.mPopularity++; - it2->second.mNumberOfMessages = std::max( - it2->second.mNumberOfMessages, - (*it).mNumberOfMessages ); - } - else - { - search_results_map[grpId] = *it; - search_results_map[grpId].mPopularity = 1; // number of results so far - } + // update existing data + RsGxsGroupSummary& eGpS(it2->second); + eGpS.mPopularity++; + eGpS.mNumberOfMessages = std::max( + eGpS.mNumberOfMessages, + gps.mNumberOfMessages ); } + else + { + search_results_map[grpId] = gps; + // number of results so far + search_results_map[grpId].mPopularity = 1; + } + } } // end RS_STACK_MUTEX(mNxsMutex); for(const RsGxsGroupId& grpId : groupsToNotifyResults) diff --git a/libretroshare/src/services/p3gxschannels.h b/libretroshare/src/services/p3gxschannels.h index bdb8123dc..327444509 100644 --- a/libretroshare/src/services/p3gxschannels.h +++ b/libretroshare/src/services/p3gxschannels.h @@ -114,10 +114,11 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin /** * Receive results from turtle search @see RsGenExchange @see RsNxsObserver + * @see RsGxsNetService::receiveTurtleSearchResults * @see p3turtle::handleSearchResult */ void receiveDistantSearchResults( TurtleRequestId id, - const RsGxsGroupId& grpId ); + const RsGxsGroupId& grpId ) override; /* Comment service - Provide RsGxsCommentService - redirect to p3GxsCommentService */ virtual bool getCommentData(uint32_t token, std::vector &msgs)