Northwind Electronics ENTERPRISE
#502

Natural Language Search

Type "red running shoes under 3000 in Chiang Mai" and see it turned into safe, parameterised SQL.

Technique: Rule-based parser: vocabulary from the database, number/compare phrases, sort words
Read the code: src/main/java/com/study/advlab/nlsearch/QueryParser.javasrc/main/java/com/study/advlab/nlsearch/NlSearchService.java
What the parser understands
Price: under / below / up to 3000, over / above 1k, between 1000 and 2000, around 5k
Rating: 4 stars, 4.5+ stars, at least 4 stars
Sort: cheapest, most expensive, best rated, newest, best selling
Stock: in stock, out of stock, low stock
Vocabulary: categories, brands, colours and cities of this company (read from the database)
Synonyms: notebook → laptops, bike → bicycles, couch → sofas ...
Limit: top 5, first 10
Typos: "laptp" → did you mean laptops?