---
title: "Free, fast, full text search: Laravel + Typesense"
url: "https://aaronfrancis.com/videos/free-fast-full-text-search-laravel-typesense"
path: "/videos/free-fast-full-text-search-laravel-typesense"
type: video
author: Aaron Francis
published: 2024-09-16
topic: "Laravel & PHP"
keywords: [typesense, full-text search, laravel scout, vue, instantsearch, search ui, search highlighting, laravel, typesense adapter, search snippets, transcript search, search schema]
youtube_url: "https://www.youtube.com/watch?v=bDLVeJQei_Q"
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Free, fast, full text search: Laravel + Typesense

## Chapters

- Introduction and Overview
- Integrating Typesense with Laravel
- Installing Typesense Locally
- Using Laravel Scout with Typesense
- Configuring Laravel Scout for Typesense
- Making a Model Searchable
- Setting the Searchable Schema
- Configuring Typesense in Laravel Scout
- Importing Data into Typesense
- Using Laravel Prompts for Command-Line Search
- Testing Search Functionality with Laravel Prompts
- Exploring Search Results with Transcript Highlights
- Setting Up the Frontend with Vue.js and InstantSearch
- Installing InstantSearch for Vue.js
- Building the Search UI with InstantSearch Components
- Integrating the Typesense Adapter and Configuring Queries
- Implementing Highlighting in Search Results
- Using Snippets for Large Transcripts
- Enhancing the UI with CSS and Line Clamping
- Final Thoughts

## Transcript

**Aaron Francis:** Here's the plan for this video. I wanna get full text search going on one of my course websites. Specifically, we're gonna do highperformancesqlite.com. It's a very good course. If you're looking to learn SQLite, please go check it out. What I need to do is give the user the ability to search across all the titles of the videos, but more importantly, across all the transcripts, and the transcripts are many tens of thousands of words.

**Aaron Francis:** I think it's, like, seven, eight, nine hours of content, and so you can imagine that is a lot of words. We're gonna be using Laravel with Typesense here, and Typesense did sponsor this video, so thanks Typesense for keeping my dreams alive. I appreciate that. Um, we're gonna be integrating Typesense with Laravel Scout, and then in the end, with Vue.js.

**Aaron Francis:** The first thing I need to tell you is Typesense is open source. What I'm gonna be showing you here, I didn't pay anything for. I actually didn't even create an account for any of this. I just Brew installed it, and I'm running Typesense locally. So that's kinda nice. The second thing we have to talk about, for goodness sakes, if you load typesense.org, they default to recipes with steam- like steamed mussels.

**Aaron Francis:** Nobody wants that. So, let's go ahead and type in pizza. That's a lot better. Homemade pizza dough, much better than steamed broccoli. So, this is what we're gonna be using. Um, I have already completed this behind the scenes, because, uh, dealing with Homebrew can sometimes take a long time. This actually didn't, but I installed a Brew Typesense server, and then I started the server.

**Aaron Francis:** So it is running here on my Mac. You don't have to do it this way. You could do Docker, Kubernetes. You could, you could do a bunch of different ways. I just did it this way because it was easiest. I will say, if you don't wanna muck around with any of that, they do have Typesense Cloud, which is a hosted version, and that can make your life a lot easier, depending on kinda what you're after.

**Aaron Francis:** Moving on. We have already installed this. We're gonna be using Laravel Scout, and fortunately, Laravel Scout has documentation for Typesense. If you're not familiar with Laravel Scout, it's a first-party package from the Laravel team that adds full text search to your Laravel application, and it is driver-based. So it provides a common interface, and you can use any one of the drivers.

**Aaron Francis:** We're gonna be using the Typesense driver. That is the whole point of this video. So, first thing we're gonna do is we're gonna require Scout and the Typesense, uh, PHP SDK. So we're gonna install both of those things, and then after that, I think what we probably wanna do is we wanna say vendor publish, and we're gonna look for, not Typesense.

**Aaron Francis:** We're actually gonna look for Scout. So we're gonna publish the, uh, scout.php, which is the config file. So, hopping over to PHP Storm, let's look at scout.php, and here we go. There is already a Typesense, um, a Typesense array in here, and so you can see these are the different configurations.

