SynonymReader.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\App\ResourceConnection;
  8. use Magento\Framework\Data\Collection\AbstractDb as DbCollection;
  9. use Magento\Framework\Model\AbstractModel;
  10. use Magento\Framework\Model\ResourceModel\AbstractResource;
  11. use Magento\Framework\Registry;
  12. /**
  13. * Data model to retrieve synonyms by passed in phrase
  14. *
  15. * @method \Magento\Search\Model\SynonymReader setGroupId(int $group)
  16. * @method int getGroupId()
  17. * @method \Magento\Search\Model\SynonymReader setStoreId(int $storeId)
  18. * @method int getStoreId()
  19. * @method \Magento\Search\Model\SynonymReader setWebsiteId(int $websiteId)
  20. * @method int getWebsiteId()
  21. * @method \Magento\Search\Model\SynonymReader setSynonyms(string $value)
  22. * @method string getSynonyms()
  23. * @api
  24. * @since 100.1.0
  25. */
  26. class SynonymReader extends AbstractModel
  27. {
  28. /**
  29. * Event prefix
  30. *
  31. * @var string
  32. * @since 100.1.0
  33. */
  34. protected $_eventPrefix = 'search_synonyms';
  35. /**
  36. * Event object key name
  37. *
  38. * @var string
  39. * @since 100.1.0
  40. */
  41. protected $_eventObject = 'search_synonyms';
  42. /**
  43. * Construct
  44. *
  45. * @param \Magento\Framework\Model\Context $context
  46. * @param Registry $registry
  47. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  48. * @param DbCollection $resourceCollection
  49. * @param array $data
  50. */
  51. public function __construct(
  52. \Magento\Framework\Model\Context $context,
  53. Registry $registry,
  54. AbstractResource $resource = null,
  55. DbCollection $resourceCollection = null,
  56. array $data = []
  57. ) {
  58. parent::__construct($context, $registry, $resource, $resourceCollection, $data);
  59. }
  60. /**
  61. * Init resource model
  62. *
  63. * @return void
  64. * @since 100.1.0
  65. */
  66. protected function _construct()
  67. {
  68. $this->_init(\Magento\Search\Model\ResourceModel\SynonymReader::class);
  69. }
  70. /**
  71. * Load synonyms by user query phrase in context of current store view
  72. *
  73. * @param string $phrase
  74. * @return $this
  75. * @throws \Magento\Framework\Exception\LocalizedException
  76. * @since 100.1.0
  77. */
  78. public function loadByPhrase($phrase)
  79. {
  80. $this->_getResource()->loadByPhrase($this, strtolower($phrase));
  81. $this->_afterLoad();
  82. $this->setOrigData();
  83. return $this;
  84. }
  85. }