-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConceptSearch.inc.php
executable file
·215 lines (187 loc) · 5.69 KB
/
ConceptSearch.inc.php
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
require_once(MCL_ROOT . 'ConceptSearchGroup.inc.php');
require_once(MCL_ROOT . 'ConceptDatatypeCollection.inc.php');
require_once(MCL_ROOT . 'ConceptClassCollection.inc.php');
/**
* Object to setup a search query.
*/
class ConceptSearch
{
/**
* Full multi-line search query
*/
public $query = '';
/**
* Array of ConceptSearchGroup objects
*/
public $arr_search_group = array();
/**
* Array of ConceptSearchSource objects for all possible sources
*/
private $coll_all_sources = null;
/**
* Array of ConceptSearchSource objects for selected sources
*/
private $coll_selected_sources = null;
/**
* Whether filters apply globally (MCL_FILTER_SCOPE_GLOBAL) or
* only to the text component of queries (MCL_FILTER_SCOPE_TEXT).
* Default is text. For example: if someone queried concept id:10 but also
* selected to only see concepts of type boolean, the global settings
* would filter out id:10 if it was not of type boolean.
*/
public $filter_scope = MCL_FILTER_SCOPE_TEXT;
/**
* Collection of class filters.
*/
public $coll_class_filter = null;
/**
* Collection of datatype filters.
*/
public $coll_datatype_filter = null;
/**
* Whether to include retired concepts in the search results.
* This variable does not apply to concept id or map code search terms.
*/
public $include_retired = false;
/**
* Number of search results to show per page. Set to a false value (0, null, false, etc)
* to retrieve all results.
* NOTE: Something (I think MySQL) freaks out if too many results and just errors out.
*/
public $num_results_per_page = 100;
/**
* Zero-indexed page number to retrieve.
*/
public $current_page_num = 0;
/**
* Whether to return each of items in the concept results.
*/
public $load_descriptions = true;
public $load_concept_attributes = true;
public $load_qa_sets = true;
public $load_mappings = true;
public $load_concept_sets = true;
public $load_concept_list_names = true;
/**
* Constructor
*/
public function __construct($q = null)
{
$this->coll_class_filter = new ConceptClassCollection();
$this->coll_datatype_filter = new ConceptDatatypeCollection();
if ($q) $this->parse($q);
}
/**
* Set the ConceptSearch to request detailed search results.
*/
public function setDetailResults()
{
$this->load_descriptions = true;
$this->load_concept_attributes = true;
$this->load_qa_sets = true;
$this->load_mappings = true;
$this->load_concept_sets = true;
$this->load_concept_list_names = true;
}
/**
* Parses the passed search query into search groups. Groups are denoted
* by the newline character.Returns true if one or more search groups are
* present in the search query; false otherwise.
*/
public function parse($q)
{
$this->query = $this->preprocess($q);
$arr_split = explode("\n", $this->query);
foreach ($arr_split as $str_search_group) {
if (trim($str_search_group)) $this->arr_search_group[] = new ConceptSearchGroup($str_search_group);
}
return (bool)count($arr_split);
}
/**
* Preprocesses the full search query. This is the first step in ConceptSearch::parse().
*/
protected function preprocess($q) {
return strtolower(trim($q));
}
/**
* Return whether any filter settings are contained in this object.
*/
public function hasFilter()
{
// NOTE: SQL needs to be added in order to exclude retired, so invert the include retired variable
if ( !$this->include_retired ||
$this->coll_datatype_filter->Count() ||
$this->coll_class_filter->Count() )
{
return true;
}
return false;
}
/**
* Adds a filter to either the class or datatype filter array.
* @param $filter_criteria ConceptDatatype or ConceptClass
*/
public function addFilter($filter_criteria)
{
if ($filter_criteria instanceof ConceptClass)
{
$this->coll_class_filter ->Add( $filter_criteria->getKey() , $filter_criteria );
}
elseif ($filter_criteria instanceof ConceptDatatype)
{
$this->coll_datatype_filter->Add( $filter_criteria->getKey() , $filter_criteria);
}
else
{
trigger_error('Unrecognized filter criteria: ' . var_export($filter_criteria, true), E_USER_ERROR);
}
}
/**
* Returns the number of ConceptSearchGroup objects in this ConceptSearch object.
*/
public function Count() {
return count($this->arr_search_group);
}
/**
* True if one or more ConceptSearchGroup objects are empty.
*/
public function hasEmptyConceptSearchGroup()
{
foreach (array_keys($this->arr_search_group) as $k) {
if ($this->arr_search_group[$k]->isEmpty()) return true;
}
return false;
}
/**
* Set selected global sources
* @param ConceptSearchSourceCollection $coll_selected_sources
*/
public function setSelectedSources(ConceptSearchSourceCollection $coll_selected_sources) {
$this->coll_selected_sources = $coll_selected_sources;
}
/**
* Set all sources (used to parse inline source statements)
* @param ConceptSearchSourceCollection $coll_selected_sources
*/
public function setAllSources(ConceptSearchSourceCollection $coll_all_sources) {
$this->coll_all_sources = $coll_all_sources;
}
/**
* Get selected global sources
* @return ConceptSearchSourceCollection of selected sources
*/
public function getSelectedSources()
{
return $this->coll_selected_sources;
}
/**
* Get all sources
* @return ConceptSearchSourceCollection of all sources
*/
public function getAllSources()
{
return $this->coll_all_sources;
}
}
?>