Commit 7e545ae0 authored by Bert Balcaen's avatar Bert Balcaen
Browse files

Removing field mapping.

parent 48053d00
<?php namespace Rekall\LaravelSolr;
use Laravel\Scout\Searchable as ScoutSearchable;
trait Searchable
{
use ScoutSearchable;
/**
* Generates Eloquent attributes to Solr fields mapping.
*
* @return array
*/
public function getScoutMap()
{
return array_combine($this->attributes, $this->attributes);
}
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
$attributes = $this->toArray();
$map = $this->getScoutMap();
foreach ($attributes as $attribute => &$value) {
if ($attribute == 'id')
$value = $this->getTable()."-$value";
if ($attribute == $map[$attribute])
continue;
$attributes[$map[$attribute]] = $value;
unset($attributes[$attribute]);
}
return $attributes;
}
}
......@@ -124,16 +124,19 @@ class SolrEngine extends Engine
*/
public function map($results, $model)
{
$map = array_flip($model->getScoutMap());
$models = [];
$eloquentResults = [];
$modelClass = get_class($model);
foreach ($results as $document) {
$attributes = [];
foreach ($document as $field => $value)
$attributes[$map[$field]] = ($map[$field] != 'id')? $value : str_replace($model->getTable().'-', '', $value);
$models[] = new $modelClass($attributes);
foreach ($document as $field => $value) {
$attributes[$field] = $value;
}
$eloquentResult = new $modelClass();
$eloquentResult->id = $document->id;
$eloquentResult->fill($attributes);
$eloquentResults[] = $eloquentResult;
}
return Collection::make($models);
return Collection::make($eloquentResults);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment