Skip to content

Commit 6594388

Browse files
committed
Add tests for model boosting, fixes in other tests.
1 parent 5e3b58d commit 6594388

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

tests/functional/FieldsBoostingTest.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,30 @@ protected function configure()
3333
public function testSearchWithFieldsBoosting()
3434
{
3535
$query = Search::query('laser pointer', ['name', 'description']);
36-
$founded = $query->get();
36+
$names = $query->get()->lists('name');
3737

38-
$this->assertCount(3, $founded);
39-
$this->assertEquals('noname pointer', $founded[0]->name);
40-
$this->assertEquals('broken pointer', $founded[1]->name);
41-
$this->assertEquals('laser pointer', $founded[2]->name);
38+
$this->assertCount(3, $names);
39+
40+
$this->assertEquals([
41+
'noname pointer',
42+
'broken pointer',
43+
'laser pointer'
44+
45+
], $names);
4246
}
4347

4448
public function testSearchWithDynamicFieldsBoosting()
4549
{
4650
$query = Search::query('laser pointer', ['boosted_name', 'description']);
47-
$founded = $query->get();
51+
$names = $query->get()->lists('name');
52+
53+
$this->assertCount(3, $names);
4854

49-
$this->assertCount(3, $founded);
55+
$this->assertEquals([
56+
'laser pointer',
57+
'noname pointer',
58+
'broken pointer'
5059

51-
$this->assertEquals('laser pointer', $founded[0]->name);
52-
$this->assertEquals('noname pointer', $founded[1]->name);
53-
$this->assertEquals('broken pointer', $founded[2]->name);
60+
], $names);
5461
}
5562
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace functional;
2+
3+
use tests\functional\BaseTestCase;
4+
use Config;
5+
use Search;
6+
7+
/**
8+
* Class FieldsBoostingTest
9+
* @package functional
10+
*/
11+
class ModelBoostingTest extends BaseTestCase
12+
{
13+
protected function configure()
14+
{
15+
parent::configure();
16+
17+
Config::set(
18+
'laravel-lucene-search::index.models',
19+
[
20+
'tests\models\Product' => [
21+
'fields' => [
22+
'name',
23+
'description',
24+
],
25+
'optional_attributes' => [
26+
'accessor' => 'custom_optional_attributes'
27+
],
28+
'boost' => [
29+
'accessor' => 'custom_boost'
30+
],
31+
]
32+
]
33+
);
34+
}
35+
36+
public function testSearchWithModelBoosting()
37+
{
38+
$query = Search::query('lamp', ['name', 'description']);
39+
$names = $query->get()->lists('name');
40+
41+
$this->assertCount(3, $names);
42+
43+
$this->assertEquals([
44+
'led lamp',
45+
'dim lamp',
46+
'bright lamp',
47+
], $names);
48+
}
49+
50+
}

tests/unit/Model/ConfigTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testFields()
9595
$this->assertEquals(['name' => ['boost' => 1], 'description' => ['boost' => 1]], $fields);
9696

9797
$fields = $this->config->fields($this->dummyRepoMock);
98-
$this->assertEquals(['first_field' => ['boost' => 1], 'second_field' => ['boost' => 1]], $fields);
98+
$this->assertEquals(['first_field' => ['boost' => 0.1], 'second_field' => ['boost' => 0.2]], $fields);
9999
}
100100

101101
public function testOptionalAttributes()
@@ -222,8 +222,8 @@ private function getValidConfigs()
222222
'tests\models\DummyModel' => [
223223
'primary_key' => 'pk',
224224
'fields' => [
225-
'first_field',
226-
'second_field',
225+
'first_field' => ['boost' => 0.1],
226+
'second_field' => ['boost' => 0.2],
227227
],
228228
'optional_attributes' => [
229229
'accessor' => 'custom_optional_attributes'

0 commit comments

Comments
 (0)