2016-04-07 11 views
0

punycodesにはmongoDBがあります。私は彼らの母国語でユーザーの要求を検索する必要があります。ユーザーが完全な住所を入力した場合はそれを見つけることができますが、住所の一部を入力した場合は見つけられません。これは、実際のコードではありませんが、私はこのような何か:punycodeで検索する

//$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を見つけるしようとします。 $punycode$query1を見つけるにはどうすればよいですか?

答えて

0

データベースに新しいフィールドが追加されました。これは、母国語で保存されたURLです。そして、サーバー側で検索するフィールドを選択しました

$query = 'tä'; 
$punycode = Heplper::punycodeEncode($query); 
$field = Heplper::isPunycode($punycode) ? 'ref_host_native' : 'ref_host'; 
$condition = [$field => ['$regex' => $query],]; 
$result = CwShow::findAggregateSum($condition);