{"id":22544397,"url":"https://github.com/hardiksinghbehl/ngram-search-api","last_synced_at":"2025-09-10T10:33:24.592Z","repository":{"id":118947397,"uuid":"419622899","full_name":"hardikSinghBehl/ngram-search-API","owner":"hardikSinghBehl","description":"Search API with spelling correction using ngram-index algorithm: implementation using Java Spring-boot and MySQL ngram full text search index","archived":false,"fork":false,"pushed_at":"2021-10-21T19:51:01.000Z","size":63,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T23:50:56.880Z","etag":null,"topics":["entity-manager","java","ngram","rest-api","search-algorithm","spelling-correction","spring-boot"],"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/hardikSinghBehl.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":"2021-10-21T07:25:34.000Z","updated_at":"2021-12-04T08:39:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d4abc8e-df3e-4db5-a084-bb7c59a51b8c","html_url":"https://github.com/hardikSinghBehl/ngram-search-API","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hardikSinghBehl/ngram-search-API","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardikSinghBehl%2Fngram-search-API","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardikSinghBehl%2Fngram-search-API/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardikSinghBehl%2Fngram-search-API/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardikSinghBehl%2Fngram-search-API/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hardikSinghBehl","download_url":"https://codeload.github.com/hardikSinghBehl/ngram-search-API/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hardikSinghBehl%2Fngram-search-API/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274447535,"owners_count":25287113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["entity-manager","java","ngram","rest-api","search-algorithm","spelling-correction","spring-boot"],"created_at":"2024-12-07T14:07:08.639Z","updated_at":"2025-09-10T10:33:24.576Z","avatar_url":"https://github.com/hardikSinghBehl.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Search API to handle Spelling-Corrections\n### Based on N-gram index algorithm: using [MySQL Ngram Full-Text Parser](https://dev.mysql.com/doc/refman/5.7/en/fulltext-search-ngram.html)\n#### Sample Screen-Recording\nhttps://user-images.githubusercontent.com/69693621/138235026-bfbba08f-a254-4d2c-a81a-d2193bbd84d4.mov\n\n### Tech stack\n* MySQL Ngram Text Parser [(REFERENCE)](https://dev.mysql.com/doc/refman/5.7/en/fulltext-search-ngram.html)\n* EntityManager (JpaRepository can also be used)\n* Flyway\n* Spring-boot to expose REST API\n\n### Important files \n* [SQL migration scripts](https://github.com/hardikSinghBehl/ngram-search-API)\n* [Character.class](https://github.com/hardikSinghBehl/ngram-search-API/blob/main/src/main/java/com/behl/dragonera/entity/Character.java)\n* [CharacterService](https://github.com/hardikSinghBehl/ngram-search-API/blob/main/src/main/java/com/behl/dragonera/service/CharacterService.java)\n\n### Customizing response through score values\nngram index algorithm computes `scores` for every record in accordance with the provided keyword. Below attached is a sample screenshot to show the results (look at the score column)\n\n\u003cimg width=\"655\" alt=\"Screenshot 2021-10-21 at 6 43 37 PM\" src=\"https://user-images.githubusercontent.com/69693621/138284922-2f3eae3d-7337-4149-81d8-6a44732f232a.png\"\u003e\n\nDepending on the usecase in front and functionality to be achieved by a particular application, we can put a condition in our native sql query to return only those records which have a computed score greater than `{value-needed: example 1.5, 0.7 etc}`\n\n### Attaching sample query\n\n```\nSELECT id, name, bio,\n    MATCH(name,bio) \n    AGAINST('James Potter') as score\nFROM characters \nWHERE \n    MATCH(name,bio) \n    AGAINST('James Potter') \u003e1.4 ORDER BY score DESC;\n```\n\u003cimg width=\"575\" alt=\"Screenshot 2021-10-21 at 6 52 41 PM\" src=\"https://user-images.githubusercontent.com/69693621/138286579-dc4384c0-2624-4f2c-8914-8a64f4913759.png\"\u003e\n\nThe count of the data was reduced significantly just by introducing the greater than score condition\nWe can even make the value dynamic depending upon the size of records being matched or have the frontend provide the value using request-parameter to the API \n\n### Local Setup\n* Install Java 17 (recommended to use [SdkMan](https://sdkman.io))\n\n`sdk install java 17-open`\n* Install Maven (recommended to use [SdkMan](https://sdkman.io))\n\n`sdk install maven`\n\n* Clone the repo and configure datasource values in the application.properties file, run the below command\n\n`mvn clean install`\n\n* To start the application\n\n`mvn spring-boot:run \u0026`\n\n* Access the sole API on below path(s)\n  * **to view all character records**\n  \n  ```\n  http://localhost:8080/characters\n  ```\n  * **to view character records based on a searchable keyword** (page starts from index 1 and count is set to 10 of no count param is provided)\n  \n  ```\n  http://localhost:8080/characters?keyword=harry\u0026count=20\u0026page=1\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardiksinghbehl%2Fngram-search-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhardiksinghbehl%2Fngram-search-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhardiksinghbehl%2Fngram-search-api/lists"}