Adding Search Functionality
In this lesson, we're going to add search functionality
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Fullstack ASP.NET Core and React course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Fullstack ASP.NET Core and React with a single-time purchase.

[00:00 - 00:09] We have added sorting, filtering and pagination feature to our API so far. And one of the most important feature is to search for the courses by their name.
[00:10 - 00:15] We don't have to create anything from scratch. We already have our criteria set up.
[00:16 - 00:20] This is another criteria we need to add. So let's see how to implement this.
[00:21 - 00:30] This will be part of our course parameters. So let me open course parameters since we are going to receive the search string from the client.
[00:31 - 00:44] So we have to add an additional property. So like private and page size, let me change it to page size now that I've seen it.
[00:45 - 00:58] All right. So I will create a private string field which will be called search.
[00:59 - 01:12] We will create a public property now. So this will be a string and we will call it search.
[01:13 - 01:36] We will get the underscore search field and while setting it, we want the value to be converted into lower string so that we are matching things on the similar ground. So what I'll do is search is equal to value dot to lower.
[01:37 - 01:56] We will now go to our courses with category specification. Let me get rid of all this and we will go to the courses with categories specification and add it to our existing criteria.
[01:57 - 02:30] So what we can do is wrap it inside brackets so that it's easier to differentiate and on top of it we can write our search criteria and we will use the and sign here. Since this is a string, we can check string dot is null or empty and pass cos per arms dot search or if it's not empty, we will check if our title contains the search string.
[02:31 - 02:48] So what we can do is x dot title, first of all, we will convert it into a lower string. So we will do not to lower and then we will see if it contains the search string.
[02:49 - 03:01] We also need this when we count for the results. So what we can do is simply copy this and paste it to our courses filters count specification.
[03:02 - 03:15] Let me wrap it inside brackets and on top of it, I can simply paste it. We can now open postman and run the search dev request.
[03:16 - 03:21] It has a search string dev. So let's see, as you can see, we see two results.
[03:22 - 03:30] One contains the word dev and the next one contains a word developer. Not just we get the correct results.
[03:31 - 03:39] We get the correct count as well. Since we passed this criteria to our courses filters count specification.
[03:40 - 03:41] I'll see you in the next one now.