**Aaron Francis:** Algolia, Meilisearch or Meilisearch, I never know. Um, and the default is set to, if we come all the way up here, you'll see that the default is set to Algolia. So, let's hop over into our ENV, and we've already set that to Typesense. So we're good there. And coming back here, and we'll look for Typesense.

**Aaron Francis:** This is the default. So when you, uh, Homebrew, when you Brew install it, it is set up to localhost 8108, and so we should be good to go there. Now, the next question is, how do we get all of our data out of our database into the Typesense indexes? And fortunately, Scout makes this super easy.

**Aaron Francis:** So we're gonna open models video here, and we're gonna say that it is searchable. Eh, that's pretty much all we have to do. We're gonna add a few things here, and so let's say, uh, searchable as, and we're just gonna give this an index name. So we'll say video index. And that, uh, lets us control the name of the index, which we will need on the front end later.

**Aaron Francis:** And this also lets us separate... Let's say we've got, uh, users and documents and videos, and we wanna be able to search them one at a time. That's how we do this. Now, we also need to do toSearchableArray. So what toSearchableArray does is instead of sending the entire video object over, which may con- contain a bunch of columns I don't actually wanna search against, this lets us control what we send to Typesense.

**Aaron Francis:** So here, what we're gonna do is, in fact, let's check the docs, because there's one interesting thing that we have to do here. We have to cast the ID to a string, and we have to cast createdAt to a timestamp. So we're gonna yoink. That's mine now. And whoops, messed that up. And we're gonna put that in...

**Aaron Francis:** Actually, I just want those parts. I wanna do this all myself. So, we're gonna put that in there. That is correct. So, because of the way that Typesense works, you have to cast it to a string and to this, um, this integer instead of a date time object. The only other things that I wanna include, I wanna say, let's do title, and let's do transcript.

**Aaron Francis:** So for transcript, I'm gonna say this, this-transcript, and then I know that it is a JSON, so we're casting transcript to JSON, and then all the good stuff is inside this content key. So that's all, that's all we're sending over. We're sending over the ID, which is required to link up Laravel's eloquent and Typesense.

**Aaron Francis:** We're sending createdAt as an integer to help sort, and then the two things we actually wanna search against are the title and the transcript. Now, this is our, this is kind of our schema, right? This is our searchable schema. However, we need to be more explicit about that. So coming over to scout.php, back in the Typesense, if you scroll down here, you'll see you've got model settings.

**Aaron Francis:** And so what I'm gonna do here is I'm gonna uncomment these, and I'm gonna say, instead of, uh, user, it's actually video. And fields, we have ID as a string, which we just talked about. We have, uh, name as a string, which in our case it's actually title, and we have createdAt as an Int 64, which was that timestamp conversion we did on the carbon object.

**Aaron Francis:** So we're good to go. The only thing we need to add is transcript type string, default sorting createdAt. Query by, we don't have name anymore. Name doesn't make a lot of sense. I'm gonna put title first and then transcript. You can, um, assign different weights, so you can say that a, a hit on title is worth three times as much as a hit on transcript, for example.

**Aaron Francis:** You can add that parameter right down here. I'm not gonna do that right now because according to the documentation, whichever one you put first has the highest weight if the weights aren't specified. Title first, transcript after. Hey, seems pretty good to me. All right, so we're good to go. We're this close to importing all of our data and being able to search.

**Aaron Francis:** We're gonna start by searching on the command line 'cause it's very easy to set up, and then we're gonna muck around on the front end and set up a little bit of a, a little bit of a nice autocomplete. We love a little autocomplete. So before we do that, we have to... Let's look at AR Scout. AR is just my shorthand for PHP Artisan. Here are the scout, uh, options.

**Aaron Francis:** Delete all? No. Delete, flush, import. That looks like the one we want to do. So import a given model. So let's clear this out, AR Scout import, and let's see what we get. Missing model. Perfect. So the model is app, models, video. Now, if we run that, we see 141 videos were imported into Typesense.

**Aaron Francis:** Everything seems to be working so far. It seems too good to be true. Let us, um, let's do composer require Laravel prompts. We're gonna have a little fun here. And there we go. Almost. There we go. Okay, so we have now, we've imported all of our videos, and we've required Laravel prompts.

