• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / 247f32f1-ae5b-4443-b1f0-8d637c15f754

pending completion
247f32f1-ae5b-4443-b1f0-8d637c15f754

push

circleci

Aimeos
Include extensions in tests

11599 of 12811 relevant lines covered (90.54%)

47.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.91
/src/MShop/Index/Manager/Text/PgSQL.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2023
6
 * @package MShop
7
 * @subpackage Index
8
 */
9

10

11
namespace Aimeos\MShop\Index\Manager\Text;
12

13

14
/**
15
 * PostgreSQL based index text for searching in product tables.
16
 *
17
 * @package MShop
18
 * @subpackage Index
19
 */
20
class PgSQL
21
        extends \Aimeos\MShop\Index\Manager\Text\Standard
22
{
23
        private array $searchConfig = array(
24
                'index.text:relevance' => array(
25
                        'code' => 'index.text:relevance()',
26
                        'internalcode' => ':site AND mindte."langid" = $1 AND CAST( to_tsvector(mindte."content") @@ to_tsquery( $2 ) AS integer )',
27
                        'label' => 'Product texts, parameter(<language ID>,<search term>)',
28
                        'type' => 'float',
29
                        'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
30
                        'public' => false,
31
                ),
32
                'sort:index.text:relevance' => array(
33
                        'code' => 'sort:index.text:relevance()',
34
                        'internalcode' => 'ts_rank(to_tsvector(mindte."content"), to_tsquery( $2 )) * mpro."boost"',
35
                        'label' => 'Product text sorting, parameter(<language ID>,<search term>)',
36
                        'type' => 'float',
37
                        'internaltype' => \Aimeos\Base\DB\Statement\Base::PARAM_INT,
38
                        'public' => false,
39
                ),
40
        );
41

42

43
        /**
44
         * Initializes the object
45
         *
46
         * @param \Aimeos\MShop\ContextIface $context Context object
47
         */
48
        public function __construct( \Aimeos\MShop\ContextIface $context )
49
        {
50
                parent::__construct( $context );
1✔
51

52
                $level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
1✔
53
                $level = $context->config()->get( 'mshop/index/manager/sitemode', $level );
1✔
54

55
                $name = 'index.text:relevance';
1✔
56
                $expr = $this->siteString( 'mindte."siteid"', $level );
1✔
57
                $this->searchConfig[$name]['internalcode'] = str_replace( ':site', $expr, $this->searchConfig[$name]['internalcode'] );
1✔
58
                $this->searchConfig[$name]['function'] = $this->searchConfig['sort:' . $name]['function'] = $this->getFunctionRelevance();
1✔
59
        }
60

61

62
        /**
63
         * Returns a list of objects describing the available criterias for searching.
64
         *
65
         * @param bool $withsub Return also attributes of sub-managers if true
66
         * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attriubte items
67
         */
68
        public function getSearchAttributes( bool $withsub = true ) : array
69
        {
70
                $list = parent::getSearchAttributes( $withsub );
×
71

72
                foreach( $this->searchConfig as $key => $fields ) {
×
73
                        $list[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $fields );
×
74
                }
75

76
                return $list;
×
77
        }
78

79

80
        /**
81
         * Returns the search function for searching by relevance
82
         *
83
         * @return \Closure Relevance search function
84
         */
85
        protected function getFunctionRelevance()
86
        {
87
                return function( $source, array $params ) {
1✔
88

89
                        if( isset( $params[1] ) )
×
90
                        {
91
                                $strings = [];
×
92
                                $regex = '/(\&|\||\!|\-|\+|\>|\<|\(|\)|\~|\*|\:|\"|\'|\@|\\| )+/';
×
93
                                $search = trim( mb_strtolower( preg_replace( $regex, ' ', $params[1] ) ), "' \t\n\r\0\x0B" );
×
94

95
                                foreach( explode( ' ', $search ) as $part )
×
96
                                {
97
                                        if( strlen( $part ) > 2 ) {
×
98
                                                $strings[] = $part . ':*';
×
99
                                        }
100
                                }
101

102
                                $params[1] = join( ' | ', $strings ) . ' | "' . join( ' <-> ', explode( ' ', $search ) ) . '"';
×
103
                        }
104

105
                        return $params;
×
106
                };
1✔
107
        }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc