Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
soap_api_search_service.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/web_services/api/soap_api/soap_api.inc';
19 
31 class Soap_Api_Search_Service extends Soap_Api
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
55  public function getFunctionList()
56  {
57  return Array(
58  'BasicSearch' => '1', // Does not accept search term
59  'AdvancedSearch' => '1',
60  'ReIndex' => '1',
61  );
62 
63  }//end getFunctionList()
64 
65 
84  function BasicSearch($request)
85  {
86  $request_info = (Array) $request;
87  $search_asset_types = array_get_index($request_info, 'AssetTypes', '');
88  $search_limit = array_get_index($request_info, 'Limit', '');
89  $search_roots = array_get_index($request_info, 'RootIDs', '');
90  $search_result_format = array_get_index($request_info, 'ResultFormat', '');
91  $search_restrict_statuses = array_get_index($request_info, 'Statuses', '');
92  $exclude_root_nodes = self::getBooleanIndex($request_info, 'ExcludeRootNodes', FALSE);
93 
94  if (!is_array($search_restrict_statuses)) {
95  $search_restrict_statuses = Array ($search_restrict_statuses);
96  }//end if
97 
98  if (isset($search_asset_types->AssetType)) {
99  $search_asset_types = Array ($search_asset_types);
100  }//end if
101 
102  $final_types_array = Array();
103  foreach ($search_asset_types as $type_info)
104  {
105  $final_types_array[strtolower($type_info->AssetType)] = $type_info->Inherit;
106  }//end foreach
107 
108  if (!is_array($search_roots)) {
109  $search_roots = Array ($search_roots);
110  }//end if
111 
112 
113  $installed = $GLOBALS['SQ_SYSTEM']->am->installed('search_manager');
114  if ($installed) {
115  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
116  $search_info = Array(
117  'limit' => $search_limit,
118  'asset_types' => $final_types_array,
119  'statuses' => $search_restrict_statuses,
120  'roots' => $search_roots,
121  );
122 
123  $results = $sm->processBasicSearch($search_info, TRUE);
124  $final_result = Array();
125  if (!empty($results)) {
126  foreach ($results as $assetid => $info) {
127  if ($exclude_root_nodes) {
128  if (in_array($assetid, $search_roots)) {
129  unset($results[$assetid]);
130  continue;
131  }//end if
132  }//end if
133  if (!empty($search_result_format)) {
134  $final_result[] = self::formatAssetResult($assetid, $search_result_format);
135  } else {
136  $final_result[] = $assetid;
137  }
138  }//end foreach
139  }
140 
141  return Array (
142  'BasicSearchResult' => $final_result,
143  );
144 
145  } else {
146  throw new SoapFault('Server', 'Search Manager is not installed');
147  }//end else
148 
149  }//end BasicSearch()
150 
151 
174  function AdvancedSearch($request)
175  {
176  $request_info = (Array) $request;
177  $search_asset_types = array_get_index($request_info, 'AssetTypes', '');
178  $exclude_words = array_get_index($request_info, 'ExcludeWords', '');
179  $search_field_logic = array_get_index($request_info, 'FieldLogic', 'AND');
180  $search_word_logic = array_get_index($request_info, 'WordLogic', 'AND');
181  $search_limit = array_get_index($request_info, 'Limit', '');
182  $search_result_format = array_get_index($request_info, 'ResultFormat', '');
183  $search_roots = array_get_index($request_info, 'RootIDs', '');
184  $root_logic = array_get_index($request_info, 'RootLogic', 'AND');
185  $search_restrict_statuses = array_get_index($request_info, 'Statuses', '');
186  $search_fields = array_get_index($request_info, 'SearchFields', '');
187  $exclude_root_nodes = self::getBooleanIndex($request_info, 'ExcludeRootNodes', FALSE);
188 
189  if (!is_array($search_restrict_statuses)) {
190  $search_restrict_statuses = Array ($search_restrict_statuses);
191  }//end if
192 
193  $installed = $GLOBALS['SQ_SYSTEM']->am->installed('search_manager');
194  if ($installed) {
195  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
196 
197  $field_name_count = 0;
198  $final_search_field = Array();
199  if (!empty($search_fields)) {
200  if (isset($search_fields->SearchTerm)) {
201  $search_fields = Array ($search_fields);
202  }//end if
203  foreach ($search_fields as $field_info) {
204  $new_field_info = Array();
205  $new_field_info['word_logic'] = $field_info->WordLogic;
206  $new_field_info['words'] = $field_info->SearchTerm;
207  $new_field_info['data_sources'] = Array();
208 
209  if (isset($field_info->DataSources->FieldType)) {
210  $field_info->DataSources = Array (
211  $field_info->DataSources,
212  );
213  }//end if
214 
215  foreach ($field_info->DataSources as $data_source) {
216  if ($data_source->FieldType == 'Metadata') {
217  $data_source_new = Array (
218  'type' => 'metadata',
219  'params' => Array (
220  'assetid' => $data_source->MetadataOption->MetadataFieldID,
221  ),
222  );
223  } else if ($data_source->FieldType == 'Attribute') {
224  $data_source_new = Array (
225  'type' => 'asset_attrib',
226  'params' => Array (
227  'asset_type' => $data_source->AttributeOption->AssetType,
228  'attrid' => $data_source->AttributeOption->AttributeID,
229  ),
230  );
231  } else if ($data_source->FieldType == 'Standard') {
232  $data_source_new = Array (
233  'type' => 'standard',
234  'params' => Array (
235  'field' => $data_source->StandardOption->FieldName,
236  ),
237  );
238  } else if ($data_source->FieldType == 'IncludeAll') {
239  $data_source_new = Array (
240  'type' => 'include_all',
241  'params' => Array (),
242  );
243  }
244  $new_field_info['data_sources'][] = $data_source_new;
245 
246  }//end foreach
247 
248  if (!isset($new_field_info['name'])) {
249  $new_field_info['name'] = 'FieldName'.$field_name_count;
250  }//end if
251  $final_search_field['fieldname'.$field_name_count] = $new_field_info;
252  $field_name_count++;
253  }//end foreach
254  }//end if
255 
256  if (isset($search_asset_types->AssetType)) {
257  $search_asset_types = Array ($search_asset_types);
258  }//end if
259  $final_types_array = Array();
260  foreach ($search_asset_types as $type_info)
261  {
262  $final_types_array[strtolower($type_info->AssetType)] = $type_info->Inherit;
263  }//end foreach
264 
265  if (!is_array($search_roots)) {
266  $search_roots = Array ($search_roots);
267  }//end if
268 
269  $search_info = Array(
270  'asset_types' => $final_types_array,
271  'field_logic' => $search_field_logic,
272  'limit' => $search_limit,
273  'statuses' => $search_restrict_statuses,
274  'roots' => $search_roots,
275  'root_logic' => $root_logic,
276  'statuses' => $search_restrict_statuses,
277  'fields' => $final_search_field,
278  );
279  if (!empty($exclude_words)) {
280  if (!is_array($exclude_words)) {
281  $exclude_words = Array ($exclude_words);
282  }//end if
283  $search_info['exclude'] = $exclude_words;
284  }//end if
285 
286  $results = $sm->processSearch($search_info, TRUE);
287  $final_result = Array();
288  if (!empty($results)) {
289  $i = 0;
290  foreach ($results as $index => $asset_info) {
291  if ($exclude_root_nodes) {
292  if (in_array($asset_info['assetid'], $search_roots)) {
293  unset($results[$index]);
294  continue;
295  }//end if
296  }//end if
297 
298  if (!empty($search_result_format)) {
299  $asset_print_formatted = self::formatAssetResult($asset_info['assetid'], $search_result_format);
300  } else {
301  $asset_print_formatted = $asset_info['assetid'];
302  }//end else
303 
304  $final_result[$i]['AssetDisplay'] = $asset_print_formatted;
305  $final_result[$i]['SearchScore'] = $asset_info['search_score'];
306  $final_result[$i]['Source'] = $asset_info['source'];
307  $i++;
308  }//end foreach
309  }
310 
311  return Array (
312  'AdvancedSearchResult' => $final_result,
313  );
314  } else {
315  throw new SoapFault('Server', 'Search Manager is not installed');
316  }//end else
317 
318  }//end AdvancedSearch()
319 
320 
335  function ReIndex($request)
336  {
337  $request_info = (Array) $request;
338  $reindex_assetid = array_get_index($request_info, 'AssetID', '');
339  $reindex_components = array_get_index($request_info, 'IndexComponents', 'all');
340 
341  if (!empty($reindex_assetid)) {
342  $reindex_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($reindex_assetid);
343  if (empty($reindex_assetid)) {
344  throw new SoapFault('Server', 'There Is No Asset In The System With AssetID '.$reindex_assetid);
345  }//end if
346  $installed = $GLOBALS['SQ_SYSTEM']->am->installed('search_manager');
347  if ($installed) {
348  $sm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('search_manager');
349  $sm->reindexAsset($reindex_asset, Array($reindex_components));
350 
351  return Array (
352  'ReIndexResult' => TRUE,
353  );
354  } else {
355  throw new SoapFault('Server', 'Search Manager is not installed');
356  }//end else
357  } else {
358  throw new SoapFault('Server', 'No Asset ID was found to reindex');
359  }//end else
360 
361  }//end ReIndex()
362 
363 
370  private static function formatAssetResult($assetid, $search_result_format)
371  {
372  $formatted_assets = Array();
373  require_once SQ_FUDGE_PATH.'/general/text.inc';
374  $replacement_keywords = Array();
375 
376  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
377  $tmp_format = $search_result_format;
378  $keywords = extract_keywords($search_result_format);
379  foreach ($keywords as $keyword) {
380  $replacement = $asset->getKeywordReplacement($keyword);
381  if ($replacement == '%'.$keyword.'%') {
382  $replacement = '';
383  }//end if
384  $replacement_keywords[$keyword] = $replacement;
385 
386  }//end foreach
387  $asset_result_print = replace_keywords($tmp_format, $replacement_keywords);
388 
389  return $asset_result_print;
390 
391  }//end formatAssetResult()
392 
393 
400  public static function getComplexElements($func_list=Array())
401  {
402  $obj_optional = self::getArgType('AssetObject', 0, 1);
403  $statuses = self::getArgType('AssetStatus', 0, 'unbounded');
404  $search_logic = self::getArgType('SearchLogicValue', 0, 1, TRUE);
405  $search_fields = self::getArgType('SearchField', 0, 'unbounded', TRUE);
406  $asset_types = self::getArgType('AssetTypes', 0, 'unbounded');
407  $root_nodes = self::getArgType('string', 0, 'unbounded', TRUE);
408  $search_result = self::getArgType('string', 0, 'unbounded', TRUE);
409  $advanced_search_result = self::getArgType('AdvancedResult', 0, 'unbounded', TRUE);
410  $exclude_words = self::getArgType('string', 0, 'unbounded', TRUE);
411  $index_component = self::getArgType('IndexComponent', 0, 1);
412 
413  $complex_types = Array (
414  'BasicSearch' => Array (
415  'BasicSearch' => Array (
416  'AssetTypes' => $asset_types,
417  'Limit' => self::$string_non_optional,
418  'Statuses' => $statuses,
419  'RootIDs' => $root_nodes,
420  'ExcludeRootNodes' => self::$boolean_optional,
421  'ResultFormat' => self::$string_optional,
422  ),
423  'BasicSearchResponse' => Array (
424  'BasicSearchResult' => $search_result,
425  ),
426  ),
427  'AdvancedSearch' => Array (
428  'AdvancedSearch' => Array (
429  'AssetTypes' => $asset_types,
430  'ExcludeWords' => $exclude_words,
431  'FieldLogic' => self::$string_optional,
432  'Limit' => self::$string_non_optional,
433  'ResultFormat' => self::$string_optional,
434  'RootIDs' => $root_nodes,
435  'RootLogic' => $search_logic,
436  'ExcludeRootNodes' => self::$boolean_optional,
437  'Statuses' => $statuses,
438  'SearchFields' => $search_fields,
439  ),
440  'AdvancedSearchResponse' => Array (
441  'AdvancedSearchResult' => $advanced_search_result,
442  ),
443  ),
444  'ReIndex' => Array (
445  'ReIndex' => Array (
446  'AssetID' => self::$string_non_optional,
447  'IndexComponents' => $index_component,
448  ),
449  'ReIndexResponse' => Array (
450  'ReIndexResult' => self::$boolean_non_optional,
451  ),
452  ),
453 
454  );
455 
456  $complex_types_available = parent::getComplexElements($complex_types);
457 
458  return $complex_types_available;
459 
460  }//end getComplexElements();
461 
462 
469  public static function getComplexTypes($func_list=Array())
470  {
471  $data_sources = self::getArgType('DataSource', 0, 'unbounded');
472  $metadata_option = self::getArgType('MetadataSearchOption', 0, 'unbounded');
473  $attribute_option = self::getArgType('AttributeSearchOption', 0, 'unbounded');
474  $standard_option = self::getArgType('StandardSearchOption', 0, 'unbounded');
475  $search_field_type = self::getArgType('SearchFieldType', 1, 1);
476  $assetType_optional = self::getArgType('AssetType', 0, 'unbounded');
477  $asset_type_inhr = Array (
478  'AssetType' => $assetType_optional,
479  'Inherit' => self::$string_non_optional,
480  );
481 
482  $complex_types = Array (
483  'AdvancedSearch' => Array (
484  'SearchField' => Array (
485  'SearchTerm' => self::$string_non_optional,
486  'WordLogic' => self::$string_non_optional,
487  'DataSources' => $data_sources,
488  ),
489  'DataSource' => Array (
490  'FieldType' => $search_field_type,
491  'MetadataOption' => $metadata_option,
492  'AttributeOption' => $attribute_option,
493  'StandardOption' => $standard_option,
494  ),
495  'MetadataSearchOption' => Array (
496  'MetadataFieldID' => self::$string_optional,
497  ),
498  'AttributeSearchOption' => Array (
499  'AssetType' => self::$string_optional,
500  'AttributeID' => self::$string_optional,
501  ),
502  'StandardSearchOption' => Array (
503  'FieldName' => self::$string_optional,
504  ),
505 
506  'AdvancedResult' => Array (
507  'AssetDisplay' => self::$string_optional,
508  'SearchScore' => self::$string_optional,
509  'Source' => self::$string_optional,
510  ),
511  'AssetTypes' => $asset_type_inhr,
512  ),
513  'BasicSearch' => Array (
514  'AssetTypes' => $asset_type_inhr,
515  ),
516  );
517 
518  $complex_types_available = parent::getComplexElements($complex_types);
519 
520  return $complex_types_available;
521 
522  }//end getComplexTypes()
523 
524 
531  public static function getSimpleRestrictedTypes($func_list=Array())
532  {
533  $asset_types_info = $GLOBALS['SQ_SYSTEM']->am->getAssetTypes(TRUE, TRUE);
534  $asset_types = Array();
535  foreach ($asset_types_info as $asset_type_info) {
536  $asset_types[] = $asset_type_info['type_code'];
537  }//end foreach
538 
539  $simple_restricted_types = Array (
540  'BasicSearch' => Array (
541  'AssetType' => Array (
542  'restriction_base' => 'string',
543  'enumeration' => $asset_types,
544  ),
545  'AssetStatus' => Array (
546  'restriction_base' => 'string',
547  'enumeration' => Array (
548  '1','2','4','8','16','32','64','128','256',
549  ),
550  ),
551  'SearchLogicValue' => Array (
552  'restriction_base' => 'string',
553  'enumeration' => Array (
554  'AND', 'OR',
555  ),
556  ),
557  ),
558  'ReIndex' => Array (
559  'IndexComponent' => Array (
560  'restriction_base' => 'string',
561  'enumeration' => Array (
562  'asset', 'metadata', 'all'
563  ),
564  ),
565  ),
566  'AdvancedSearch'=> Array (
567  'SearchFieldType' => Array (
568  'restriction_base' => 'string',
569  'enumeration' => Array (
570  'Metadata', 'Attribute', 'Standard', 'IncludeAll',
571  ),
572  ),
573  'AssetType' => Array (
574  'restriction_base' => 'string',
575  'enumeration' => $asset_types,
576  ),
577  ),
578  );
579 
580  $simple_restricted_types_available = parent::processSimpleRestrictedTypes($simple_restricted_types);
581 
582  return $simple_restricted_types_available;
583 
584  }//end getSimpleRestrictedTypes()
585 
586 
587 }//end class
588 ?>