WEBVTT

00:03.810 --> 00:04.680
Hey there, everyone.

00:04.750 --> 00:05.250
They share.

00:05.250 --> 00:09.100
And in this video we are going to work through with the really, really long one.

00:09.120 --> 00:12.640
In case you remember, we worked and we actually talked a lot.

00:12.660 --> 00:18.030
Almost half an hour long video about how to deal with the queries which comes into the you are a long

00:18.030 --> 00:20.010
query parameter list in this video.

00:20.010 --> 00:23.880
We're going to go ahead and simplify this because this is a thing you are going to do with a lot of

00:23.880 --> 00:24.240
products.

00:24.240 --> 00:28.370
So it makes sense to actually extract the functionality, put that into utils, do it.

00:28.500 --> 00:29.970
Do you really need to do that?

00:29.970 --> 00:36.000
Probably no, because in a lot of cases, especially when I also do that in the teaching part, I've

00:36.000 --> 00:37.350
seen that in the demo test.

00:37.470 --> 00:38.460
We receive this search.

00:38.460 --> 00:42.180
So anybody who is searching that, we actually handle that into a separate function.

00:42.180 --> 00:46.380
When somebody actually sends out these pagination, we handle that into a separate function.

00:46.380 --> 00:51.330
And when somebody sees us this ratings and all of that greater than equal to, we handle that into a

00:51.330 --> 00:52.350
separate function.

00:52.500 --> 00:57.510
But at the end of the day, the goal is whatever this user dot find is or what are the models to find

00:57.540 --> 01:01.680
is we simply want to go ahead and inject these things inside this.

01:01.680 --> 01:06.720
So inside these parenthesis, a curly brace is going to come in and inside that this is all what we

01:06.720 --> 01:07.020
care.

01:07.020 --> 01:08.280
We have to inject this one.

01:08.280 --> 01:10.650
So this is the whole idea about doing anything.

01:10.650 --> 01:15.210
This is a really powerful method and all the things which you inject inside is kind of a rare clause.

01:15.210 --> 01:19.050
So we are going to define a kind of a var clause into this one.

01:19.050 --> 01:24.540
So let's go ahead and name this one as simply a word clause and let's add a simple utility up here.

01:24.540 --> 01:30.330
So let's go ahead and we're going to call this one as simply let's call this one as we're close, because

01:30.330 --> 01:36.000
that's what precisely it is where clause that J is.

01:36.000 --> 01:42.360
Now what this where clause is going to be, it's going to be a simple file or basically rather a class

01:42.360 --> 01:48.320
which accepts that on which model you want to run this because it's going to be a user defined product,

01:48.330 --> 01:50.940
fine category, fine or something else like that.

01:50.940 --> 01:55.800
So first thing is that going to be parameter, and the second parameter is going to be this one.

01:55.800 --> 01:58.530
The long string that we had is so much of the discussion.

01:58.530 --> 02:02.760
So everything after the question mark is going to come to us and that is pretty easy request query.

02:02.760 --> 02:06.840
So from search equals to all of that, this is going to what is going to come to us.

02:06.840 --> 02:09.420
So let me copy this and first paste this one.

02:09.420 --> 02:13.920
So this is the entirety of the big thing that is going to come in, and the first one is going to be

02:13.920 --> 02:16.380
simple base itself.

02:16.380 --> 02:18.630
So let's go ahead and call this one as base.

02:18.630 --> 02:25.990
So whatever the base is, this is going to be simple product, dot find product.

02:26.040 --> 02:26.310
Fine.

02:26.310 --> 02:28.110
So this is what you are passing me up here.

02:28.110 --> 02:32.520
I'm going to comment this one out and I'm going to call this one as simply the big query.

02:32.520 --> 02:35.970
So let's go ahead and say a big queue.

02:36.210 --> 02:37.740
Yeah, that's kind of a sound name.

02:38.880 --> 02:40.650
Okay, so this is what we are having.

02:40.650 --> 02:42.990
So these are two parameters that I'll be receiving.

02:42.990 --> 02:45.870
Okay, now let's go ahead and create this class based on this one.

02:45.870 --> 02:48.570
So let's go ahead and call this one class.

02:48.570 --> 02:50.430
And this one is going to be simple.

02:50.430 --> 02:55.710
Let's capitalize it because it's a class obviously where clause.

02:57.300 --> 02:58.030
There we go.

