Wildcard Search Results0:03
All right, welcome back. So now in this video, let's get comfortable. So once again, I'm gonna run course search and I'll use the * to represent anything, and I'll get the results and return them as json. All right. Have a look in the browser and yeah, like we saw at the conclusion of the last video, we get our results. But in this case, because I used a * for the search query, we are
Inspecting Returned Models0:21
But in this case, because I used a star for the search query, we are effectively searching everything, right? So in this case, it, it'll fall back to the default sorting, uh, mechanism, which in this case would be insertion order. So that's why we get the most recently created, uh, record first, and then it works its way down. Okay, very cool. But now take a look at this. Uh, if I instead just simply run dd on this and we take a look at what's actually being returned,
Uh, if I instead just simply run dd on this and we take a look at what's actually being returned, we get an Eloquent collection that consists of items. But notice that each item itself is a Course instance. And this is really cool, right? So before, when we were manually working with the client, we would get that response and then we would have to manually, uh, go through the hits and pluck out the information we need. But in this case, Scout is converting it back into the, uh,
Using Raw Responses1:05
and pluck out the information we need. But in this case, scout is converting it back into the, uh, the appropriate course, um, models or instances, which is really cool. So we have access to all of this data, which is great. Okay? But take a look at this. Now, if we swap out get with raw, yeah, as you might expect, this will now give us the raw type sense response rather than converting it back into Eloquent instances. So now if I give it a refresh, yeah, this is going
than converting it back into Eloquent instances. So now if I give it a refresh, yeah, this is going to look very familiar to you at this point. So now we can dive into the hits, uh, like we did before, if we are using highlighting, we could get it this way. We could go into the document, we could read the information that we want, which is great. So now imagine we want to search for this word, whatever that word happens to mean.
Filtering with Where1:48
So now imagine we want to search for this word, whatever that word happens to mean. Uh, but I wanna limit it. I wanna filter it down to only the courses that were created by this User with an ID of 500. I'll show you how to do that with scout. First, let's save this to courses. We will get the results and then we will return the results as json. Okay, so now all we have to do is insert our query.
and then we will return the results as json. Okay, so now all we have to do is insert our query. Yeah. And once again, we have our results. But notice that each Course was created by a different User. So imagine you want to filter things down. You want to effectively say, gimme only the Courses that were created by this particular User. Those are the ones I care about, right? Alright, well we can use this where method here. Now, be a little careful.
Alright, well we can use this wear method here. Now, be a little careful. Uh, I know this looks like the same wear that you would use when performing, um, Eloquent queries against a relational database. It's not the same, right? Type sense is not your relational database. So with that in mind, just remember it's, it's very primitive support. You're not gonna do really fiy stuff.
it's very primitive support. You're not gonna do really fiy stuff. You can do simple number and string based checks. So for example, if I wanted to say, alright, search all Course models for this keyword, but filter them down to only the ones where the userId is 500, yeah, once again, this is something you could do. So if I come back and give this a refresh, in this case, the way we set up our seating, uh,
So if I come back and give this a refresh, in this case, the way we set up our seating, uh, every Course belongs to a unique User. So we get exactly one response, but sure enough, it is working, which is great. Okay, so now maybe we wanna say, alright, well search for this key word, but I only care about the Courses where the category is set to languages. So yeah, once again, if you wanted to implement your own filtering system, um,
So yeah, once again, if you wanted to implement your own filtering system, um, this would be a simple way to do it. Once again, we get only courses that include that keyword, but also have a category of languages. That's great. Um, next. So if we come back to our query, check this out. If we turn it back into *, once again, that just means everything, right? But now we're saying, well give me everything
that just means everything, right? But now we're saying, well give me everything but filter it down to only the ones where the category is languages, right? So again, this is a nice way, if you just wanna click on a category and then see all of the matching results, uh, you could use * for that and that would be fine, right? You could do all of this through, uh, through type sense. But of course the real power is when you are
Paginating Search Results4:12
You could do all of this through, uh, through type sense. But of course the real power is when you are performing, um, queries. Now we can also paginate our results using Scout. So once again, the API is going to be very similar to what you're used to when working with Eloquent, and that's intentional. I just want to remind you that when you call here, you're not calling the same method as when you normally do something, uh, like this, right?
you're not calling the same method as when you normally do something, uh, like this, right? And that's because when you call this search method, you're actually getting a Scout specific builder, and that's how everything can be prepared for TypeSense, right? So when I call page eight here, notice that I actually have a Scout\Builder class, um, that once again will take care of it in the same way we would normally expect,
that once again will take care of it in the same way we would normally expect, but the, the implementation and, and the way it goes about doing that is a little bit different. Mostly, you don't need to worry about that though. And that's the great thing about Scout, uh, and how it integrates with Laravel. You can use the knowledge you already have and it's just going to work, which is great.
Request-Based Search Query5:06
You can use the knowledge you already have and it's just going to work, which is great. Alright, so let's bring that back to get, and yeah, if we wanted to reproduce what we had, uh, originally, here's what we might do. We don't need this variable. We will return the results and let's put these on their own line and we'll say search. And we're gonna look in the request for q, but I will default to * there.
And we're gonna look in the request for Q, but I will default to star there. Okay? So now if I give it a refresh, once again, let's search for this word here and I'll just manually add it as the query string. And now we once again get only the results where I think that was the one I, I, uh, copied where that word is referenced, which is really cool. Alright, so now that you understand the basics of querying with scouts in the next episode, we need to figure out,
Alright, so now that you understand the basics of querying with scouts in the next episode, we need to figure out, okay, well how do we add new records into our index? Or if I update a table, how do I then ensure that it gets synchronized with your typesense collection? Or if I delete something, I need to make sure it gets deleted. Or what about situations where maybe certain courses should not be searchable? How do we allow for that? Well,
where maybe certain courses should not be searchable? How do we allow for that? Well, I'm gonna show you it all in the next episode.
