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

aimeos / aimeos-core / b9a6d8a0-e971-4dc5-869c-e0a333e1ba3c

12 May 2024 01:59PM UTC coverage: 91.701%. Remained the same
b9a6d8a0-e971-4dc5-869c-e0a333e1ba3c

push

circleci

aimeos
Added order demo data

11127 of 12134 relevant lines covered (91.7%)

52.66 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-2024
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
                        'public' => false,
30
                ),
31
                'sort:index.text:relevance' => array(
32
                        'code' => 'sort:index.text:relevance()',
33
                        'internalcode' => 'ts_rank(to_tsvector(mindte."content"), to_tsquery( $2 )) * mpro."boost"',
34
                        'label' => 'Product text sorting, parameter(<language ID>,<search term>)',
35
                        'type' => 'float',
36
                        'public' => false,
37
                ),
38
        );
39

40

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

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

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

59

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

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

74
                return $list;
×
75
        }
76

77

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

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

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

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

103
                        return $params;
×
104
                };
1✔
105
        }
106
}
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