**Aaron Francis:** So we're- what we're gonna do is, this is m- this is my command where I just do stuff. Um, so we're gonna take search, and we're gonna import, we're gonna import Laravel prompts search. And let's see what we need to do here. Label, options, placeholder. So we're gonna do it like this. We're gonna say label, um, search for a, search for a video.

**Aaron Francis:** Then options. Options takes a closure. So let's make this a little not insane, and we'll say that the closure accepts a string of value. And if, um, let's do if strlen of value is greater than zero, then we're gonna do some kind of search.

**Aaron Francis:** Otherwise, we're gonna return an empty array. So the search that we're gonna do, let's break out here and here. The search that we're gonna do is using Laravel Scout, which under the hood is going to use Typesense. So we're gonna say video search for value. That's the interface. That's it. That's all you have to do. And then we're gonna say get all of those, and then we're gonna pluck.

**Aaron Francis:** I don't remember the order that we're supposed to pluck them in. I think it's title, ID, and then we're gonna turn that into an array. So let's just see if that worked. That would be pretty awesome if that actually worked. Um, so if we run and we do... Actually, I honestly, I'm not gonna lie, I did not expect that to work first time.

**Aaron Francis:** I thought I was gonna have to cut and retake that. Ah. I love it when it works first time. Okay, so, eh, it worked. I'm not super impressed because I'm searching basically by title, and so what if... I, I, I guess I am impressed, but I'm not proving that it's searching by transcript also. So if I type favorite, I remember when I was recording this course talking about how my favorite data transport format is JSON.

**Aaron Francis:** So this makes sense to me that JSON is coming up first even though favorite is not in the title. So we have now, we can go back to JSON, or we could go back to indexes is probably everywhere. And so now if we do that, then there you go. We've got, we've got nonsense because I didn't do anything. So if we did ID equals that and dump out the ID and run this again and do indexes, now that's the ID of the video that we just selected.

**Aaron Francis:** It's very cool so far, right? In a matter of just a few minutes, we've set up Typesense, we've got Laravel Scout running, we imported all of our data, we ran a search, we used Laravel prompts, which is awesome. It's very cool. I think the real use case is not running it on the command line. As much as I just wanna say, "Hey, look, it's cool.

**Aaron Francis:** Awesome. Thanks. See ya," s- come on. Hey, we- people wanna see this on the front end, right? So we have to carry on. And the good news is we're, we're back here on the Typesense documentation right where we left off with the Homebrew installation. But come down here to search UI components. Using InstantSearch JS, the good folks over at Algolia have built an open source set of UI components, React, View, and Angular.

**Aaron Francis:** So there's this interesting thing happening amongst all these search competitors where they're like, "Ooh, let's all do the same front end. We can customize it, whatever, and we'll build our own back ends." Kind of awesome. Makes everyone's lives much easier, so thank you for doing that. If we look, we've got View, or I'm sorry, Algolia Instant Search here. It is a monorepo, so it's got the React, View, and Angular all in here.

**Aaron Francis:** And then we have the Typesense adapter that is Typesense Instant Search adapter. So we're gonna be using both of those things together, and I'll leave links to this down in the description. And so let's hop over here, and we are gonna NPM install the CSS And then TypeScript, that's the adapter, and then vue-instantsearch, because we're using Vue.js locally.

**Aaron Francis:** And if we run that, uh, dah, that worked a lot faster than I expected, and with a lot, a lot fewer, uh, warnings. So now we've got all of that, let's take a look at... We're using, uh, Vue.js, so with vue-instantsearch. I am just gonna yoink, take that, and here is what we've got going so far.

**Aaron Francis:** It's not my best work. Um, I just have the word search written. It's, it's a start. So if we come over here, that is where I wrote search, and I'm just gonna paste all of that in. We'll take a look at, uh, we'll take a look at this in a second. It's not quite right, but first, we need to come over to app.js. So we need to import this instantsearch plugin and then use that in our Vue.js application.

**Aaron Francis:** So I am going to import instantsearch from Vue 3, and then down here, I have createApp, use. I'm using a, uh, inertia plugin, and I'm gonna just chain this on and say use the instantsearch plugin as well. Now we can come back to search, and we can start to clean this up just a little bit. The index name, remember, we set up in video, we set up an index name as searchableAs, and so we're just gonna say searchableAs videoIndex.

