SearchEngine.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Search\Model;
  7. use Magento\Framework\Search\AdapterInterface;
  8. use Magento\Framework\Search\RequestInterface;
  9. use Magento\Framework\Search\SearchEngineInterface;
  10. /**
  11. * Search Engine
  12. */
  13. class SearchEngine implements SearchEngineInterface
  14. {
  15. /**
  16. * @var AdapterInterface
  17. */
  18. private $adapter = null;
  19. /**
  20. * Adapter factory
  21. *
  22. * @var AdapterFactory
  23. */
  24. private $adapterFactory;
  25. /**
  26. * @param AdapterFactory $adapterFactory
  27. */
  28. public function __construct(AdapterFactory $adapterFactory)
  29. {
  30. $this->adapterFactory = $adapterFactory;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function search(RequestInterface $request)
  36. {
  37. return $this->getConnection()->query($request);
  38. }
  39. /**
  40. * Get adapter
  41. *
  42. * @return AdapterInterface
  43. */
  44. protected function getConnection()
  45. {
  46. if ($this->adapter === null) {
  47. $this->adapter = $this->adapterFactory->create();
  48. }
  49. return $this->adapter;
  50. }
  51. }