در حال بارگذاری ...

Querying Algolia in Tinker0:00

Alright, so now that we've done all the setup, we've pushed our indices up to Algolia in this case, now let's figure out how to query that engine. Okay, so I'm going to go to php artisan tinker, and now this is pretty nice. We have a search method right on the builder. So if I were to say, app.film, search, and let's just look for Zoolander in this case. Okay, well if I run it just like this, I'm going to get a builder instance. So this is just like a query scope. search for Zoolander, fetch the results, but then behind the scenes it's actually going to query Algolia's API in this case because that's the driver we chose. And once again, remember, you can use a different driver.

Paginating Search Results0:36

because that's the driver we chose. And once again, remember, you can use a different driver. You can write your own. For development or testing, you probably want to use Laravel's null driver. All of those are available. But anyways, if we take a look, we return all of the results where, I'm surprised there's so many actually, where Zoolander is included in the title. And you can even paginate these. So I could say, search for Zoolander and paginate those into sets of three.

Understanding Search Ranking0:57

And you can even paginate these. So I could say, search for Zoolander and paginate those into sets of three. And now you're going to get, just like performing a regular Eloquent query, you'll get an instance of Paginator. So if I were to say first, you get the basic idea. But now let's talk a little bit about search rankings. I have my film index, and let's just do a query. I saw this American title when looking through our database, so we're going to look for that. And we get some results, American, American, but also African. Isn't that interesting?

Updating Indexed Attributes5:52

So now if I save it, and we come back to our Film index, and we look for African, you'll see that we only get three. So the Zoolander record was not included because we are not indexing special features. But now, let's do one more thing. Let's go back. Let's just stick with Zoolander. And we're going to change the description once again to have Ancient Africa. Okay, so now if I search for African again, it should once again be included in the results.

Adding a Search Route7:05

Okay, but anyways, you can dig into that quite a bit more. You can go through the advanced settings, whether to allow typos, all of that stuff. But the important thing is that for you, you're going to call this search method on your Eloquent object. So if we were to open this up in Sublime, yeah, imagine you have some kind of search route, and maybe actually we'll do film/search/query. How about that? Now I could say return app('film'),

How about that? Now I could say return app Film, search for the query, and then give me the results. And now the same is going to be true where if you return an Eloquent model or a collection from a route, it will be cast to JSON. So now if we were to try this out, scout.dev/films/search/African, and we get the exact same results. So okay, that's really the gist of working with Scout.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