**Aaron Francis:** And then there are a few other things I wanna clean up. This is, I'm gonna use xyz, which is just the default key. I think that is a writable key, so if you were doing this in production, you'd want a read-only key. I'm just gonna do that for now. And we have discussed it's localhost:8108. That is fine. And so we're just cleaning a little bit of this up.

**Aaron Francis:** Remember, we want to query by, um, we wanna query by title and then transcript. And remember, we're not, we're not going through Laravel Scout anymore. This is actually gonna hit Typesense directly, and so if you feel like, "Wait, we're duplicating. We already said that on the back end," we did already say that on the back end, but this is skipping Scout altogether and going straight to the Typesense server, which is a lot faster and a lot more flexible, because Scout just

**Aaron Francis:** kind of searches and then returns the model. But here, we wanna highlight the hits. We wanna show people, um, the keywords that they searched for showing up in the transcript. All right. Let's take a look at how we can build up this UI. So if we scroll back up here, you'll see we've got AisInstantSearch, and this is a component provided by that Algolia instant search package, and because we installed it with the Vue.js plugin, these components are just available to us everywhere.

**Aaron Francis:** So you can see, yeah, the IDE is complaining, but these are available to us in all places, and you can then mix and match the components within. So the search box is what actually provides the place where you type, the search box, hmm, and then the hits is, that's where you see all of the results. So I've deleted everything that's in the hits, because I wanna build it up by ourselves together.

**Aaron Francis:** And so what I'm gonna do is I'm just gonna put a template in there, and then we're going to receive the item, which is the hit, and then I'm just gonna show you that we have access to a bunch of stuff, and then we'll do some cool things. The final thing I need to import is import InstantSearchCSSThemesAlgoliaMin. We'll do that one. There are several themes that you can use that are just kinda straight out of the box.

**Aaron Francis:** We're gonna just start with that one. And so now, if we look, we have, we have a search. Um, it's not great, but we're getting closer. So if we say JSON, we see a bunch of stuff's changed. If we say favorite, whoa, we're really lagging, because look at what we're putting into the browser.

**Aaron Francis:** So not a great start. Well, in fact, a great start. Let's keep going, though. Let us put something here. Let's do, um, item.title. So this is the result out of Typesense. So if you're expecting this to match your eloquent model, it doesn't. This is the two searchable array part. So now coming back here, hey, hey, hey, hey, not bad.

**Aaron Francis:** So much better, in fact. So you see we're, we've got 10 results here, um, and if we were to change to, um, let's see, date. Is, did I do anything about dates? There. There's dates down there. So you can see, yeah, we're doing some searching. Now, it's not quite good enough, in my opinion. I think what I wanna do next is I want to, as the user is typing, I wanna highlight the, the words that they're typing in the results.

**Aaron Francis:** So if they type JSON, not only do they see relevant videos, but they see the word JSON highlighted. That's what we've come to know and love. The first thing, before we muck around up here, we need to come down here and send something additional to the server. So we're gonna say highlightFields, and we're just gonna say title and transcript again. So now we're s- we're telling the Typesense server, "Hey, as you're doing this searching, why don't you go ahead and highlight the fields title and transcript against the user's search intent?" We

**Aaron Francis:** can control the cl- opening and closing tag, but it's fine. We're just gonna keep on going. So if we were to do... What do we need to do now? We're gonna use a different component. Instead of just dumping out item.title, we're gonna use this AisHighlight component. And the attribute is title, and the hit, which is the search hit, is this item that we have, um, v-slotted into scope here.

**Aaron Francis:** So now if we come back here and we refresh, we can say JSON, and it worked. That's it. It totally worked. So you can see that the server is sending us back, and I think if we were to inspect this, I think it's marks maybe. Um, yeah, mark. So you can change that. It doesn't have to be mark. You can actually s- change it to be mark class and then put a Tailwind class in there.

**Aaron Francis:** That's totally fine. This, this works well enough. Um, let's go ahead and get the, let's go ahead and get the transcript in there as well. The first thing I wanna do, um, before we do that, is add a little bit of nice stuff here. So we're gonna say font bold, and then we're gonna come down here and we're gonna take that, and we'll say highlight, uh, attribute, ooh, uh, transcript.

