Skip to main content

How to Extend the Elastic Search Listing Model

The Aero\Search\Elastic\Models\Listingmodel is built up from an array of data returned from elastic search. You can modify the model's attributes through the Aero\Search\Elastic\Pipelines\ListingAttributespipeline.

For example you can change every listing’s name to be “Example”.

It’s important to note that this pipeline is run for every listing that is loaded, everytime. If you use this approach to add a resource intensive calculation it’s important to take steps such as caching so performance isn’t impacted.

<?php

namespace Acme\MyModule;

use Aero\Common\Providers\ModuleServiceProvider;
use Aero\Search\Elastic\Pipelines\ListingAttributes;

class ServiceProvider extends ModuleServiceProvider
{
   public function setup()
   {
       ListingAttributes::extend(function ($attributes) {
           $attributes['name'] = 'Example';

           return $attributes;
       });
   }
}