0

I have some punycodes in mongoDB. I need to search them on user requests by their native languages. I can find it if user has entered a complete address, but if he has entered part of the address, then I can not find them. It is not a real code, but I do something like this:

//$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

Any attempt to find $query1 in $punycode returns false. How can I find $query1 in $punycode?

Tirth Patel
  • 5,443
  • 3
  • 27
  • 39
outdead
  • 448
  • 6
  • 15

1 Answers1

0

I added a new field in the database, which is stored url in the native language. And on the server side I selected by which field do search

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