Files
timebank-cc-public/app/Polls/SearchEngineWithoutPolls.php
T

92 lines
2.4 KiB
PHP

<?php
namespace App\Polls;
use Laravel\Scout\Builder;
use Laravel\Scout\Engines\Engine;
/**
* Search engine for posts that never indexes a poll: polls are for logged-in profiles only.
*
* Scout checks shouldBeSearchable() only in its own model events and imports, while explicit
* $post->searchable() calls (Posts/Manage, the Scout observers, reindex commands) go straight
* to the engine's update(). Every one of those paths ends in Post::searchableUsing()->update(),
* so the check is made here: polls are removed from the index instead of added. Searching is
* passed through unchanged.
*/
class SearchEngineWithoutPolls extends Engine
{
public function __construct(private Engine $engine)
{
}
public function update($models)
{
$excluded = $models->reject->shouldBeSearchable();
if ($excluded->isNotEmpty()) {
$this->engine->delete($excluded->values());
}
$models = $models->filter->shouldBeSearchable()->values();
if ($models->isNotEmpty()) {
$this->engine->update($models);
}
}
public function delete($models)
{
return $this->engine->delete($models);
}
public function search(Builder $builder)
{
return $this->engine->search($builder);
}
public function paginate(Builder $builder, $perPage, $page)
{
return $this->engine->paginate($builder, $perPage, $page);
}
public function mapIds($results)
{
return $this->engine->mapIds($results);
}
public function map(Builder $builder, $results, $model)
{
return $this->engine->map($builder, $results, $model);
}
public function lazyMap(Builder $builder, $results, $model)
{
return $this->engine->lazyMap($builder, $results, $model);
}
public function getTotalCount($results)
{
return $this->engine->getTotalCount($results);
}
public function flush($model)
{
return $this->engine->flush($model);
}
public function createIndex($name, array $options = [])
{
return $this->engine->createIndex($name, $options);
}
public function deleteIndex($name)
{
return $this->engine->deleteIndex($name);
}
/** Engine-specific extras (e.g. of the Elasticsearch engine) */
public function __call($method, $parameters)
{
return $this->engine->{$method}(...$parameters);
}
}