nqxcode / laravel-lucene-search

Laravel 4.2, 5.* package for full-text search over Eloquent models based on ZF2 Lucene.
73 stars 28 forks source link

Working with relationship #53

Closed visualight closed 6 years ago

visualight commented 7 years ago

I use the version 2.2.* of Lucene Search. Some tables of my database have data in another table.

  1. How i can make a search that return all data (relationship method). I try this but the data returned in collection not link the relational table : "users".
public static function searchableIds(){
    return self::where('status', 2)->where('active', 1)->with('users')->lists('id');
}
  1. How can I do (with an example) a search on my "product" table with the table where my product type is stored (product_type: table)? What I want to do is search for example on the word: airplane (stored in my product_type: table) and that this search returns all data related from the "product" table ??

Thank you

nqxcode commented 7 years ago

For indexing of data from other tables, you should use indexing for optional fields (see https://github.com/nqxcode/laravel-lucene-search#indexing-of-dynamic-fields). For example, 1) in config for product model add option: 'optional_attributes' => true 2) in product model add accessor like this:

public function getOptionalAttributesAttribute()
{
    $typesAttributes = [];
    foreach($this->types as $type) {
        $typesAttributes["type_{$type->id}"] = $type->name;
    }

    return $typesAttributes;
}