Completed
Push — master ( 321c29...f7acb7 )
by Peter
05:07
created

SearchBoostAnnotation   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 4
dl 0
loc 18
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link http://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Annotations;
14
15
use Maslosoft\Manganel\Meta\ManganelPropertyAnnotation;
16
17
/**
18
 * Use this annotation to increase or decrease importance of field in search
19
 * results. Use above one values to increase importance, and below one to
20
 * decrease.
21
 *
22
 * Default value for query boosting is 1.0, using decimal values is perfectly
23
 * fine. In fact it's required for demoting results.
24
 *
25
 * Increase importance example:
26
 *
27
 * ```php
28
 * @SearchBoost(3)
29
 * ```
30
 *
31
 * Decrease importance example:
32
 *
33
  ```php
34
 * @SearchBoost(0.3)
35
 * ```
36
 *
37
 * @Target('property')
38
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
39
 */
40
class SearchBoostAnnotation extends ManganelPropertyAnnotation
41
{
42
43
	const Ns = __NAMESPACE__;
44
45
	/**
46
	 * Search boosting value for a field
47
	 * @var float
48
	 */
49
	public $value = 1.0;
50
51 1
	public function init()
52
	{
53 1
		assert(is_numeric($this->value), sprintf('@SearchBoost must be numeric value, on property: `%s::$%s`', $this->getMeta()->type()->name, $this->name));
54 1
		$this->getEntity()->searchBoost = (float) $this->value;
55 1
	}
56
57
}
58