https://github.com/mongodb-developer/whatscooking-multilingual
whatscooking multilingual
https://github.com/mongodb-developer/whatscooking-multilingual
Last synced: 3 months ago
JSON representation
whatscooking multilingual
- Host: GitHub
- URL: https://github.com/mongodb-developer/whatscooking-multilingual
- Owner: mongodb-developer
- License: apache-2.0
- Created: 2024-04-12T07:50:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-14T00:37:59.000Z (about 1 year ago)
- Last Synced: 2024-04-14T04:28:31.489Z (about 1 year ago)
- Language: JavaScript
- Size: 12.7 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
What's Cooking with Atlas Search
A Restaurant Finder Application Demo MongoDB Atlas Search
Hello! 👋 This application allows you to search lightning fast through restaurants in English, Thai, Indonesian and Japanese based on a variety of search parameters and data types:
- restaurant name
- food name
- geolocation coordinates
- cuisine type
- average star rating
- borough

Note1: This dataset is mocked. Please do not use to make actual dining decisions.
Note2: This demo is multiligual version of the What's Cooking repos.
What's Cooking implements many Atlas Search features from autocomplete to custom function scoring. Using the $search operator in a MongoDB aggregation pipeline, we can build fine-grained searches across text, numerics, and geospatial data. By building out What's Cooking, you'll learn all sorts of ways MongoDB allows you to build complex, fine-grained full-text searches on your Atlas data.
**No additional servers or software needed. No need to keep data in sync. Everything is done in MongoDB Atlas.**
- fuzzy matching
- highlighting
- autocomplete
- range queries
- geoqueries
- facets
- relevance-based scoring
- custom function scoring
- synonyms
Check out the demo video to see a demonstration of all the features or visit the link below to play around with the finished application, hosted entirely in MongoDB Atlas:
whatscooking.mongosa.net
This application is hosted entirely by MongoDB Atlas was created using:
- React
- Tailwind CSS
- MongoDB Realm for backend HTTPs endpoints and functions
- A modified sample dataset based on MongoDB's Atlas sample_restaurants dataset
Currently this app is not suitable for mobile, but feel free to send a PR. 😊
Prerequisites
- A MongoDB Atlas account. Get one for free here.
- Node.js version 16 and npm.
- Restaurant sample dataset.
- Synonyms dataset.
- (Recommended) MongoDB Compass - GUI
You can read and download the dataset using the MongoDB Shell, any MongoDB driver, or my favorite MongoDB Compass using the following URI:
mongodb+srv://mongodb:[email protected]/whatscooking
It is also included in this repo's data and indexes directory.
---
To Build This Application...
Prepare Data
- Load data to Atlas cluster:
- database:
whatscooking
- collection:
restaurants_[locale] (e.g. restaurants_en)
,menu_synonyms_[locale](e.g. menu_synonyms_en)
- database:
- Create Search indexes. (Index definitions includes in
indexes
directory.) - default
- autocomplete
- facetIndex
Deploy HTTPS Endpoints at your own AWS environment
Follow the instructions in [Whatscooking BaaS using AWS Lambda Functions](./lambda/README.md)
Testing HTTPS endpoints
You can test each HTTPS endpoints with the following commands
getRestaurantsAutocomplete
command
curl https://7voovjzrkjgdudds53so7rtsae0vjouf.lambda-url.ap-southeast-1.on.aws?restname=burger&locale=en
response
[{"_id":"6095a34a7c34416a90d3212d","name":"Burger King","restaurant_id":"40370238"},{"_id":"6095a34a7c34416a90d3212e","name":"Burger King","restaurant_id":"40370167"},{"_id":"6095a34a7c34416a90d32135","name":"Burger King","restaurant_id":"40370239"},{"_id":"6095a34a7c34416a90d3214b","name":"Burger King","restaurant_id":"40370916"},{"_id":"6095a34a7c34416a90d32164","name":"Burger King","restaurant_id":"40370917"},{"_id":"6095a34a7c34416a90d32166","name":"Burger King","restaurant_id":"40372422"},{"_id":"6095a34a7c34416a90d3216b","name":"Burger King","restaurant_id":"40372618"},{"_id":"6095a34a7c34416a90d321b4","name":"Cozy Soup \u0026 Burger","restaurant_id":"40375839"},{"_id":"6095a34a7c34416a90d3228a","name":"Burger Barn Restaurant","restaurant_id":"40384486"}]
getRestaurants
command
curl \
-H "Content-Type: application/json" \
-d '{"searchTerm": "burger ", "food": "", "operator": "text", "dist": 1, "stars": 1, "cuisine": [], "locale": "en"}' \
https://f6lhyweuc6xvqp5jylghwt7v5u0qzwjz.lambda-url.ap-southeast-1.on.aws
response
{"aggString":"[{\"$search\":{\"text\":{\"query\":\"burger \",\"path\":\"name\",\"fuzzy\":{\"maxEdits\":2}}}},{\"$limit\":21},{\"$project\":{\"name\":1,\"cuisine\":1,\"borough\":1,\"location\":1,\"menu\":1,\"restaurant_id\":1,\"address.street\":1,\"stars\":1,\"review_count\":1,\"PriceRange\":1,\"sponsored\":1,\"score\":{\"$meta\":\"searchScore\"},\"highlights\":{\"$meta\":\"searchHighlights\"}}}]","restaurants":[{"_id":"6095a4864ba3a04a69a79eba","address":{"street":"Pearl Street"},"borough":"Manhattan","cuisine":"Hamburgers","name":"Burger Burger","restaurant_id":"41316784","location":{"type":"Point","coordinates":[-74.0105051,40.7040805]},"stars":3.5,"review_count":159,"menu":["Bacon burger","Santa Fe burger","Ahi Tuna burger","Cheeseburger","Loaded Fries","Mushroom swiss burger","Hickory burger","Classic burger","Fajita burger","Oldtimer with cheese","French Fries","Vegetarian burger"],"PriceRange":2,"score":3.3074374198913574},{"_id":"6095a34a7c34416a90d3212d","address":{"street":"Northern Boulevard"},"borough":"Queens","cuisine":"Hamburgers","name":"Burger King","restaurant_id":"40370238","location":{"type":"Point","coordinates":[-73.89707140000002,40.7543896]},"stars":3,"review_count":38,"menu":["Cheeseburger","Ahi Tuna burger","Chili Cheeseburger","Buffalo Fries","Vegetarian burger","Loaded Fries","French Fries","Classic burger","Triple layer burger","Oldtimer with cheese","Hickory burger","Oldtimer"],"PriceRange":2,"score":2.49027419090271}, ...}
getFacets
command
curl \
-H "Content-Type: application/json" \
-d '{"searchTerm": "burger", "food": "", "operator": "text", "dist": 1, "stars": 1, "cuisine": [], "locale": "en"}' \
https://cwoaaqy74pwe76cajhevu7kaby0eutbe.lambda-url.ap-southeast-1.on.aws
response
{"results":[{"count":{"lowerBound":183},"facet":{"cuisineFacet":{"buckets":[{"_id":"Hamburgers","count":105},{"_id":"American","count":69},{"_id":"Other","count":3},{"_id":"Jewish/Kosher","count":2},{"_id":"Pizza/Italian","count":2},{"_id":"Latin (Cuban, Dominican, Puerto Rican, South \u0026 Central American)","count":1},{"_id":"Mexican","count":1}]},"boroughFacet":{"buckets":[{"_id":"Manhattan","count":69},{"_id":"Brooklyn","count":47},{"_id":"Queens","count":36},{"_id":"Bronx","count":23},{"_id":"Staten Island","count":8}]}}}],"searchMetaStageString":"{\"$searchMeta\":{\"index\":\"facetIndex\",\"facet\":{\"operator\":{\"text\":{\"query\":\"burger\",\"path\":[\"name\",\"cuisine\"]}},\"facets\":{\"cuisineFacet\":{\"type\":\"string\",\"path\":\"cuisine\"},\"boroughFacet\":{\"type\":\"string\",\"path\":\"borough\"}}}}}","searchMetaStage":{"$searchMeta":{"index":"facetIndex","facet":{"operator":{"text":{"query":"burger","path":["name","cuisine"]}},"facets":{"cuisineFacet":{"type":"string","path":"cuisine"},"boroughFacet":{"type":"string","path":"borough"}}}}},"ok":true}
getFoodSynonyms
command
curl https://nqez7rq6c6hkbsydjsf3ktpfru0qkaan.lambda-url.ap-southeast-1.on.aws?locale=en
response
{"foodSynonyms":[{"_id":"6268a01b5899f60be615cb66","input":["noodles"],"mappingType":"explicit","synonyms":["lo mein","chow mein","pasta","udon","ramen","spaghetti","alphabetti","macaroni","pasta"],"date_inserted":"2022-04-27T01:44:59.057Z","editable":false}],"ok":true}
To Run This Application....
1. Clone the repo.
2. Navigate inside `whatscooking-multilingual` directory.
3. Run npm install
.
4. Change HTTPS endpoint urls at src/hooks/useHomeFetch.js
to your own ones.
5. Change HTTPS endpoint urls at src/compenents/SearchBar.js
to your own one.
6. Change MongoDB Connectionstring at src/pages/IndexPage.js
to your own one.
7. Run npm start
.
To Deploy Frontend to AWS S3...
1. Make sure that you're using NodeJS v16 to successfully build the artifacts. If you're using [nvm](https://github.com/nvm-sh/nvm) to manage your Node version, just type `nvm use` to swich to the correct NodeJS version
2. Set AWS temporary credentials in your environment variable and ensure that you're pointing to the correct AWS account
3. Run ./deploy_to_s3.sh
4. The S3 bucket is fronted by CloudFront, so it might take a while for the cache to be refreshed. If you want [invalidate the cache manually](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Invalidation.html), following the instructions when you run the script
---
React Components....
Using AWS Lambda as Your Serverless Backend....
What's Cooking uses AWS Lambda Functions to create 5 APIs to allow you to query for your restaurant data over HTTP:
- `GetRestaurantsEndPoint` called from the `useHomeFetch.js` hook.
- `GetFacetsEndpoint` called from the `useHomeFetch.js` hook.
- `Suggestions_AC_Endpoint` called from the `SearchBar.js` component.
- `getSynonyms` called in the `SynonymsPage.js`.