**Aaron Francis:** Transcript, and this is, this is gonna be wrong, by the way, so just hang on a second. So now if we look at that, it's, it's, it's right. Um, you know, if I were to say favorite, you see favorite. But over here, it always... Key- keyboard cl- keys clacking. That is how all the videos start. Um, this is not that great, 'cause favorite shows up way down there.

**Aaron Francis:** So instead of highlight for the long guy, we're gonna use snippet. And now that looks a lot better, except this part, but, uh, we'll fix that in a second. So if we say favorite, or if we say JSON, so now we're seeing just the snippet, just the relevant part that was highlighted. Now, we did notice here in the beginning, they all start with keyboard keys, keyboard keys, typing clicks, and then it's the entire transcript.

**Aaron Francis:** There might be a way around this. I know one way around this. We're gonna use, uh, we're gonna use our old friend CSS. So we're just gonna say line clamp two, and this is good also because a snippet might be super long, and I, I just really wanna show them two lines. So look, we got a nice line clamp. We got a nice dot dot dot. If we say favorite, then we have that.

**Aaron Francis:** If we say JSON, lots of JSONs. If we say index, if we say Boolean. It's kind of awesome. I gotta be honest. It's kind of awesome. Um, this is not what the final UI would look like, um, but I didn't wanna s- you know, spend forever f- messing around with CSS, but this is very close. I just need to adjust the CSS now, and I have full text search across all of my transcripts, all of my videos, and of course, in here, in this template, I could change

**Aaron Francis:** these, um, I could change these to be links to link right out to the video. So hopefully that gives you a sense of the power of Laravel Scout plus TypeSense together. We've barely scratched the surface of TypeSense. You know, when you're, when you're on the back end using Laravel Scout, all you're doing is you're getting back your models. So Laravel Scout goes to TypeSense, it does the search, it pulls back the primary keys, and then it pulls the models out of the database, and then you just get your models.

**Aaron Francis:** Like we looked at on the front end, you have a lot more control when you hit directly, when you hit the TypeSense server directly, 'cause then you can do stuff like highlighting matches and all of that. On both sides, you can have, um, fuzzy matches, you can have stop words, you can have minimum words, you can have all kinds of stuff, and I have barely scratched the surface of it all.

**Aaron Francis:** But hopefully that gives you a sense of how quickly you can get full text search up and running on your site. Thank you to TypeSense for letting me do this. Y'all please go tell them thank you. Thank you for supporting me. I'll leave all the links in the description down below. Please go watch some other video that I've made. They're all good. They're all very good. Until the next time, see ya.

---

## Related on aaronfrancis.com

- [Teaching Databases, Writing PHP, and Independent Work with Aaron Francis](/podcast/teaching-databases-writing-php-and-independent-work-with-aaron-francis-a22e6b07) *(Podcast · 2024-08-27 · shared: laravel, vue, full-text search)*
- [PHP is the future](/videos/php-is-the-future) *(Video · 2023-05-12 · shared: laravel, laravel scout, vue)*
- [This is a season of Type Two fun](/newsletter/this-is-a-season-of-type-two-fun) *(Newsletter · 2025-08-08 · shared: vue, laravel)*
- [The Big Announcement w/ Taylor Otwell](/podcast/the-big-announcement-w-taylor-otwell-2f9739f5) *(Podcast · 2025-04-29 · shared: laravel, vue)*
- [Developing your personal API | Aaron Francis](/podcast/developing-your-personal-api-aaron-francis-63180c6c) *(Podcast · 2025-04-25 · shared: vue, laravel)*

## Relevant Resources from Aaron Francis

- **[Solo](https://soloterm.com)** (overview on site: [/software](/software)): All-in-one agentic development platform and terminal workspace built by Aaron Francis for orchestrating processes and AI coding agents.
- **[Screencasting.com](https://screencasting.com)** (overview on site: [/courses](/courses)): Practical video course on recording high-quality technical screencasts, lighting, audio, studio setup, and publishing faster.

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `typesense` ([T-Z](/llms/keywords/t-z.txt)), `full-text search` ([F-G](/llms/keywords/f-g.txt)), `laravel scout` ([K-L](/llms/keywords/k-l.txt)), `instantsearch` ([H-J](/llms/keywords/h-j.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
