From the course: Vector Databases in Practice: Deep Dive
Solution: App enhancements
- [Instructor] Okay, here's my solutions to challenge exercise. You are asked to make improvements through our app by adding a keyword search option, add a year based filter, and to show review data for each movie. The UI element for selecting keyword search had been added already. So what we needed to do was to construct the keyword or BM25 search query. The way I did it was to add an if else clause just here if the input was keyword, and then construct a search just like this. Remember that BM25 is the search ranking algorithm and the method name for keyword searches. And once you've called that function, you can pass the same parameters as you've done above. So that's our keyword search implemented. And now let's get onto the filter. Again, the UI has been done already. We can capture the user's inputs as integers. Now just be mindful that the inputs here must be integers because we've defined the year property to be an integer at the database level. Once we've done that, what we need to do is to add those conditions to our filter. Now this is an additional requirement, so the right operator would be an and. So we can add that with an ampersand and construct the filter. This filter of course will make sure that the year is greater than or equal to the minimum specified year. And this will do a similar thing, but for the maximum year and make sure the data that's returned has the year that's less than or equal to the maximum year specified. So lastly, let's fetch and display the review data. For this, we need to remember how the movie collection is linked to the review collection. If we now inspect the collection definition for the movies, you see that the collection has a hasReview property that links to the review collection. This is what we're going to use to fetch or query the referenced collection. The general pattern here is the same as a hasSynopsis reference. We use the query reference class and then link on the hasReview reference property instead of the hasSynopsis property, which we use above. And then we get the body property back as that is the property in the review collection. Now we need to remember to do something with the data that is returned as this is an additional data that's returned that wasn't displayed before. In my case, I added a section at the bottom of the tab just here. So I add a subheader called Reviews and just iterate it through each review like this, display a little bolded heading for each review. This is just markdown syntax. And then show the review body for each review. If we save that and run the app again, we now see that the app has been updated. We have an additional keyword option here in the radio buttons, and we have the year filters. Let's pick a keyword search for the word time, and then perform our search. And if we change the year filter, let's say to between 1980 and 2000. You see that there's just the one hit that meet these criteria. And if we inspect the results in the movie details tab, we see that the year is indeed within our criteria. And what else do we have here? We actually have the reviews displayed as well. I hope you found this interesting. There's obviously a lot that you can do with apps like this that'll be really valuable and interesting to the end user. So I would encourage you to continue to tinker with apps like this or even build your own powered by your own data sets.