BxElsSearch.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup ElasticSearch ElasticSearch
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxElsSearch extends BxTemplSearch
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct ($aChoice = '')
  16. {
  17. parent::__construct($aChoice);
  18. $this->aClasses = array();
  19. $this->aChoice = array();
  20. $this->_sModule = 'bx_elasticsearch';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. $aSystems = BxDolContentInfo::getSystems();
  23. foreach($aSystems as $aSystem)
  24. $this->aClasses[$aSystem['name']] = array_merge($aSystem, array(
  25. 'GlobalSearch' => 1
  26. ));
  27. if (is_array($aChoice) && !empty($aChoice))
  28. foreach ($aChoice as $sValue) {
  29. if (!isset($this->aClasses[$sValue]))
  30. continue;
  31. $this->aChoice[$sValue] = $this->aClasses[$sValue];
  32. }
  33. else
  34. $this->aChoice = $this->aClasses;
  35. }
  36. public function response ()
  37. {
  38. $sKeyword = bx_process_input(bx_get('keyword'));
  39. $sUnitTemplate = '';
  40. if($this->_bLiveSearch)
  41. $sUnitTemplate = 'unit_live_search.html';
  42. $sResult = '';
  43. foreach ($this->aChoice as $sKey => $aValue) {
  44. if (!$this->_sMetaType && !$aValue['GlobalSearch'])
  45. continue;
  46. $aResults = $this->_oModule->serviceSearchSimple($sKeyword, $sKey);
  47. if((int)$aResults['total'] == 0 || empty($aResults['hits']))
  48. continue;
  49. $sContent = '';
  50. foreach ($aResults['hits'] as $aResult) {
  51. if (!isset($aResult['_index']))
  52. continue;
  53. list ($sHost, $sObject) = explode('@', $aResult['_index']);
  54. if (empty($sObject))
  55. continue;
  56. if (!($oContentInfo = BxDolContentInfo::getObjectInstance($sObject)))
  57. continue;
  58. $sContent .= $oContentInfo->getContentSearchResultUnit($aResult['_id'], $sUnitTemplate);
  59. }
  60. $sResult .= $this->_oModule->_oTemplate->parseHtmlByName('search_results_block.html', array(
  61. 'id' => $aValue['id'],
  62. 'content' => DesignBoxContent(_t($aValue['title']), $sContent, BX_DB_PADDING_DEF)
  63. ));
  64. }
  65. return $sResult;
  66. }
  67. }
  68. /** @} */