{"id":22613057,"url":"https://github.com/seahrh/sbac","last_synced_at":"2026-04-28T11:33:53.317Z","repository":{"id":75892031,"uuid":"82021232","full_name":"seahrh/sbac","owner":"seahrh","description":"American Names 1890-2010 (REST API, MongoDB)","archived":false,"fork":false,"pushed_at":"2017-02-16T05:11:11.000Z","size":327,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T23:46:52.310Z","etag":null,"topics":["jersey-jetty-rest","mongodb","morphia"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seahrh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-15T04:46:24.000Z","updated_at":"2017-03-17T06:38:24.000Z","dependencies_parsed_at":"2023-07-12T00:01:10.412Z","dependency_job_id":null,"html_url":"https://github.com/seahrh/sbac","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/seahrh/sbac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seahrh%2Fsbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seahrh%2Fsbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seahrh%2Fsbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seahrh%2Fsbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seahrh","download_url":"https://codeload.github.com/seahrh/sbac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seahrh%2Fsbac/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32379331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T11:25:28.583Z","status":"ssl_error","status_checked_at":"2026-04-28T11:25:05.435Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jersey-jetty-rest","mongodb","morphia"],"created_at":"2024-12-08T17:14:54.936Z","updated_at":"2026-04-28T11:33:53.309Z","avatar_url":"https://github.com/seahrh.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Autocomplete \u0026 Search\n\n![Autocomplete suggestions](https://drive.google.com/uc?id=0B7gBv2Jut0VxdGg3U0ZGcTZTQXc)\n\n![Search results](https://drive.google.com/uc?id=0B7gBv2Jut0VxVElINFNnU29FZms)\n\n## Data\n\nDataset contains 1.7 million name records in the tuple {`name`, `gender`, `count`, `year`}. See how names change in popularity from 1890 to 2010. Source: [US Social Security Administration](https://www.data.gov/) \n\n## Setup\n\ncd to workspace directory and clone this git repo:\n\n\u003e git clone [https://github.com/seahrh/sbac](https://github.com/seahrh/sbac)\n\nInstall frontend dependencies (npm packages)\n\n\u003e npm install\n\n\u003e gulp update\n\nInstall Java dependencies\n\n\u003e mvn clean install\n\n## Database\n\nInstall mongodb \n\n[Download the data dump (206MB)](https://drive.google.com/open?id=0B7gBv2Jut0VxT29uQ0RLb2duNkU)\n\nImport the data dump (assuming data is stored at default path /data/db):\n\n\u003e mongoimport --db sbac --collection Name Name.json --jsonArray\n\nStart the mongo daemon\n\n\u003e mongod --auth\n\nAccess is password protected. Create the following users in mongo shell:\n\nuser: dba, password: dba (all privileges)\n\n\u003e use admin\n\n\u003e db.createUser({user: \"dba\",pwd: \"dba\",roles: [ { role: \"userAdminAnyDatabase\", db: \"admin\" } ]  })\n\nuser: sbacu, password: sbacu (read/write privilege on sbac database)\n\n\u003e use sbac\n\n\u003e db.createUser({user: \"sbacu\",pwd: \"sbacu\",roles: [ { role: \"readWrite\", db: \"sbac\" } ]  })\n\nLogin as sbacu:\n\n\u003e mongo --port 27017 -u \"sbacu\" -p \"sbacu\" --authenticationDatabase \"sbac\"\n\n## Build\n\nFrontend is built with gulp e.g. concatenate and minify js, css.\n\n[`gulpfile.js`](gulpfile.js)\n\n\u003e gulp \n\nBackend java is built with maven.\n\n[`pom.xml`](pom.xml)\n\n\u003e mvn clean package\n\n## Tests\n\nTests are run with maven. Unit tests are run in `test` phase and integration tests are run in `verify` phase of the Maven build lifecycle. Tests are contained in [`src/test/java` package](src/test/java/sbac); `*Test.java` are unit tests and `*IT.java` are integration tests. \n\nThe REST API is tested as an integration test because it requires a live mongodb connection and the API must be deployed on a server.\n\nIf mongod has not already started, \n\n\u003e mongod --auth\n\nTo run the tests,\n\n\u003e mvn verify\n\n## One-Step Deploy\n\nTo do the localhost in one step, run the following batch script (Windows): [`dev.bat`](dev.bat)\n\n\u003e dev\n\nThis will run the gulp build, then maven build including all unit and integration tests.\n\nOpen the following url in browser:\n\nhttp://localhost:8080/\n\n## Configuration\n\nApp configuration (e.g. database credentials) is stored in a configuration file separate from source code. So that if we need to change configuration, we don’t need to recompile.\n\n[`src/main/resources/config/config.properties`](src/main/resources/config/config.properties)\n\n## System Design \u0026 Time Spent\n\nThere are actually two tasks. First, autocomplete the search query. Second, given a search query, use mongodb to perform the full text search.\n\n1. Use MongoDB as the main database (4 hours)\n\n    1. database=`sbac`\n\n    2. collection=`Name` (same as model classname [`Name.java`](src/main/java/sbac/model/Name.java), following DRY principle)\n\n    3. Schema: {name, gender, count, year}\n\n    4. example query: `db.Name.find()`\n\n    5. Used Morphia as ORM and mongodb Java driver\n\n    6. Did not shard as data is not big\n\n2. Use MongoDB textsearch for autocomplete feature (1 hour)\n\n    7. Built a full text search index on two fields {`name`, `year`} as these are the likely fields to search\n\n3. Have a simple AutoComplete Search Bar (3 hours) \n\n    8. Handle the autocomplete on the client side to make the user experience responsive in real time\n\n    9. Used a 3rd party JavaScript widget: bootstrap-3-typeahead. Fetches a json file [`src/main/webapp/names.json`](src/main/webapp/names.json) from the server to populate the widget.\n\n    10. Autocomplete suggestions are limited to names that have at least count=10. This reduces the size of the json file, so that the autocomplete/network latency is more performant.\n\n    11. Reduce load on datastore by linking the autocomplete to json file\n\n        1. Basically the results of the query are cached in the json file. \n\n        2. Nature of data is static (names), so do not need to update the json file frequently\n\n    12. Call search api when button is clicked\n\n4. A simple result page for the search terms (3 hours)\n\n    13. Made with jquery/bootstrap\n\n    14. When data is returned from api, use JavaScript to show search results\n\n5. REST API done with Jersey (8 hours)\n\n    15. see [`sbac.api`](src/main/java/sbac/api) package\n\n    16. No api key as the api is public. Instead log session id. If user misbehaves, rate limit by session id (or ip address).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseahrh%2Fsbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseahrh%2Fsbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseahrh%2Fsbac/lists"}