scout-extended icon indicating copy to clipboard operation
scout-extended copied to clipboard

Laravel search records by id

Open matthiasvanwoensel opened this issue 3 years ago • 3 comments

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?

matthiasvanwoensel avatar Dec 03 '21 10:12 matthiasvanwoensel

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!

DevinCodes avatar Dec 06 '21 09:12 DevinCodes

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);

}

matthiasvanwoensel avatar Dec 17 '21 16:12 matthiasvanwoensel

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

DevinCodes avatar Dec 20 '21 12:12 DevinCodes