02:58.050 --> 03:02.250
So in this very close, we need to create a constructor because we are accepting two parameters.

03:02.250 --> 03:07.050
So let's go ahead and call this as a little bit of a short because this is too big to call this one.

03:07.050 --> 03:09.120
So this is going to be constructor.

03:10.310 --> 03:10.910
Toure.

03:10.940 --> 03:11.690
There we go.

03:11.780 --> 03:17.000
And inside the constructor, we expect that whoever uses this class actually gives me two parameter.

03:17.030 --> 03:21.140
He gives me base and he gives me the big Q.

03:21.230 --> 03:23.780
So we're going to go ahead and say, hey, give me a big cube.

03:24.630 --> 03:32.400
Ah, the big query this big Q again is just a request or query dot request dot query that you are sending

03:32.400 --> 03:33.090
me up here.

03:33.240 --> 03:36.450
Let's go ahead and create available so that we can reference them again.

03:36.450 --> 03:43.290
So we are going to go ahead and call this one as this dot base is going to be base itself and further

03:43.290 --> 03:44.160
down the road.

03:44.160 --> 03:47.340
And again, this shouldn't be there.

03:48.000 --> 03:48.630
There we go.

03:49.710 --> 03:57.900
And further down the road, we're going to call this one as this big cue is also going to be big queue.

03:59.910 --> 04:05.640
And again, this should be a smaller one, this big queue.

04:05.670 --> 04:06.390
There we go.

04:06.750 --> 04:07.060
Okay.

04:07.080 --> 04:08.110
Now this is all done.

04:08.130 --> 04:13.170
Now what we want to do further down the road is this class is going to have a few method which can actually

04:13.170 --> 04:14.820
handle all of our situation.

04:15.390 --> 04:18.550
The three precisely one are the search here first.

04:18.570 --> 04:22.290
The second one is going to be the pagination that is handling for us.

04:22.290 --> 04:25.800
And the third one, which is having this ratings and all of that.

04:25.800 --> 04:31.890
So this category equals whatever that is or if there is something that comes up as ratings equals to

04:31.890 --> 04:32.250
dollars.

04:32.550 --> 04:36.890
So that kind of a situation that we can handle shortly, we can inject more methods as we like.

04:36.900 --> 04:41.340
Now the first one and the easiest one that we are going to handle is going to be the search functionality.

04:41.340 --> 04:45.450
So let's go ahead and say that is going to be a simple search method inside this one.

04:45.450 --> 04:50.730
This goes like this and the search method, all I have to do is inside this big query.

04:50.730 --> 04:56.490
I have to find this keyword search and I have to find whatever the value of this search keyword is.

04:56.490 --> 05:00.990
And that is pretty easy because we have seen that earlier, that whenever you send a request or query,

05:00.990 --> 05:02.190
it comes up as an object.

05:02.190 --> 05:04.650
An object has a lot of key value properties there.

05:04.800 --> 05:10.290
So let's go ahead and see that that I want to store this one as a search word.

05:10.290 --> 05:13.170
So that is going to be the exact word that you are giving it to me.

05:13.380 --> 05:15.570
So this is going to be like this.

05:15.570 --> 05:20.790
So first I will select, I will search that whether you are having any search keyword or not.

05:20.790 --> 05:26.820
So if we are going to say that this dot big query, so inside this big query, whatever the big string

05:26.820 --> 05:30.780
that we have got, does this have a keyword search?

05:31.020 --> 05:34.770
If this is having search keyword, then we are going to do something.

05:34.800 --> 05:38.280
Otherwise we are going to go ahead and do something or nothing basically.

05:38.400 --> 05:43.290
So if this dot search keyword exist, then we want to extract this value.

05:43.500 --> 05:47.280
So where do we want to search here?

05:47.280 --> 05:49.680
Because end of the day you have to write something like this.

05:49.680 --> 05:54.450
So again, remember inside this, if I just go ahead and copy this one here, all you got to do here

05:54.450 --> 05:55.560
is say something like this.

05:55.560 --> 06:00.630
Hey, email is going to be something like this at the rate ae def.

06:00.630 --> 06:02.940
So this is all what we do in the search category.

06:03.150 --> 06:05.430
So let me just go ahead and add this one.

06:05.430 --> 06:09.360
So we are searching for this a string, so let's go ahead and search for this.

