Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
searchaction.php
1<?php
2
3namespace Bitrix\Main\Search;
4
8
9abstract class SearchAction extends Engine\Action
10{
11 final public function run($searchQuery, array $options = null, PageNavigation $pageNavigation = null)
12 {
13 $searchQuery = $this->prepareSearchQuery($searchQuery);
14 if (!$searchQuery)
15 {
16 return [
17 'items' => [],
18 'limits' => [],
19 ];
20 }
21
22 $resultItems = $this->provideData($searchQuery, $options, $pageNavigation);
23 if (!is_array($resultItems) && !($resultItems instanceof \Traversable))
24 {
25 throw new ArgumentTypeException('The method ::provideData() has to return iterable data');
26 }
27
28 foreach ($resultItems as $item)
29 {
30 $this->adjustResultItem($item);
31 }
32
33 $limits = $this->provideLimits($searchQuery, $options);
34 if (!is_array($limits) && !($limits instanceof \Traversable))
35 {
36 throw new ArgumentTypeException('The method ::provideLimits() has to return iterable data');
37 }
38
39 return [
40 'items' => $resultItems,
41 'limits' => $limits,
42 ];
43 }
44
45 final protected function adjustResultItem(ResultItem $item)
46 {
47 if (!$item->getModule())
48 {
49 $item->setModule($this->getController()->getModuleId());
50 }
51
52 return $item;
53 }
54
55 protected function prepareSearchQuery($searchQuery)
56 {
57 return trim($searchQuery);
58 }
59
60 protected function provideLimits($searchQuery, array $options = null)
61 {
62 return [];
63 }
64
74 abstract function provideData($searchQuery, array $options = null, PageNavigation $pageNavigation = null);
75}
adjustResultItem(ResultItem $item)
run($searchQuery, array $options=null, PageNavigation $pageNavigation=null)
provideLimits($searchQuery, array $options=null)
provideData($searchQuery, array $options=null, PageNavigation $pageNavigation=null)