@@ -35,11 +35,9 @@ void TraverseAllMatching(const DocIndex& index, const OpArgs& op_args, F&& f) {
3535 string scratch;
3636 auto cb = [&](PrimeTable::iterator it) {
3737 const PrimeValue& pv = it->second ;
38- if (pv.ObjType () != index.GetObjCode ())
39- return ;
40-
4138 string_view key = it->first .GetSlice (&scratch);
42- if (key.rfind (index.prefix , 0 ) != 0 )
39+
40+ if (!index.Matches (key, pv.ObjType ()))
4341 return ;
4442
4543 auto accessor = GetAccessor (op_args.db_cntx , pv);
@@ -149,9 +147,13 @@ string DocIndexInfo::BuildRestoreCommand() const {
149147 // ON HASH/JSON
150148 absl::StrAppend (&out, " ON" , " " , base_index.type == DocIndex::HASH ? " HASH" : " JSON" );
151149
152- // optional PREFIX 1 *prefix*
153- if (!base_index.prefix .empty ())
154- absl::StrAppend (&out, " PREFIX" , " 1 " , base_index.prefix );
150+ // optional PREFIX count *prefix1* *prefix2* ...
151+ if (!base_index.prefixes .empty ()) {
152+ absl::StrAppend (&out, " PREFIX" , " " , base_index.prefixes .size ());
153+ for (const auto & prefix : base_index.prefixes ) {
154+ absl::StrAppend (&out, " " , prefix);
155+ }
156+ }
155157
156158 // STOPWORDS
157159 absl::StrAppend (&out, " STOPWORDS " , base_index.options .stopwords .size ());
@@ -247,7 +249,18 @@ uint8_t DocIndex::GetObjCode() const {
247249}
248250
249251bool DocIndex::Matches (string_view key, unsigned obj_code) const {
250- return obj_code == GetObjCode () && key.rfind (prefix, 0 ) == 0 ;
252+ if (obj_code != GetObjCode ())
253+ return false ;
254+
255+ // Empty prefixes means match all keys
256+ if (prefixes.empty ())
257+ return true ;
258+
259+ for (const auto & prefix : prefixes) {
260+ if (key.rfind (prefix, 0 ) == 0 )
261+ return true ;
262+ }
263+ return false ;
251264}
252265
253266ShardDocIndex::ShardDocIndex (shared_ptr<const DocIndex> index)
@@ -269,7 +282,8 @@ void ShardDocIndex::Rebuild(const OpArgs& op_args, PMR_NS::memory_resource* mr)
269282
270283 indices_->FinalizeInitialization ();
271284
272- VLOG (1 ) << " Indexed " << key_index_.Size () << " docs on " << base_->prefix ;
285+ VLOG (1 ) << " Indexed " << key_index_.Size ()
286+ << " docs on prefixes: " << absl::StrJoin (base_->prefixes , " , " );
273287}
274288
275289void ShardDocIndex::RebuildForGroup (const OpArgs& op_args, const std::string_view& group_id,
0 commit comments