#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?
Recent searches
- cheapest laptops with 4 stars or more, in stock 4 rows
- gold laptops under 60k in Pattaya 1 rows
- top 5 best selling products 5 rows
- newest products, best rated 24 rows
- low stock items, most expensive first 0 rows
- Orbix laptops between 10k and 37k 2 rows
- newest products, best rated 24 rows
- top 5 best selling products 5 rows