vendor/elements/omnisearch-bundle/src/Service/AbstractSource.php line 186

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\OmnisearchBundle\Service;
  3. abstract class AbstractSource implements SourceInterface
  4. {
  5.     /**
  6.      * @var Context
  7.      */
  8.     protected $context;
  9.     /**
  10.      * @var string
  11.      */
  12.     protected $query;
  13.     /**
  14.      * @var \ArrayIterator
  15.      */
  16.     protected $resultList;
  17.     /**
  18.      * @var int
  19.      */
  20.     protected $resultCount;
  21.     /**
  22.      * duration time in seconds
  23.      * @var float
  24.      */
  25.     protected $duration 0;
  26.     /**
  27.      * @var int
  28.      */
  29.     protected $limit 10;
  30.     /**
  31.      * @var int
  32.      */
  33.     protected $offset 0;
  34.     /**
  35.      * ASource constructor.
  36.      */
  37.     public function __construct()
  38.     {
  39.         $this->reset();
  40.     }
  41.     /**
  42.      * @param string $query
  43.      *
  44.      * @return $this
  45.      */
  46.     public function setQuery($query)
  47.     {
  48.         $this->query $query;
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return string
  53.      */
  54.     public function getQuery()
  55.     {
  56.         return $this->query;
  57.     }
  58.     /**
  59.      * @return int
  60.      */
  61.     public function getOffset()
  62.     {
  63.         return $this->offset;
  64.     }
  65.     /**
  66.      * @param int $offset
  67.      *
  68.      * @return $this
  69.      */
  70.     public function setOffset($offset)
  71.     {
  72.         $this->offset = (int)$offset;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return int
  77.      */
  78.     public function getLimit()
  79.     {
  80.         return $this->limit;
  81.     }
  82.     /**
  83.      * @param int $limit
  84.      *
  85.      * @return $this
  86.      */
  87.     public function setLimit($limit)
  88.     {
  89.         $this->limit = (int)$limit;
  90.         return $this;
  91.     }
  92.     /**
  93.      * @return Context
  94.      */
  95.     public function getContext()
  96.     {
  97.         return $this->context;
  98.     }
  99.     /**
  100.      * @param Context $context
  101.      *
  102.      * @return $this
  103.      */
  104.     public function setContext(Context $context)
  105.     {
  106.         $this->context $context;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return $this
  111.      */
  112.     public function prepare()
  113.     {
  114.         return $this;
  115.     }
  116.     /**
  117.      * @return $this
  118.      */
  119.     public function process()
  120.     {
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return $this
  125.      */
  126.     public function getResult()
  127.     {
  128.         return $this->prepare()->execute()->process();
  129.     }
  130.     /**
  131.      * @return $this
  132.      */
  133.     public function reset()
  134.     {
  135.         $this->resultList = new \ArrayIterator();
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return bool
  140.      */
  141.     public function isDirectHit(): bool
  142.     {
  143.         $wordCount str_word_count($this->getQuery(), null'äüöÄÜÖ0123456789');
  144.         return $wordCount === && $this->resultCount === 1;
  145.     }
  146.     /**
  147.      * @return float
  148.      */
  149.     public function getDuration()
  150.     {
  151.         return $this->duration;
  152.     }
  153.     /**
  154.      * @inheritdoc
  155.      */
  156.     public function current()
  157.     {
  158.         return $this->resultList->current();
  159.     }
  160.     /**
  161.      * @inheritdoc
  162.      */
  163.     public function next()
  164.     {
  165.         $this->resultList->next();
  166.     }
  167.     /**
  168.      * @inheritdoc
  169.      */
  170.     public function key()
  171.     {
  172.         return $this->resultList->key();
  173.     }
  174.     /**
  175.      * @inheritdoc
  176.      */
  177.     public function valid()
  178.     {
  179.         return $this->resultList->valid();
  180.     }
  181.     /**
  182.      * @inheritdoc
  183.      */
  184.     public function rewind()
  185.     {
  186.         $this->resultList->rewind();
  187.     }
  188.     /**
  189.      * @inheritdoc
  190.      */
  191.     public function count()
  192.     {
  193.         return $this->resultCount;
  194.     }
  195. }