Overview of Typesense Cloud0:03
All right, so now let's wrap up this course with a review of Typesense Cloud. Alright, so yeah, as it says here on the tin Typesense Cloud is effectively the hosted version of Typesense. So yeah, imagine if in production you just wanna hand over the workload, uh, related to provisioning the server, installing Typesense and configuring it properly. Um, handling scalability issues and concerns, uh, dealing with failover, providing a dashboard to your non-developers so
and concerns, uh, dealing with failover, providing a dashboard to your non-developers so that they can review all of your indices and documents. Uh, maybe they need to create their own collections or custom analytics. If you just wanna hand over all of that work, which is immense by the way, in that case, typescloud is an incredible solution. Lemme show you how to use it. Let's begin by signing up with GitHub.
Create Cluster Configuration0:46
Lemma show you how to use it. Let's begin by signing up with GitHub. Great, nice and quick, let's set up our cluster and of course configure these options according to your organization's needs. I don't have to say that to you, okay? But a quick little note here related to memory, if you're wondering what to select here, well you can start with 0.5 gigs and that's nice because it's free for the first 720 hours.
with 0.5 gigs and that's nice because it's free for the first 720 hours. However, just keep in mind a warning. If you're gonna leverage embeddings like we discussed in the previous episode, it's a lot of ram and with 0.5 gigs, you're almost certainly going to run into memory issues. So at minimum, again, if you're gonna use embeddings, start with two gigs and then work your way up. But yeah, if you're testing, if you're playing around,
with two gigs and then work your way up. But yeah, if you're testing, if you're playing around, if you're working with this course, if can start with 0.5, okay? Everything else can be configured according to your needs. Alright, so let's go ahead and launch it. Okay, and we're in, so now it's configuring and neutralizing our cluster. It'll take just four to six minutes. So through the magic of screen
Generate Keys and Configure .env1:45
It'll take just four to six minutes. So through the magic of screen casting, let's skip over that. Alright, we're all set to go. So now let's generate our API keys and store them as usual within our Laravel Apps .env file. So generate API keys and that will download them here. Alright? And if we open that, we can see our admin API key, our search only API key, which
Alright? And if we open that, we can see our admin API key, our search only API key, which by the way you would use in your JavaScript front ends. And then finally our host. Alright, so let's copy this and switch over to PHPStorm. Alright, let's open our .env file and update these values. But first a quick little note of course, if you want you can still use typesense locally and just reach for typesense cloud in your production environment.
and just reach for type sense cloud in your production environment. However, if you prefer, you could also use cloud in a local and production environment. In those cases, just create two clusters. One cluster is for local, another cluster is for production only, and that way they don't interfere with one another, which you definitely don't want. Okay, so let's do this for that file
which you definitely don't want. Okay, so let's do this for that file that we just downloaded, I will paste it temporarily here. Okay, so we have our admin API key. Of course this is the private key that we don't expose to the world and I'm gonna delete this key when I'm done here. Okay? So I will paste that in. Next we have a search only API key and again, this is what you would reach
Next we have a search only API key and again, this is what you would reach for in your front end if you're using instantsearch.js and you just need a key that allows us to search our collections but not create new ones, that's the key you would reach for. So yeah, just right now let's create a new one and I'll call it typesenseSearchApiKey and then we will tweak that in just a minute. Okay, and then finally the node, well that is going
and then we will tweak that in just a minute. Okay, and then finally the node, well that is going to be our host, so let's paste that in. Okay, so finally, let's clear this out. Our port is going to be 443 because we are using https and I think that should do it. Okay, so now check this out. If I switch back to my dashboard and we switch over to collections, of course we don't have anything at the moment.
Import Data and Explore Dashboard3:47
and we switch over to collections, of course we don't have anything at the moment because we haven't imported our data. So let's do that now from the command line, php artisan scout:import and no change here, we're still importing our course and we'll get that just a moment. All right, and that's done. So let's have a look in our dashboard now. There we go. Now we see all
in our dashboard now. There we go. Now we see all of our data in a nice dashboard ui. So yeah, here's our dummy little courses, dogs and cat training, love Doctor Laravel techniques and all about type sense with the typo included. Uh, and what's even nice is if I scroll down, we have uh, search parameters and we're already super comfortable with this, which is great. So let's say, uh, you know what, I wanna be able
comfortable with this, which is great. So let's say, uh, you know what, I wanna be able to facet by the category. So let's update this and then expand my browser. And if I scroll back up, yeah, now we see the familiar category facet. So it looks like we have four dummy categories here, one for pets and that filters the data, which is great. Okay, so I'm feeling good about this. Why don't we test it out.
Okay, so I'm feeling good about this. Why don't we test it out. So from the command line, I'm gonna boot up php artisan tinker and we're gonna find just the first Course we see here. So app/models/Course.php, uh, let's see which one we get. Alright, we get all about type senses. Okay, let's go ahead and finally fix that typo or that capitalization issue. So I'm gonna say courseName =
or that capitalization issue. So I'm gonna say courseName equals uh, let's change it entirely. The type sense course now I'm gonna save it locally and we've learned that it will automatically sync via Eloquent model events that Scout hooks into. So that means if I switch back to our dashboard and maybe give this a quick refresh, let's see if it works. Uh, dog and cat training, love doctor, where are you? There we go. It has been synchronized perfect.
Uh, dog and cat training, love doctor, where are you? There we go. It has been synchronized perfect. This is exactly what we want. And sure enough we can see the embedding, which of course they're not going to display all of. They definitely don't wanna do that. Okay, this is looking good. We can perform searches. So let's say doctor, and of course love doctor is going to come up first and we can review all of the various scores.
Update instantsearch.js Setup5:54
and of course LoveDoctor is going to come up first and we can review all of the various scores. Okay, so now let's integrate this into our little instantSearch.js example. So back to my editor, let's open our routes file and yeah, I'm going to return that inertia view that we created a handful of episodes ago. I'll say inertia render search index. Okay? And if we open this up, yeah, you'll remember this is where we pulled in instantSearch.js.
And if we open this up, yeah, you'll remember this is where we pulled in instantsearch.js. We uh, instantiated our typesense adapter, we configured it and then we rendered the data. But you'll notice here this is still set up for when we were working with the books collection and now we are working with courses. So yeah, this is a cool opportunity to put our learning to the test and see if we can make everything work. Okay, let's do that. Now. First up, the server credentials.
to the test and see if we can make everything work. Okay, let's do that. Now. First up, the server credentials. Ideally I would love to not duplicate everything. For example, the API key. Yeah, I don't wanna have to just say, well let's go right here. Let's copy that, let's paste that in. Uh, you can if you want and it's fine. But instead, here's what we can do. If we're using Laravel
But instead, here's what we can do. If we're using Laravel and Laravel Vet, what I can do is prefix any of these values with VCO and then instantly it will be exposed to our front end. So yeah, what we might wanna do is have, um, two sets of values. So let's do this, let's double these up and then we will remove any that are not required. But yeah, notice if I were to say, uh, let's say typeSense
and then we will remove any that are not required. But yeah, notice if I were to say, uh, let's say type search right here and I proceed them with vco. Now these values will be available to me. So here's what we could do. I don't want my privateKey sent to the front end. I want the searchKey. So what I could do is take this searchOnlyApiKey and update it here. Okay, so now this version is the privateKey
and update it here. Okay, so now this version is the private key and we could even add a note, privateKey, uh, privateAdminKey. And then this version down here is the searchOnlyKey. All right, very cool. So now I can get rid of that value as well as this one. And now all of this data is safe to send to the front end. So now check this out. If I return to our view, we can access those values.
So now check this out. If I return to our view, we can access those values and real quick I'll show you as an alert, uh, by saying import.meta.env. And then I provide our value. So in this case we want VITE_SOME_API_KEY, uh, let's do this, let's boot up VT and then load this in the browser. And sure enough, we get the value it's working. Very cool. So switch back and now let's update these.
And sure enough, we get the value it's working. Very cool. So switch back and now let's update these. So once again, import .env, typeSenseAPIKey. And then to save myself some time, I will replace these typeSenseHost, typeSensePort, and then finally typeSenseProtocol. Perfect. Okay, next, for the search brands, we are dealing with courses.
Perfect. Okay, next, for the search brands, we are dealing with courses. So let's do this. Uh, let's go back to our collection for courses. And let's have a look. A course consists of a name and a description. So let's reference those values here. To start, we're just gonna query by the name only sort by, I will comment out, but you can tweak that how you need to. And then we'll scroll down and update these values.
I will comment out, but you can tweak that how you need to. And then we'll scroll down and update these values. So I don't care about publication year, we don't have authors or a published date, we just have the name of the course. And then right at the top, let's configure that. The index name that we are working with of course is called courses. And then finally for faceting, we're gonna do, uh, categories.
And then finally for faceting, we're gonna do, uh, categories. And again, remember just to drill this into you, category is coming from this value here and that's available because when we declared it within config/scout.php by looking for category, we declared that it should be treated as a facet. And so it's, okay. So one more time. Is this everything? Let's do our final review. Uh, yeah, we instantiate it properly, query
Let's do our final review. Uh, yeah, we instantiate it properly, query by the course's name, we reference the appropriate index name. We have a facet for categories. Actually, why don't we just call it category? Uh, and then we have a search box. This is all looking correct to me. So let's cross our fingers and have a look in the browser to see if it's working.
So let's cross our fingers and have a look in the browser to see if it's working and ta it works. So we have our four ridiculously named courses. I can filter them using the category, facet frameworks, pets. I can't decide do I want a dog course or a Laravel course. Which one do I need? Here we have lightning fast search. Of course we have typo tolerance out of the box. Uh, it's really amazing stuff.
Set Up Analytics Rules10:54
Of course we have typo tolerance out of the box. Uh, it's really amazing stuff. Okay, so now I wanna finish up by showing you what you might research next. So heads up, this is the last episode in the course, but who knows, maybe in the future we'll have some bonus episodes that show you how you can take things even further with some examples. Okay? So let's do this. Come down to analytics rules. This is your homework, check this out.
Okay? So let's do this. Come down to analytics rules. This is your homework, check this out and research how you can leverage this in your own projects. So imagine two examples. Imagine you wanna track the most popular queries, uh, in, in thisCase@larcast.com. How would you do that? Well, couldn't we just listen for what the users search for and then store them in their own collection and, and track them?
and then store them in their own collection and, and track them? And then we could use that to provide feedback. Here are the popular searches we can provide instant, uh, recommendations. That would be amazing, right? Or what if instead we wanted to track which search queries produce no results at all as you see here? Well, that could be an indication that hey, you need
as you see here? Well, that could be an indication that hey, you need to develop this course because everyone's searching for it, but it's nowhere to be found on your site. And that's really cool. Okay, so very quickly, just to give you an idea of what you might wanna do, if you want to track all of the popular queries, well, you could call this popularQueries, um, rule, name it whatever you want, you declare the source. In this case, we're using courses as our source.
name it whatever you want, you declare the source. In this case, we're using courses as our source. And the destination would be, well, where are we going to deposit, uh, all of the data? Well, we need a special collection for that. So very quickly, let's create a new collection directly from the dashboard, like this new collection. So let's call it popularQueries. And if you're wondering, well, what fields do we require? Of course you can check the documentation,
And if you're wondering, well, what fields do we require? Of course you can check the documentation, you only need two. So if we open the API reference for typesense, let's scroll down to query suggestions and specifically, uh, how to create the rule. Yeah, this is what we want. We need two fields. So I will swipe that and paste it in right here. Okay, so we have one for q of course, that's the query that is a string.
Okay, so we have one for Q of course, that's the query that is a string. And then finally the count, uh, to track how many people are searching for that. Okay, finally, we can get rid of these. And we have our custom collection for popular queries created through the dashboard. Okay, so now if we scroll back to our analytics, let's do it one more time. We're gonna track popular queries.
let's do it one more time. We're gonna track popular queries. The source is going to be courses. The destination to track all of those popular queries will be its own collection. And let's limit it to the top thousand search results. And believe it or not, that's it. It's now going to be begin tracking all of our searches. And just keep in mind it's not in real time. So for example, if I were to say, uh, Laravel
And just keep in mind it's not in real time. So for example, if I were to say, uh, Laravel and we immediately go back and check, well, maybe we'll see something, but I imagine it's queued up every five minutes or so. So let's go into our collection for popular queries. And yeah, I don't see anything yet, but let's do this. Let's search for a couple things. Let's go for doctor. All right, and then maybe one more cat and I'm gonna step my fingers.
All right, and then maybe one more cat and I'm gonna step my fingers and we're gonna wait just a few minutes for this to populate. Alright, and here we go. So I pause for just a few minutes and now we can see that our popular queries collection is well populating. I can see searches for DoctorCat and then finally Laravel. So of course now you can use this internally to track
I can see searches for Doctor Cat and then finally Laravel. So of course now you can use this internally to track what are my users interested in. But like any other collection, you can also expose this to your users so that they can see here's some popular queries that folks are interested in. Maybe you would like to search for that as well. Okay? So that's gonna do it for typesense cloud. Of course, there's so, so much more to this,
So that's gonna do it for type sense cloud. Of course, there's so, so much more to this, but this'll get you going. And then further we are done with this course. It has been a massive investment on your part and I really do appreciate you for sticking to the very end like you have. So that's gonna do it. But you know what, if there are other things, if there are other examples you would like to see,
But you know what, if there are other things, if there are other examples you would like to see, let us know in the comments below and maybe we'll come through. I'll see you later.
