Repository: 10up/ElasticPress (PHP)

Issue:
BUG: Search in multisite for 'sites' => 'current'
### Describe the bug

After upgrading to Elasticpress 4.4.0 we are no longer able to search within the 'current' site,  all requests seams to be using the Main site URL

### Steps to Reproduce

If the search quests is using:
```
new WP_Query( array(
    's'     => 'search phrase',
    'sites' => 'current',
) );
```
It doesn't work !

But if it's changed to:
```
new WP_Query( array(
    's'     => 'search phrase',
    'sites' => get_current_blog_id(),
) );
```
It starts working correctly again

### Screenshots, screen recording, code snippet

_No response_

### Environment information

_No response_

### WordPress and ElasticPress information

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion: Hi @anders-naslund ,

By what you said, it seems this would be a regression? If so, can you let us know which version was working correctly for you?
 
4.3.1 was working fine,
looks like it might have to do with changes in [includes/classes/Indexable/Comment/QueryIntegration.php]

Changed to use 'sites__in' according to the release note but still 'current' is not working so if that's not going to work anymore you might need to update this article. 
https://elasticpress.zendesk.com/hc/en-us/articles/360052027951-How-can-I-search-across-multiple-sites-in-a-multi-site-



Fix (patch):
diff --git a/includes/classes/Indexable/Comment/QueryIntegration.php b/includes/classes/Indexable/Comment/QueryIntegration.php
index 7520dfa579..9cf1bc781f 100644
--- a/includes/classes/Indexable/Comment/QueryIntegration.php
+++ b/includes/classes/Indexable/Comment/QueryIntegration.php
@@ -123,15 +123,17 @@ public function maybe_filter_query( $results, WP_Comment_Query $query ) {
 		$site__not_in = [];
 
 		if ( ! empty( $query->query_vars['sites'] ) ) {
-
 			_deprecated_argument( __FUNCTION__, '4.4.0', esc_html__( 'sites is deprecated. Use site__in instead.', 'elasticpress' ) );
-			$site__in = (array) $query->query_vars['sites'];
-			$scope    = 'all' === $query->query_vars['sites'] ? 'all' : $site__in;
 		}
 
-		if ( ! empty( $query->query_vars['site__in'] ) ) {
-			$site__in = (array) $query->query_vars['site__in'];
-			$scope    = 'all' === $query->query_vars['site__in'] ? 'all' : $site__in;
+		if ( ! empty( $query->query_vars['site__in'] ) || ! empty( $query->query_vars['sites'] ) ) {
+			$site__in = ! empty( $query->query_vars['site__in'] ) ? (array) $query->query_vars['site__in'] : (array) $query->query_vars['sites'];
+
+			if ( in_array( 'all', $site__in, true ) ) {
+				$scope = 'all';
+			} elseif ( in_array( 'current', $site__in, true ) ) {
+				$site__in = (array) get_current_blog_id();
+			}
 		}
 
 		if ( ! empty( $query->query_vars['site__not_in'] ) ) {
diff --git a/includes/classes/Indexable/Post/QueryIntegration.php b/includes/classes/Indexable/Post/QueryIntegration.php
index 611ba5341a..4067bc2ec0 100644
--- a/includes/classes/Indexable/Post/QueryIntegration.php
+++ b/includes/classes/Indexable/Post/QueryIntegration.php
@@ -280,16 +280,17 @@ public function get_es_posts( $posts, $query ) {
 			$site__not_in = '';
 
 			if ( ! empty( $query_vars['sites'] ) ) {
-
 				_deprecated_argument( __FUNCTION__, '4.4.0', esc_html__( 'sites is deprecated. Use site__in instead.', 'elasticpress' ) );
-				$site__in = (array) $query_vars['sites'];
-				$scope    = 'all' === $query_vars['sites'] ? 'all' : $site__in;
 			}
 
-			if ( ! empty( $query_vars['site__in'] ) ) {
+			if ( ! empty( $query_vars['site__in'] ) || ! empty( $query_vars['sites'] ) ) {
+				$site__in = ! empty( $query_vars['site__in'] ) ? (array) $query_vars['site__in'] : (array) $query_vars['sites'];
 
-				$site__in = (array) $query_vars['site__in'];
-				$scope    = 'all' === $query_vars['site__in'] ? 'all' : $site__in;
+				if ( in_array( 'all', $site__in, true ) ) {
+					$scope = 'all';
+				} elseif ( in_array( 'current', $site__in, true ) ) {
+					$site__in = (array) get_current_blog_id();
+				}
 			}
 
 			if ( ! empty( $query_vars['site__not_in'] ) ) {
diff --git a/includes/classes/Indexable/Term/QueryIntegration.php b/includes/classes/Indexable/Term/QueryIntegration.php
index f310a29481..60d33a77c6 100644
--- a/includes/classes/Indexable/Term/QueryIntegration.php
+++ b/includes/classes/Indexable/Term/QueryIntegration.php
@@ -94,15 +94,17 @@ public function maybe_filter_query( $results, WP_Term_Query $query ) {
 			$site__not_in = [];
 
 			if ( ! empty( $query->query_vars['sites'] ) ) {
-
 				_deprecated_argument( __FUNCTION__, '4.4.0', esc_html__( 'sites is deprecated. Use site__in instead.', 'elasticpress' ) );
-				$site__in = (array) $query->query_vars['sites'];
-				$scope    = 'all' === $query->query_vars['sites'] ? 'all' : $site__in;
 			}
 
-			if ( ! empty( $query->query_vars['site__in'] ) ) {
-				$site__in = (array) $query->query_vars['site__in'];
-				$scope    = 'all' === $query->query_vars['site__in'] ? 'all' : $site__in;
+			if ( ! empty( $query->query_vars['site__in'] ) || ! empty( $query->query_vars['sites'] ) ) {
+				$site__in = ! empty( $query->query_vars['site__in'] ) ? (array) $query->query_vars['site__in'] : (array) $query->query_vars['sites'];
+
+				if ( in_array( 'all', $site__in, true ) ) {
+					$scope = 'all';
+				} elseif ( in_array( 'current', $site__in, true ) ) {
+					$site__in = (array) get_current_blog_id();
+				}
 			}
 
 			if ( ! empty( $query->query_vars['site__not_in'] ) ) {