1 00:00:02,090 --> 00:00:06,660 Now I did mention that you can only have one text index per collection and that is true, 2 00:00:06,780 --> 00:00:13,230 if we get the indexes for products, we see we have one text index down there and you see it assume 3 00:00:13,240 --> 00:00:14,840 the default language of English, 4 00:00:14,970 --> 00:00:16,150 we can change that by the way, 5 00:00:16,170 --> 00:00:17,200 I'll come back to that 6 00:00:17,490 --> 00:00:23,550 but for now let's simply try to add another text index because in products if we find one, 7 00:00:23,670 --> 00:00:26,310 the title is of course also text. 8 00:00:26,310 --> 00:00:34,710 So we could say products create index and then say title should also be a text index like this, 9 00:00:34,710 --> 00:00:39,270 now what we get here is essentially an error, index options conflict. 10 00:00:39,270 --> 00:00:45,300 Now this is a bit hard to read but in the end, it's tried to create the index which we already have because 11 00:00:45,300 --> 00:00:47,770 you can only have one text index. 12 00:00:48,390 --> 00:00:54,910 What we can do though is we can merge the text of multiple fields together into one text index, 13 00:00:54,990 --> 00:01:01,320 for this I first of all need to drop my existing text index and now dropping text index is a bit harder, 14 00:01:01,440 --> 00:01:06,330 you can't do title text, 15 00:01:06,530 --> 00:01:11,870 this doesn't work as you can see but what you can do is you can drop it by the name, by the index name 16 00:01:11,990 --> 00:01:17,630 so you can copy that index name you have up there with get indexes and then you can simply drop it by the 17 00:01:17,770 --> 00:01:18,140 name, 18 00:01:18,140 --> 00:01:24,680 we did drop by name earlier in this module too, whoops, needs to be in quotation marks though. So now 19 00:01:24,760 --> 00:01:25,650 this is gone, now 20 00:01:25,650 --> 00:01:32,660 this old text index is gone and if I repeat get indexes, we see we only have the default ID index now and now 21 00:01:32,660 --> 00:01:35,020 we can create a text index again 22 00:01:35,180 --> 00:01:42,440 but now we can actually merge together multiple fields by simply adding them like this, description text. 23 00:01:42,500 --> 00:01:49,070 Now there is still will only be one text index but it will contain the keywords of both the title and 24 00:01:49,070 --> 00:01:50,620 the description field, so if I hit 25 00:01:50,630 --> 00:01:56,790 enter, this works and now I can of course also search for items we have in a title. 26 00:01:56,870 --> 00:02:02,820 So if I find one, you see for example I could search for book because I also have that here, 27 00:02:02,990 --> 00:02:08,690 now we won't see a difference because we had book there before but now we will search for both. And I 28 00:02:08,690 --> 00:02:11,980 can prove this by simply inserting a new product 29 00:02:13,470 --> 00:02:26,410 with a title of a ship and a description of floats perfectly and as you see, we have ship only in the title, 30 00:02:26,470 --> 00:02:27,820 not in the description. 31 00:02:28,150 --> 00:02:37,660 So now with that added, we can of course reach into products and find with the help of 32 00:02:37,660 --> 00:02:44,100 $text for a search term of ship 33 00:02:44,350 --> 00:02:49,810 and again, the casing doesn't matter here. And I do find one document because ship is in the title and 34 00:02:49,810 --> 00:02:51,730 I now have a combined text index.