06:09.360 --> 06:14.670
So we're going to say that if this search would exist, I would look for in the name, you can look

06:14.670 --> 06:18.150
for it in the name, in the description, whatever suits best to you.

06:18.300 --> 06:23.730
So in the name further down the road, remember, this is exactly what we do, email and then an object

06:23.730 --> 06:24.720
and just like this.

06:24.720 --> 06:27.300
So I would like to inject this search keyword.

06:27.300 --> 06:31.350
Now I can go ahead and simply say that, hey, just add this search keyword and that's it.

06:31.350 --> 06:35.910
That will be absolutely fine to handle this case, but I don't want to do that.

06:35.910 --> 06:40.440
I want to search not for precise word, but actually for a regex based search.

06:40.440 --> 06:44.070
So I'm going to go ahead and remove this one and expand this object.

06:44.070 --> 06:47.340
And I will say, hey, just craft this one as simple regex.

06:47.340 --> 06:49.020
Yes, this is given to us by Mongoose.

06:49.020 --> 06:50.700
In fact, MongoDB also gives that.

06:50.910 --> 06:57.630
So this dot inside this big query, we will be filling it up with the.

06:58.540 --> 06:59.800
Search keyword.

07:00.070 --> 07:02.590
So this will be holding up as a regex.

07:02.590 --> 07:06.860
So instead of passing it as a literal string, we are now passing it as a regex match.

07:06.860 --> 07:10.210
So anything that closely related to that actually comes in.

07:10.450 --> 07:15.040
And we are also going to go ahead and pass on an option in case you want to wish to, you can go ahead

07:15.040 --> 07:15.740
and pass on.

07:15.760 --> 07:17.290
It's not really compulsory.

07:17.320 --> 07:19.180
I'm going to go ahead and pass on an option.

07:19.200 --> 07:22.120
IE there is also an option of g for global search.

07:22.150 --> 07:24.760
The IE is for the case in sensitivity.

07:24.760 --> 07:26.560
So this is all what we got up here.

07:26.740 --> 07:27.280
Okay.

07:27.760 --> 07:35.740
Once this is all done, this entirety of the thing is being done so that I can inject something inside

07:35.740 --> 07:36.440
in here.

07:36.460 --> 07:37.880
This is product fine.

07:37.900 --> 07:39.760
This product dot find is actually the base.

07:39.760 --> 07:41.640
So we need to inject that into a base.

07:41.650 --> 07:43.270
So let's go ahead and work on with that.

07:43.270 --> 07:45.580
So we will say that this dot base.

07:45.850 --> 07:48.580
So inside this base, let's go ahead and modify this one.

07:48.580 --> 07:54.240
So this one is going to be this dot base and a dot find.

07:54.250 --> 07:57.550
Let's add this add a find on to this query itself.

07:58.180 --> 08:03.460
And then further down the road, I will just expand this object and I will say, hey, just add this

08:03.460 --> 08:04.210
search word here.

08:04.210 --> 08:08.860
So whatever existing values were there, we were not changing that, we're just adding it.

08:08.890 --> 08:14.160
Now surely you might say, Hey, this was already product find and you are adding a dot find onto this.

08:14.620 --> 08:17.410
Yes, we are actually doing this a little bit.

08:17.410 --> 08:19.840
This can be actually modified a little bit more onto that.

08:19.840 --> 08:21.190
But this is all what we got.

08:21.340 --> 08:25.410
Now, once this is done, let's go ahead and simply go ahead and say, hey, I want to return this.

08:25.420 --> 08:30.070
Why you are returning the entire this because I also want to return the big query itself.

08:30.070 --> 08:31.270
Maybe somebody needs it.

08:31.270 --> 08:31.720
That's why.

08:31.720 --> 08:32.470
Why to bother it.

08:32.470 --> 08:34.120
Why to return just this dot base.

08:34.120 --> 08:35.560
Let's return then to this.

08:35.560 --> 08:37.630
So it returns the entire context of it.

08:38.020 --> 08:39.400
Okay, so I hope you got that.

08:39.400 --> 08:41.980
How this where clause is working onto the search.

08:42.790 --> 08:44.830
I guess this is all for this video.

08:44.830 --> 08:48.640
Let's go ahead and move on to the next video and talk about how pagination is going to work.

08:48.640 --> 08:50.350
Let's go ahead and catch up with the next one.
