algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
393 stars 85 forks source link

Laravel search records by id #294

Open matthiasvanwoensel opened 2 years ago

matthiasvanwoensel commented 2 years ago

Is there any good way to search records by id?

this is what i get:

`public function toSearchableArray() {

    $array = $this->toArray();

    $array['ticket_number'] = strval($this->id);
     // some other code

    return $array;

}

`

At the moment a created an extra array element "ticket_number", but this doesn't work properly, please can someone help me?

DevinCodes commented 2 years ago

Hi @matthiasvanwoensel ,

Could you explain a bit more what exactly isn't working properly?

The code you sent should add the ticket_number attribute to your records. Please keep in mind you need to add the ticket_number attribute to your searchableAttributes in order for Algolia to search into the values here.

Thank you in advance!

matthiasvanwoensel commented 2 years ago

Hi @matthiasvanwoensel ,

Could you explain a bit more what exactly isn't working properly?

The code you sent should add the ticket_number attribute to your records. Please keep in mind you need to add the ticket_number attribute to your searchableAttributes in order for Algolia to search into the values here.

Thank you in advance!

I cant search in numbers, only in strings ...

I have a field ticket number and a field client_number, both are numbers, but if i for example wants to search a client number (1001 or something like that), i don't get records... while it in the table exists..

` public function searchClients($term) { $clients = Client::search($term); return $clients->orderBy('client_number', 'desc')->paginate(25);

}
DevinCodes commented 2 years ago

Are these attributes configured as searchableAttributes? Could you show us the settings of your index, please? 😄