我有一些punycodes在mongoDB。我需要搜索他们的本地语言的用户请求。如果用户输入了完整的地址,我可以找到它,但是如果他输入了部分地址,我就找不到它们。这不是真正的代码,但我这样做:
//$punycode = 'xn--tst-qla.de'; //täst.de
$query1 = 'tä';
$query2 = 'täst';
$queryPunicode1 = Heplper::punycodeEncode($query1); //xn--t-0fa
$queryPunicode2 = Heplper::punycodeEncode($query2); //xn--tst-qla.de
$condition1 = ['ref_host' => ['$regex' => queryPunicode1],];
$result1 = CwShow::findAggregateSum($condition1); // false
$condition2 = ['ref_host' => ['$regex' => queryPunicode2],];
$result2 = CwShow::findAggregateSum($condition2); // true在$query1中查找$punycode的任何尝试都会返回false。如何在$query1中找到$punycode
发布于 2016-06-02 16:29:06
我在数据库中添加了一个新字段,该字段以本机语言存储url。在服务器端,我选择了哪个字段进行搜索。
$query = 'tä';
$punycode = Heplper::punycodeEncode($query);
$field = Heplper::isPunycode($punycode) ? 'ref_host_native' : 'ref_host';
$condition = [$field => ['$regex' => $query],];
$result = CwShow::findAggregateSum($condition);https://stackoverflow.com/questions/36475995
复制相似问题