00:09
we would no longer want them to be listed inside of our search results as an author. So we would want to remove this document from our author's index.
00:17
Again, one of the things that Jumpstart added was an account settings panel, which comprises of a delete account option.
00:23
So to remove this document, we can hook into this delete account operation to do exactly that.
00:29
So if we go into our text editor here, this is within our settings, account controller. And if we scroll on down, we should see this destroy method.
00:37
This deletes the user via a lucid transaction. However, Melee Search has its own database that we're not going to be able to utilize this transaction for.
00:46
So we won't want to actually apply this inside of a transaction, but rather we'll apply it after that transaction has committed and succeeded and the user is no longer a member inside of our database.
00:56
So after this transaction, that is where we will want to await, again, reach through to our search service.
01:03
And then we'll also want to grab the admin privileged instance to alter our author index
01:10
and delete the document for the user that is deleting their account. Now we have, if we scroll up a little bit, the user stored in a variable right here.
01:20
So despite this user being deleted inside of our database right here via this transaction, we're still going to have access to their information via this stored variable after the fact.
01:30
So we're going to be able to reach just directly for that user. And then this delete document just takes the document's primary key, which as we've set
01:37
up, the Melee Search primary keys all match our database's IDs. So we just need to pass in the user's ID there.
01:45
And that will be that document's primary key over in Melee Search as well. That kind of goes back to our command where we talked about setting a specific primary
01:54
key back when we had multiple with our book index. So by just passing the user's ID there, that's going to delete that specific author out
02:02
of our Melee Search database as well whenever they delete their account. And then again, just like with indexing data dynamically, we would just need to do this
02:09
the same anywhere else that we have indexed data along with delete operations inside of our application. So if we had a delete book form, we would just do this exact same thing with our books
02:19
index. So let's give it a test run. So we'll go through our delete account flow here. And as part of a confirmation here, it requires me to enter in the user's email. So I'll do that.
02:29
We'll hit delete account. And there we go. Your account has been deleted and it took me back to the register page.
02:34
If we now go back into our search page and do yet another search for Philip, we get back no results.
02:41
And furthermore, it would probably be great to show that we have no results as well, because right now we're just getting back nothing and it looks like it didn't work.
02:49
But if we were to right click inspect and dig into our console, if I remove the P from there, we can see that it does actually send out the request, but we're just not getting any results back.
02:59
Our response is an empty div. So let's just really quickly fix that. So let's jump back into our autocomplete search fragment.
03:07
And if we scroll up to our ifs here, we have this results hits length. That's omitting the entire ULs if the particular index that we've searched doesn't have any
03:17
results back. So rather than showing a no results per index that we're searching, we could show a single no results by just checking to see if none of our results have any hits.
03:27
So we'll do this outside of our loop because our loop won't render anything if this is the case. And we'll do an at if not results sum, and then we'll have our results and we should
03:37
be able to do result dot hits dot length, just like so. And then we'll end our if and inside of the if we can just add a simple div with a class
03:47
P4 text gray 600 and then in that div out and say no results matched your search or something of the sort.
03:57
Give that a save. You really put whatever you want there and jump back into our browser. Let's try searching for Philip yet again. And there we go.
04:05
Now we get back a simple no results matched your search rather than having it appear like our search just simply didn't work. So great. That is it for this series. That is how you can do multi search using Millie search.
04:14
And then we also briefly discussed how you can do a federated merged result set for that
04:19
search as well within AdonisJS and we used unpoly as well as a little bit of Alpine JS to make this nice and functional using completely server rendered HTML.