-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSolrSearchField.php
More file actions
169 lines (130 loc) · 3.35 KB
/
SolrSearchField.php
File metadata and controls
169 lines (130 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* @package omeka
* @subpackage solr-search
* @copyright 2012 Rector and Board of Visitors, University of Virginia
* @license http://www.apache.org/licenses/LICENSE-2.0.html
*/
class SolrSearchField extends Omeka_Record_AbstractRecord
{
/**
* The id of the parent element [integer].
*/
public $element_id;
/**
* The name of the element [string].
*/
public $slug;
/**
* The label of the element.
**/
public $label;
/**
* Displayed status [boolean/tinyint].
*/
public $is_indexed;
/**
* Facet status [boolean/tinyint].
*/
public $is_facet;
/**
* Set the parent element reference.
*
* @param Element $element The parent element.
*/
public function __construct($element=null)
{
parent::__construct();
if (!is_null($element)) {
// Element reference.
$this->element_id = $element->id;
// Element identifier.
$this->slug = $element->id;
// Pubilc-facing label.
$this->label = $element->name;
}
}
/**
* The key for the tokenized version of the field in a Solr document.
*
* @return string
*/
public function indexKey()
{
return "{$this->slug}_t";
}
/**
* The key for the untokenized version of the field in a Solr document.
*
* @return string
*/
public function facetKey()
{
return $this->hasElement() ? "{$this->slug}_s" : $this->slug;
}
/**
* Is the field associated with a metadata element?
*
* @return boolean True if an element is defined.
*/
public function hasElement()
{
return !is_null($this->element_id);
}
/**
* Get the parent element.
*
* @return Element|null The element.
*/
public function getElement()
{
if (!$this->hasElement()) return null;
else return $this->getTable('Element')->find($this->element_id);
}
/**
* Get the parent element set.
*
* @return ElementSet|null The element set.
*/
public function getElementSet()
{
if (!$this->hasElement()) return null;
else return $this->getElement()->getElementSet();
}
/**
* Get the name of the parent element set.
*
* @return string The element set name.
*/
public function getElementSetName()
{
if (!$this->hasElement()) return __('Omeka Categories');
else return $this->getElementSet()->name;
}
/**
* Return the original label for the field.
*
* @return string|null
**/
public function getOriginalLabel()
{
switch ($this->slug) {
case 'tag': return __('Tag');
case 'collection': return __('Collection');
case 'itemtype': return __('Item Type');
case 'resulttype': return __('Result Type');
case 'featured': return __('Featured');
default: return $this->getElement()->name;
}
}
/**
* If the label is empty, revert to the original label.
*
* @return string The facet label.
*/
public function beforeSave($args)
{
$label = trim($this->label);
if (empty($label)) $this->label = $this->getOriginalLabel();
}
}