Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| GenerisSearch | |
0.00% |
0 / 37 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
| query | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| flush | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| addIndexes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTotalCount | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| index | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| remove | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| supportCustomIndex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2014-2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\search\strategy; |
| 24 | |
| 25 | use oat\generis\model\OntologyRdfs; |
| 26 | use oat\tao\model\search\ResultSet; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\generis\model\OntologyAwareTrait; |
| 29 | use oat\tao\model\search\Search; |
| 30 | use Traversable; |
| 31 | |
| 32 | /** |
| 33 | * Simple Search implementation that ignores the indexes |
| 34 | * and searches over the labels |
| 35 | * |
| 36 | * @author Joel Bout <joel@taotesting.com> |
| 37 | */ |
| 38 | class GenerisSearch extends ConfigurableService implements Search |
| 39 | { |
| 40 | use OntologyAwareTrait; |
| 41 | |
| 42 | /** |
| 43 | * @inheritDoc |
| 44 | */ |
| 45 | public function query($queryString, $type, $start = 0, $count = 10, $order = 'id', $dir = 'DESC') |
| 46 | { |
| 47 | $rootClass = $this->getClass($type); |
| 48 | $results = $rootClass->searchInstances( |
| 49 | [ |
| 50 | OntologyRdfs::RDFS_LABEL => $queryString |
| 51 | ], |
| 52 | [ |
| 53 | 'recursive' => true, |
| 54 | 'like' => true, |
| 55 | 'offset' => $start, |
| 56 | 'limit' => $count, |
| 57 | ] |
| 58 | ); |
| 59 | |
| 60 | $ids = []; |
| 61 | |
| 62 | foreach ($results as $resource) { |
| 63 | $ids[] = [ |
| 64 | 'id' => $resource->getUri(), |
| 65 | 'label' => $resource->getLabel() |
| 66 | ]; |
| 67 | } |
| 68 | |
| 69 | return new ResultSet($ids, $this->getTotalCount($queryString, $rootClass)); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @inheritDoc |
| 74 | */ |
| 75 | public function flush() |
| 76 | { |
| 77 | // no flushing required |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @inheritDoc |
| 82 | */ |
| 83 | public function addIndexes(Traversable $IndexIterator) |
| 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @inheritDoc |
| 90 | */ |
| 91 | private function getTotalCount($queryString, $rootClass = null) |
| 92 | { |
| 93 | return $rootClass->countInstances( |
| 94 | [ |
| 95 | OntologyRdfs::RDFS_LABEL => $queryString |
| 96 | ], |
| 97 | [ |
| 98 | 'recursive' => true, |
| 99 | 'like' => true, |
| 100 | ] |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @inheritDoc |
| 106 | */ |
| 107 | public function index($document = []) |
| 108 | { |
| 109 | $i = 0; |
| 110 | |
| 111 | foreach ($document as $resource) { |
| 112 | $i++; |
| 113 | } |
| 114 | |
| 115 | return $i; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @inheritDoc |
| 120 | */ |
| 121 | public function remove($resourceId) |
| 122 | { |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @inheritDoc |
| 128 | */ |
| 129 | public function supportCustomIndex() |
| 130 | { |
| 131 | return false; |
| 132 | } |
| 133 | } |