【发布时间】:2018-07-25 08:39:05
【问题描述】:
我的搜索功能有一些问题。当一些用户在搜索字段中输入句子时,我想从用户之前输入的句子中的关键字中获取结果。例如我有这样的数据库表:
ID | Keywords | Answer
-----------------------------------------------------------------------------
1 | price, room | The price room is $150 / night
2 | credit card | Yes, you could pay with credit card
3 | location | The Hotel location is in the Los Angeles
4 | how to, way to, book | You could pay with credit card or wire transfer
5 | room, size | The room size is 50sqm
这是用户输入的句子示例:
-
房价是多少?
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
room and price。 - 系统将根据该关键字显示答案是房间价格为 150 美元/晚
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
-
我可以用信用卡付款吗?
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
credit card。 - 系统会根据该关键字显示答案是是的,您可以使用信用卡支付
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
-
房间大小?
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
room and size。 - 系统将根据该关键字显示答案是房间面积为 50 平方米
- 系统将从该句子中找到句子中的关键字,在这种情况下,关键字是
示例 1 和 3 的句子中有room。我还想知道关键字是room price 和room size。
如何从用户已经输入的句子中找到关键字?
如何使用该关键字从数据库中获取答案?
从这些示例中,我想知道如何使用 PHP 和 MySql 做到这一点?或者也许有一些方法可以构建它?请任何知道这样做的人都可以帮助我。之前谢谢。
【问题讨论】:
-
您可以通过 Mysql 使用
"Like"运算符来实现此目的。 -
@Shivrudra 问题是我怎么知道句子使用了一些关键字?比如
What is the room price ?我怎么知道关键字是room and price?
标签: php ajax keyword-search