我需要将用户将搜索的产品名称与可用产品进行比较。我有存储在 MySQL 数据库中的产品名称。我正在收集所有名称,并在我的 java 服务启动时将其带到应用程序级别(java)。
现在我的字符串比较场景是这样的:
Available product names:
1) Samsung galaxy s2
2) Samsung galaxy s3
3) Samsung galaxy s4
User input1: galaxy s3 - Then in this scenario my 2nd result should come first as it has 2 matching keywords 'galaxy' and 's3', where other 2 has only 1 matching keyword 'galaxy'.
User input2: s3 - Then here only 2nd result should come, because the other 2 has no matching key word.
User input3: samsung - Then here all three results should come.
谁能建议在Java中哪种算法适合这个?还有一件事,将所有产品名称从 MySQL 带到应用程序级别(java)是正确的方法吗?或者我也可以在 MySQL 级别做吗?(PS:我不想在 MySQL 端使用 like 查询,因为它会很慢)