Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sphinx 2.2 empty result #14

Open
IvanBurykin opened this issue Jun 11, 2021 · 1 comment
Open

Sphinx 2.2 empty result #14

IvanBurykin opened this issue Jun 11, 2021 · 1 comment

Comments

@IvanBurykin
Copy link

IvanBurykin commented Jun 11, 2021

Getting no results on Laravel 8 and Sphinx 2.2
Problem in src/SphinxEngine.php
public function map(Builder $builder, $results, $model)
{
if ($results->count() === 0) {
return $model->newCollection();
}

	$objectIds = collect($results->fetchAllAssoc())->pluck('id')->values()->all();

	$objectIdPositions = array_flip($objectIds);
	return $model->getScoutModelsByIds(
		$builder, $objectIds
	)->filter(static function (/** @var Searchable $model */ $model) use ($objectIds) {
		return in_array($model->getScoutKey(), $objectIds, true);
	})->sortBy(static function (/** @var Searchable $model */ $model) use ($objectIdPositions) {
		return $objectIdPositions[$model->getScoutKey()];
	})->values();
}

$objectIds = collect($results->fetchAllAssoc())->pluck('id')->values()->all(); - return an array of Strings
in_array($model->getScoutKey(), $objectIds, true); - here requires Strict in_array, id - integer, objectIds - Strings

As a solution -
public function getScoutKey()
{
return (string) $this->id;
}

But it is not goes outofthebox

@otobio
Copy link

otobio commented Aug 8, 2021

I can confirm the above issue and the suggested solution does work. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants