Browse Source

Option array value support added to "yii\sphinx\Query"

tags/2.0.0-beta
Klimov Paul 11 years ago
parent
commit
0275a2244f
  1. 24
      extensions/sphinx/QueryBuilder.php
  2. 4
      tests/unit/extensions/sphinx/QueryTest.php

24
extensions/sphinx/QueryBuilder.php

@ -871,8 +871,28 @@ class QueryBuilder extends Object
if ($value instanceof Expression) {
$actualValue = $value->expression;
} else {
$actualValue = self::PARAM_PREFIX . count($params);
$params[$actualValue] = $value;
if (is_array($value)) {
$actualValueParts = [];
foreach ($value as $key => $valuePart) {
if (is_numeric($key)) {
$actualValuePart = '';
} else {
$actualValuePart = $key . ' = ';
}
if ($valuePart instanceof Expression) {
$actualValuePart .= $valuePart->expression;
} else {
$phName = self::PARAM_PREFIX . count($params);
$params[$phName] = $valuePart;
$actualValuePart .= $phName;
}
$actualValueParts[] = $actualValuePart;
}
$actualValue = '(' . implode(', ', $actualValueParts) . ')';
} else {
$actualValue = self::PARAM_PREFIX . count($params);
$params[$actualValue] = $value;
}
}
$optionLines[] = $name . ' = ' . $actualValue;
}

4
tests/unit/extensions/sphinx/QueryTest.php

@ -131,6 +131,10 @@ class QueryTest extends SphinxTestCase
->where("MATCH('about')")
->options([
'cutoff' => 50,
'field_weights' => [
'title' => 10,
'content' => 3,
],
])
->all($connection);
$this->assertNotEmpty($rows);

Loading…
Cancel
Save