Skip to content

Commit b1615d9

Browse files
committed
Add tests for field level boosting.
1 parent 5b7bffa commit b1615d9

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php namespace functional;
2+
3+
use tests\functional\SearchTest;
4+
use Config;
5+
use Search;
6+
7+
/**
8+
* Class SearchTestWithFieldsBoosting
9+
* @package functional
10+
*/
11+
class SearchTestWithFieldsBoosting extends SearchTest
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' => ['boost' => 0.2],
23+
'description' => ['boost' => 0.8], // Boost 'description' field
24+
],
25+
'optional_attributes' => true
26+
]
27+
]
28+
);
29+
}
30+
31+
public function testSearchWithFieldsBoosting()
32+
{
33+
$query = Search::query('laser pointer', ['name', 'description']);
34+
$founded = $query->get();
35+
36+
$this->assertCount(3, $founded);
37+
$this->assertEquals('noname pointer', $founded[0]->name);
38+
$this->assertEquals('broken pointer', $founded[1]->name);
39+
$this->assertEquals('laser pointer', $founded[2]->name);
40+
}
41+
42+
public function testSearchWithDynamicFieldsBoosting()
43+
{
44+
$query = Search::query('laser pointer', ['boosted_name', 'description']);
45+
$founded = $query->get();
46+
47+
$this->assertCount(3, $founded);
48+
49+
$this->assertEquals('laser pointer', $founded[0]->name);
50+
$this->assertEquals('noname pointer', $founded[1]->name);
51+
$this->assertEquals('broken pointer', $founded[2]->name);
52+
}
53+
}

0 commit comments

Comments
 (0)