00:04
What we would want is for that author and their book to be added into our documents for both of
00:10
those indexes. Right now if that were to happen, they would only ever be indexed if we reran our index command manually inside of our terminal. We could of course also schedule that, but what
00:20
would be great is if that just dynamically happened whenever a user registered and added their book into our application. That itself is relatively easy to do as well. So for the sake of
00:30
this application, let's just whenever a brand new user registers, add them into the index because it would be the same behavior regardless of which index we're adding them to, whether that's the
00:38
book genre or author. So we'll go into our authentication where we have our register controller
00:43
and we'll mutate the store method here a little bit so that it also adds this brand new user into
00:49
our author's index. And just for the sake of simplicity, we're going to bypass the fact that this brand new user won't have a book. So we'll just add them into our author's index regardless
00:58
anyway. So what we can do is await and we'll import our search service yet again and this is going to
01:04
be an administrative task as we are altering our index with a brand new document and we want to
01:10
reach specifically through to our author's index. Wait for that to finish and we'll go ahead and
01:17
through to our author's index. Within that index, we want to add a new document and pass it in an
01:23
array and rather than performing a brand new select with just the user's ID and full name,
01:28
we can pass in a simple object of our own with the ID of the user. So user.id and the full
01:35
name of that user. So user.fullname. Give that a save and now whenever a user registers inside
01:40
of our application, they'll be automatically added as an author inside of our author's index with this document consisting of the ID and full name of that user. So jumping back into our
01:50
browser, let's go ahead and register a brand new user. So I'm just going to give them a name of
01:54
Philip J. Fry and a simple email of test.test.com and then something as the password. Hit enter to
02:02
register and perfect. Philip J. Fry has now been added as a brand new user inside of our database but they should have also been indexed inside of our author's index as well with a brand new
02:12
document. So within our URL bar, if we go back to our search page and now search Philip, there is
02:19
our brand new author Philip J. Fry. Great. So that just happened dynamically as the user signed up inside of our application. No manual intervention on our part to make that happen. We would just do
02:29
that exact same thing inside of this application if we also had a form to add a book or a genre as well to add those dynamically as they were created.