MONGODB Search Using Standard Analyzer Algorithm — Autocomplete feature with text and Image recommendation | Node js | Mongodb
In every website, search functionality plays vital and effective role for users. If you are shopping in e-commerce, obviously users prefer search fields and there is a high chance of committing mistake during typing in search field.
Implement the search functionality like Elastic Search using Lucene Standard Algorithm and find the best result which obviously interact your customers/users.
For example: Users likes to buy a “Laptop”, he/she prefers the search functionality for searching the laptops.
Why Lucene Standard (Standard Analyzer) Algorithm is best for search functionality like Elasticsearch?
A) There are high chances of typing mistake (grammatical mistakes) from users during using search functionality like he may search “Labtop” instead of “Laptop”. So, in order to recommend laptop, Mongo provides “fuzzy search mechanism” which gives higher accuracy result and able to find “laptop”.
Note: It converts all terms to lower case and removes punctuation.
B) It provides grammar-based tokenization that recognizes email addresses, acronyms, Chinese-Japanese-Korean characters, alphanumeric, and more.
Let’s jump into the process how we can implement standard Analyzer Method in search functionality.
Suppose, you have “Product Models “
Now, Go to Cloud Mongodb and store product collection like laptop,bag,jacket etc. After you had product collection through post request, you may find search option .
- click on “Search” and you will see “Visual Editor” and “Json Editor” option.
2. In the left side, you will see “Database and collection” section.Now you will see all your collection you had store in your database.So, for now choose “products’ as we are going to apply search functionality for Products only.
3. After choosing “Products”, In the right side , you will see “Index name” field.You may write any name for example: you can write “autocomplete” and below you will find form field , you can paste below code over there,
Lucene Standard Code:
In product controllers,
Result :
Note: Instead of Lucene standard (standard analyzer) algorithm, we can also use “edgegram” method but lucene standard shows more accurate search than edgegram method in my case.
Refer the mongodb link:
EdgeGram method : https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/
Standard Analayzer : https://www.mongodb.com/docs/atlas/atlas-search/analyzers/standard/