Skip to content

Commit

Permalink
Merge pull request #77 from vlopes11/master-issue-69
Browse files Browse the repository at this point in the history
Display results with a WHERE CLAUSE #69 - Simple comparison where clause
  • Loading branch information
nticaric authored Mar 31, 2017
2 parents 1e2906e + 7ff5de8 commit 34fc1b7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Engines/TNTSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class TNTSearchEngine extends Engine
*/
protected $tnt;

/**
* @var Builder
*/
protected $builder;

/**
* Create a new engine instance.
*
Expand Down Expand Up @@ -122,6 +127,8 @@ protected function performSearch(Builder $builder)
$limit = $builder->limit ?: 10000;
$this->tnt->selectIndex("{$index}.index");

$this->builder = $builder;

return $this->tnt->search($builder->query, $limit);
}

Expand Down Expand Up @@ -154,14 +161,17 @@ public function map($results, $model)
}

$keys = collect($results['ids'])->values()->all();
$fieldsWheres = array_keys($this->builder->wheres);
$models = $model->whereIn(
$model->getQualifiedKeyName(), $keys
)->get()->keyBy($model->getKeyName());

return collect($results['ids'])->map(function ($hit) use ($models) {
return $models->has($hit) ? $models[$hit] : null;
})->filter(function ($model) {
return !is_null($model);
})->filter(function ($model) use ($fieldsWheres) {
return !is_null($model) && array_reduce($fieldsWheres, function ($carry, $item) use($model) {
return $carry && $model[$item] == $this->builder->wheres[$item];
}, true);;
});
}

Expand Down

0 comments on commit 34fc1b7

Please sign in to comment.