11#include " indexunordered.h"
22#include " core/dbconfig.h"
33#include " core/index/indextext/ftkeyentry.h"
4- #include " core/index/payload_map.h"
54#include " core/index/string_map.h"
65#include " core/indexdef.h"
76#include " core/rdxcontext.h"
@@ -82,8 +81,8 @@ IndexUnordered<unordered_str_map<FtKeyEntry>>::IndexUnordered(const IndexDef& id
8281 hitsToCache_(cacheCfg.idxIdsetHitsToCache) {}
8382
8483template <>
85- IndexUnordered<unordered_payload_map <FtKeyEntry>>::IndexUnordered(const IndexDef& idef, PayloadType&& payloadType, FieldsSet&& fields,
86- const NamespaceCacheConfigData& cacheCfg)
84+ IndexUnordered<unordered_payload_map_ft <FtKeyEntry>>::IndexUnordered(const IndexDef& idef, PayloadType&& payloadType, FieldsSet&& fields,
85+ const NamespaceCacheConfigData& cacheCfg)
8786 : Base(idef, std::move(payloadType), std::move(fields)),
8887 idx_map (PayloadType{Base::GetPayloadType ()}, FieldsSet{Base::Fields ()}),
8988 cacheMaxSize_(cacheCfg.idxIdsetCacheSize),
@@ -219,6 +218,7 @@ Variant IndexUnordered<T>::Upsert(const Variant& key, IdType id, bool& clearCach
219218 if (keyIt == this ->idx_map .end ()) {
220219 keyIt = this ->idx_map .insert ({static_cast <key_type>(key), typename T::mapped_type ()}).first ;
221220 } else {
221+ refreshCompositeKeyImpl (key, keyIt);
222222 delMemStat (keyIt);
223223 if (this ->opts_ .IsPK ()) {
224224 WrSerializer wrser;
@@ -278,9 +278,12 @@ void IndexUnordered<T>::Delete(const Variant& key, IdType id, MustExist mustExis
278278 if constexpr (is_str_map_v<T>) {
279279 idx_map.template erase <StringMapEntryCleaner<true >>(
280280 keyIt, {strHolder, this ->KeyType ().template Is <KeyValueType::String>() && this ->opts_ .GetCollateMode () == CollateNone});
281+ } else if constexpr (is_ft_payload_map_v<T>) {
282+ idx_map.template erase <DeepClean>(keyIt, strHolder);
281283 } else {
282284 idx_map.template erase <DeepClean>(keyIt);
283285 }
286+
284287 } else {
285288 addMemStat (keyIt);
286289 this ->tracker_ .markUpdated (this ->idx_map , keyIt);
@@ -299,27 +302,10 @@ bool IndexUnordered<T>::RefreshCompositeKey(const Variant& key) noexcept {
299302 assertrx_dbg (false );
300303 return false ;
301304 }
302- delMemStat (keyIt);
303305
304- #ifdef RX_WITH_STDLIB_DEBUG
305- const hash_composite hashF (this ->GetPayloadType (), this ->Fields ());
306- assertrx_dbg (hashF (keyIt->first ) == hashF (static_cast <const PayloadValue&>(key)));
307- const equal_composite equalF (this ->GetPayloadType (), this ->Fields ());
308- assertrx_dbg (equalF (keyIt->first , static_cast <const PayloadValue&>(key)));
309- const less_composite lessF (PayloadType (this ->GetPayloadType ()), FieldsSet (this ->Fields ()));
310- assertrx_dbg (!lessF (keyIt->first , static_cast <const PayloadValue&>(key)));
311- assertrx_dbg (!lessF (static_cast <const PayloadValue&>(key), keyIt->first ));
312- #endif // RX_WITH_STDLIB_DEBUG
313-
314- auto & newKey = static_cast <const PayloadValue&>(key);
315- this ->tracker_ .refreshKey (keyIt->first , static_cast <const PayloadValue&>(key));
316- if constexpr (std::is_same_v<typename T::key_type, PayloadValueWithHash>) {
317- const_cast <PayloadValueWithHash&>(keyIt->first ) =
318- PayloadValueWithHash (PayloadValue (newKey), this ->payloadType_ , this ->Fields ());
306+ delMemStat (keyIt);
319307
320- } else {
321- const_cast <PayloadValue&>(keyIt->first ) = newKey;
322- }
308+ refreshCompositeKeyImpl (key, keyIt);
323309
324310 addMemStat (keyIt);
325311 cache_.ResetImpl ();
@@ -602,6 +588,34 @@ IndexMemStat IndexUnordered<T>::GetMemStat(const RdxContext& ctx) {
602588 return ret;
603589}
604590
591+ template <typename T>
592+ void IndexUnordered<T>::refreshCompositeKeyImpl(const Variant& key, typename T::iterator& keyIt) noexcept {
593+ if constexpr (is_payload_map_v<T>) {
594+ #ifdef RX_WITH_STDLIB_DEBUG
595+ const hash_composite hashF (this ->GetPayloadType (), this ->Fields ());
596+ assertrx_dbg (hashF (keyIt->first ) == hashF (static_cast <const PayloadValue&>(key)));
597+ const equal_composite equalF (this ->GetPayloadType (), this ->Fields ());
598+ assertrx_dbg (equalF (keyIt->first , static_cast <const PayloadValue&>(key)));
599+ const less_composite lessF (PayloadType (this ->GetPayloadType ()), FieldsSet (this ->Fields ()));
600+ assertrx_dbg (!lessF (keyIt->first , static_cast <const PayloadValue&>(key)));
601+ assertrx_dbg (!lessF (static_cast <const PayloadValue&>(key), keyIt->first ));
602+ #endif // RX_WITH_STDLIB_DEBUG
603+
604+ auto & newKey = static_cast <const PayloadValue&>(key);
605+ this ->tracker_ .refreshKey (keyIt->first , static_cast <const PayloadValue&>(key));
606+ if constexpr (std::is_same_v<typename T::key_type, PayloadValueWithHash>) {
607+ const_cast <PayloadValueWithHash&>(keyIt->first ) =
608+ PayloadValueWithHash (PayloadValue (newKey), this ->payloadType_ , this ->Fields ());
609+
610+ } else {
611+ const_cast <PayloadValue&>(keyIt->first ) = newKey;
612+ }
613+ } else {
614+ (void )key;
615+ (void )keyIt;
616+ }
617+ }
618+
605619template <typename T>
606620template <typename S>
607621void IndexUnordered<T>::dump(S& os, std::string_view step, std::string_view offset) const {
@@ -724,7 +738,7 @@ template class IndexUnordered<payload_map<Index::KeyEntry>>;
724738
725739template class IndexUnordered <unordered_str_map<FtKeyEntry>>;
726740
727- template class IndexUnordered <unordered_payload_map <FtKeyEntry>>;
741+ template class IndexUnordered <unordered_payload_map_ft <FtKeyEntry>>;
728742
729743template class IndexUnordered <unordered_uuid_map<Index::KeyEntryPK>>;
730744template class IndexUnordered <unordered_uuid_map<Index::KeyEntryPlain>>;
0 commit comments