Now I did mention that you can only have one text index per collection and that is true,
if we get the indexes for products, we see we have one text index down there and you see it assume
the default language of English,
we can change that by the way,
I'll come back to that
but for now let's simply try to add another text index because in products if we find one,
the title is of course also text.
So we could say products create index and then say title should also be a text index like this,
now what we get here is essentially an error, index options conflict.
Now this is a bit hard to read but in the end, it's tried to create the index which we already have because
you can only have one text index.
What we can do though is we can merge the text of multiple fields together into one text index,
for this I first of all need to drop my existing text index and now dropping text index is a bit harder,
you can't do title text,
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
so you can copy that index name you have up there with get indexes and then you can simply drop it by the
name,
we did drop by name earlier in this module too, whoops, needs to be in quotation marks though. So now
this is gone, now
this old text index is gone and if I repeat get indexes, we see we only have the default ID index now and now
we can create a text index again
but now we can actually merge together multiple fields by simply adding them like this, description text.
Now there is still will only be one text index but it will contain the keywords of both the title and
the description field, so if I hit
enter, this works and now I can of course also search for items we have in a title.
So if I find one, you see for example I could search for book because I also have that here,
now we won't see a difference because we had book there before but now we will search for both. And I
can prove this by simply inserting a new product
with a title of a ship and a description of floats perfectly and as you see, we have ship only in the title,
not in the description.
So now with that added, we can of course reach into products and find with the help of
$text for a search term of ship
and again, the casing doesn't matter here. And I do find one document because ship is in the title and
I now have a combined text index.