Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
decodekult committed Dec 20, 2024
1 parent 69cbbb5 commit 313d97b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Feature extends \ElasticPress\Feature {
/** @var FeatureSupport\RelatedPosts */
private $frontendRelatedPosts;

/** @var FeatureSupport\Autosuggest */
private $frontendAutosuggest;

/** @var Stats\Health */
private $statsHealth;

Expand Down Expand Up @@ -59,6 +62,7 @@ public function __construct(
Sync\CLI $syncCli,
FeatureSupport\Search $frontendSearch,
FeatureSupport\RelatedPosts $frontendRelatedPosts,
FeatureSupport\Autosuggest $frontendAutosuggest,
Stats\Health $statsHealth,
Stats\Report $statsReport
) {
Expand All @@ -69,6 +73,7 @@ public function __construct(
$this->syncCli = $syncCli;
$this->frontendSearch = $frontendSearch;
$this->frontendRelatedPosts = $frontendRelatedPosts;
$this->frontendAutosuggest = $frontendAutosuggest;
$this->statsHealth = $statsHealth;
$this->statsReport = $statsReport;

Expand All @@ -87,6 +92,7 @@ public function setup() {
$this->syncCli->addHooks();
$this->frontendSearch->addHooks();
$this->frontendRelatedPosts->addHooks();
$this->frontendAutosuggest->addHooks();
$this->statsHealth->addHooks();
$this->statsReport->addHooks();
}
Expand Down
38 changes: 38 additions & 0 deletions src/FeatureSupport/Autosuggest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace WPML\ElasticPress\FeatureSupport;

use ElasticPress\Features;
use ElasticPress\Indexables;

use WPML\ElasticPress\Constants;
use WPML\ElasticPress\FeatureSupport;

class Autosuggest extends FeatureSupport {

const FEATURE_SLUG = 'autosuggest';

public function addHooks() {
if ( ! $this->isFeatureActive() ) {
return;
}

add_filter( 'ep_autosuggest_options', [ $this, 'useIndexByLanguage' ], Constants::LATE_HOOK_PRIORITY );
}

/**
* @param array $options
*
* @return array
*/
public function useIndexByLanguage( $options ) {
$endpointUrl = $options['endpointUrl'];
$defaultIndexName = Indexables::factory()->get( 'post' )->get_index_name();
$this->indicesManager->setCurrentIndexLanguage( $this->currentLanguage );
$currentLanguageIndexName = Indexables::factory()->get( 'post' )->get_index_name();
$this->indicesManager->clearCurrentIndexLanguage();
$options['endpointUrl'] = str_replace( $defaultIndexName, $currentLanguageIndexName, $endpointUrl );
return $options;
}

}
5 changes: 5 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public static function init() {
$indicesManager,
$currentLanguage
),
new FeatureSupport\Autosuggest(
$features,
$indicesManager,
$currentLanguage
),
new Stats\Health(
$indexables,
$networkActivated,
Expand Down

0 comments on commit 313d97b

Please sign in to comment.