Fixed Unable to specify multiple content types to rebuild search index

Jake B.

Well-known member
Affected version
Currently if you rebuild the search index it's either all or one at a time, which can be a bit of a pain if you need to (for example) search index for all XFMG data, for example. Able to work around this to have multiple types specified in CLI without breaking or changing how the web rebuild works:

diff --git a/src/XF/Cli/Command/Rebuild/RebuildSearch.php b/src/XF/Cli/Command/Rebuild/RebuildSearch.php
index 4897636f6..3f2e59248 100644
--- a/src/XF/Cli/Command/Rebuild/RebuildSearch.php
+++ b/src/XF/Cli/Command/Rebuild/RebuildSearch.php
@@ -27,7 +27,7 @@ class RebuildSearch extends AbstractRebuildCommand
-                InputOption::VALUE_REQUIRED,
+                InputOption::VALUE_IS_ARRAY|InputOption::VALUE_REQUIRED,
                 'Content type to rebuild search index for. Default: all'
diff --git a/src/XF/Job/SearchRebuild.php b/src/XF/Job/SearchRebuild.php
index 422dcca73..88fc315eb 100644
--- a/src/XF/Job/SearchRebuild.php
+++ b/src/XF/Job/SearchRebuild.php
@@ -28,7 +28,7 @@ class SearchRebuild extends AbstractJob
         if (!is_array($this->data['rebuild_types']))
-            $this->data['rebuild_types'] = $this->data['type'] ? [$this->data['type']] : $search->getAvailableTypes();
+            $this->data['rebuild_types'] = $this->data['type'] ? (is_array($this->data['type']) ? $this->data['type'] : [$this->data['type']]) : $search->getAvailableTypes();
             $this->data['type'] = null;

xf xf-rebuild:search --type=post --type=profile_post
Rebuilding... Search index (Post 18)
Rebuilding... Search index
Rebuilding... Search index (Profile post 15)
Rebuilding... Search index
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.7).

Change log:
Support specifying multiple content types when rebuilding the search index
There may be a delay before changes are rolled out to the XenForo Community.
Top Bottom