Laravel Scout with typesense

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
L Scout adds a file teex search for your eloquent models through multiple drivers next to my search Alia and the database driver you can now use a new driver which is typ sense here's how it works I'm here at laa Scout documentation page and we're going to start by installing Scout into one of our level applications and we're starting by requiring it through composer let's do this together here all right let's already see what's next we need to publish the config file let's do this as well here all right we're going to need this later then we need to add the searchable trade to the model that we want to add our search to in my case this is my recipe model here and we should already see now the searchable trade here it is level Scout searchable all right what's next Qing is not so interesting to us right now so we're skipping this and we're going right to the type sense documentation here which is here so type sense is a lightning fast open source search engine and supports keyword search catic search Geo search and Vector search so it comes with a lot of cool features and you can self-host it or can use the cloud I have selfhosted it on my Mech there are a couple of options um for how to do this but just for showing what it looked like in my case here I started here after installing a new type sense server all right now we need a PHP SDK for type sense let's bring this in here as well all right and we need some environment variables here you can copy them but I have already prepared them here in my application here let's bring them in so the Scout driver is now typ sense the API key is what you set when you start a new typ sense server then you need to Define his API key in my case it's XY Z I think that's also the default value and we using it through Local Host all right those additional ones we don't need and I think we're already here at the part where we need to prepare our data for type sense so first we're going to need this two searchable array which you need for all of our Scout drivers but let's copy this one to our recipe model let's bring this in here here we go let's add a return type and what we're doing here is we're merging the data from our recipe model with the ID which is string and the created ad which is a Tim stamp so these are two fields which are required by types send so this is why we need to merge them into our data from our recipes all right what's next yeah next we need to check out our config Scout file so let's take a look at this here together so here we have our Scout config file so there are a lot of things that you can check out but we are interested in type sense so here we have type sense s configuration and here most important to us is let's go down here the model settings so you can see here example for every model that you want to support we need to define a collection schema and the fields and then what are the names like ID what is the type string and so on I have already prepared this for our recipes so let's bring this in now together here we go so let's take a look yeah so again we are talking about recipes in this example so maybe let's also take a look at the database here in PHP storm so we have 30 examples of recipes Classic Pizza margarita with some ingredients difficulty and the quiz in whatever that is so these are our examples for this demo here so this means here we also need to define the fields that we want to support so for example the name ID is a string then we have the name name which is a string we have the difficulty which is a string qu seen as a string and ingredients which is an array of strings and then we also have created at and then down here we also have to Define our search parameters so what terms are we searching for in our case we start by just searching for the name field which again in our case is the name of our recipes all right let's take another look yeah also important if you make any changes and want to delete data you can do this with Scout Flash and if you want to reimport you can do this with Scout import Scout also works with observers so this means whenever you create a new recipe in this example it will already be imported to typ sense or to the other drivers but yeah at the beginning you need to import this we a scout import let's try this together Scout import and then you need to provide the model name looks like this is working we have 30 records which were imported which is perfect and now I think it's a good idea to give this a try and we're going to do this here in Tinker well first let's see if we get all of our recipes you can see this works and we get them here but now we want to search for them and through level Scout we have now this search method which we can use and now let's search maybe for pizzza and then get the results and let's also get back an array and here we go we have our classic margarita pizza this works nicely let's try something else maybe let's go for pasta everybody loves some good pasta shrimp scumpy pasta chicken alfredo pasta amazing this works as well but maybe we want to look for something else maybe want to look now for ingredients here so let's try this out as well we just need to add to quy by here also ingredients ingredients let's search for sugar and we do have some results here Italian tiul let's check it ingredients yes here sugar what else Thai green curry what's in there it's sugar something else here butter chicken and of course what's in there is sugar as well and maybe one more thing let's also look for cine and now we're searching for Italian here we go we get the Italian triu where Italian is in the name I'm pretty sure it's also the quisine but now we also have here for example the pasta way tail is only in the cuisine so this seems to be working as well pretty cool there is much more that you can learn from typ sense and Scout so please make sure to check out the official documentation for type sense and for scout as well but I hope you now have a good understanding of how you can use typ sense with Scout it's really great to have another open source option for scout a big thanks to the typ sense team and have fun with the new Scout driver happy searching [Music] bye
Info
Channel: Laravel
Views: 8,265
Rating: undefined out of 5
Keywords:
Id: 0o3Ua52Y6pU
Channel Id: undefined
Length: 7min 9sec (429 seconds)
Published: Fri Feb 16 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.