laravel-scout-mysql-driver icon indicating copy to clipboard operation
laravel-scout-mysql-driver copied to clipboard

Search on relationships

Open paulvl opened this issue 9 years ago • 14 comments

Hi there, I was using elasticsearch driver and I had no trouble indexing relationships like this:

public function toSearchableArray()
{
    $array = $this->toArray();

    // Customize array...

    $array = remove_from_array($array, $this->appends);

    $extra_data = [];

    if ($this->company) {
        $extra_data['company_name'] = $this->company->name;
    }

    return array_merge($array, $extra_data);
}

But have no idea how to achieve the same with mysql driver

paulvl avatar Oct 28 '16 17:10 paulvl

A separate normalized search table would have to be created to support searching on relationship fields with this driver. I'll try and put some time aside this week to add easy support for this,

damiantw avatar Nov 07 '16 01:11 damiantw

Hi, +1 to question. Any update on this?

cspshadx avatar Nov 29 '16 11:11 cspshadx

Any update on this one?

jorenvh avatar Feb 09 '17 16:02 jorenvh

Any updates? :)

pwnz22 avatar Mar 13 '17 17:03 pwnz22

+1

veneliniliev avatar Aug 18 '17 09:08 veneliniliev

+1

RichardStyles avatar Oct 01 '17 19:10 RichardStyles

@damiantw it's not necessary to create separate normalized search table. You can use left join and use joined table's fulltext index.

Example of working query: SELECT table_1.id, MATCH (table_1.name) AGAINST ('Query' IN BOOLEAN MODE) AS relevance_1, MATCH (table_2.name) AGAINST ('Query' IN BOOLEAN MODE) AS relevance_2 FROM table_1 LEFT JOIN table_2 ON table_1.id = table_2.foreign_id WHERE MATCH (table_1.name) AGAINST ('Query' IN BOOLEAN MODE) OR MATCH (table_2.name) AGAINST ('Query' IN BOOLEAN MODE) HAVING (relevance_1 + relevance_2) > 0 ORDER BY (relevance_1 + relevance_2) DESC

Barcelonczyk avatar Oct 31 '17 13:10 Barcelonczyk

+1

georgearnall avatar Apr 09 '18 21:04 georgearnall

any updates?

Ere5 avatar Apr 16 '19 12:04 Ere5

Anyone have a work around for how to get this to work?

MPJHorner avatar Mar 11 '20 21:03 MPJHorner

https://github.com/ProVisionBG/searchable

veneliniliev avatar Mar 12 '20 08:03 veneliniliev

  1. any updates?

weblabio avatar Nov 07 '21 03:11 weblabio

  1. any updates?

inkomomutane avatar Aug 31 '22 14:08 inkomomutane

@inkomomutane can you please point to the PR that solves the issue I am happy to merge it

msonowal avatar Aug 31 '22 15:08 msonowal