Skip to content

Commit

Permalink
Check any status & deindex if the element shouldn’t be searchable
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Dec 6, 2023
1 parent 0541871 commit 29cfaf0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 3.3.3-beta.1 - 2023-12-06
### Fixed
- This beta release is a first try at resolving an issue with deindexing of element not working properly. ([#281](https://github.com/studioespresso/craft-scout/issues/281))

## 3.3.2 - 2023-11-15
### Fixed
- Fixed an error on the Control Panel Utility page ([#284](https://github.com/studioespresso/craft-scout/issues/284))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-scout",
"description": "Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.",
"type": "craft-plugin",
"version": "3.3.2",
"version": "3.3.3-beta.1",
"keywords": [
"craft",
"cms",
Expand Down
37 changes: 29 additions & 8 deletions src/jobs/MakeSearchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ class MakeSearchable extends BaseJob

public function execute($queue): void
{
if (!$element = $this->getElement()) {
return;
}

$this->getEngine()->update($element);
$element = $this->getElement();
if ($element) {
// Enabled element found
$this->getEngine()->update($element);

if ($this->propagate) {
$element->searchableRelations();
if ($this->propagate) {
$element->searchableRelations();
}
} else {
// Element not found, checking if it was disabled and needs to be de-indexed.
$element = $this->getAnyElement();
if($element){
if(!$element->shouldBeSearchable()) {
$element->unsearchable();
}
}
}


}

protected function defaultDescription(): string
{
if (!$element = $this->getElement()) {
if (!$element = $this->getAnyElement()) {
return '';
}

Expand All @@ -63,14 +74,24 @@ private function getElement()
->one();
}

private function getAnyElement()
{
return $this->getIndex()
->criteria
->id($this->id)
->status(null)
->siteId($this->siteId)
->one();
}

protected function getEngine()
{
return Scout::$plugin->getSettings()->getEngine($this->getIndex());
}

protected function getIndex()
{
return Scout::$plugin->getSettings()->getIndices()->first(function(ScoutIndex $scoutindex) {
return Scout::$plugin->getSettings()->getIndices()->first(function (ScoutIndex $scoutindex) {
return $scoutindex->indexName === $this->indexName;
});
}
Expand Down

0 comments on commit 29cfaf0

Please sign in to comment.