1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* class SearchSynonym|Firesphere\SolrSearch\Models\SearchSynonym Object for handling synonyms from the CMS |
4
|
|
|
* |
5
|
|
|
* @package Firesphere\SolrSearch\Models |
6
|
|
|
* @author Simon `Firesphere` Erkelens; Marco `Sheepy` Hermo |
7
|
|
|
* @copyright Copyright (c) 2018 - now() Firesphere & Sheepy |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Firesphere\SolrSearch\Models; |
11
|
|
|
|
12
|
|
|
use SilverStripe\Forms\FieldList; |
13
|
|
|
use SilverStripe\ORM\DataObject; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class \Firesphere\SolrSearch\Models\SearchSynonym |
17
|
|
|
* Manageable synonyms in the CMS |
18
|
|
|
* |
19
|
|
|
* @package Firesphere\SolrSearch\Models |
20
|
|
|
* @property string $Keyword |
21
|
|
|
* @property string $Synonym |
22
|
|
|
* @property int $WorkspaceID |
23
|
|
|
* @method Workspace Workspace() |
24
|
|
|
* @mixin SearchSynonymExtension |
25
|
|
|
*/ |
26
|
|
|
class SearchSynonym extends DataObject |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var string Table name |
30
|
|
|
*/ |
31
|
|
|
private static $table_name = 'Solr_SearchSynonym'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string Singular name |
35
|
|
|
*/ |
36
|
|
|
private static $singular_name = 'Search synonym'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string Plural name |
40
|
|
|
*/ |
41
|
|
|
private static $plural_name = 'Search synonyms'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array DB Fields |
45
|
|
|
*/ |
46
|
|
|
private static $db = [ |
47
|
|
|
'Keyword' => 'Varchar(255)', |
48
|
|
|
'Synonym' => 'Text' |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array Summary fields |
53
|
|
|
*/ |
54
|
|
|
private static $summary_fields = [ |
55
|
|
|
'Keyword', |
56
|
|
|
'Synonym' |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the required CMS Fields for this synonym |
61
|
|
|
* |
62
|
|
|
* @return FieldList |
63
|
|
|
*/ |
64
|
1 |
|
public function getCMSFields() |
65
|
|
|
{ |
66
|
1 |
|
$fields = parent::getCMSFields(); |
67
|
|
|
|
68
|
1 |
|
$fields->dataFieldByName('Synonym')->setDescription( |
69
|
1 |
|
_t( |
70
|
1 |
|
__CLASS__ . '.SYNONYM', |
71
|
1 |
|
'Create synonyms for a given keyword, add as many synonyms comma separated.' |
72
|
|
|
) |
73
|
|
|
); |
74
|
|
|
|
75
|
1 |
|
return $fields; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Combine this synonym in to a string for the Solr synonyms.txt file |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
1 |
|
public function getCombinedSynonym() |
84
|
|
|
{ |
85
|
1 |
|
return sprintf("\n%s,%s", $this->Keyword, $this->Synonym); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|