• 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

41.18
/src/MShop/Index/Manager/Text/SQLSrv.php
1
<?php
2

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

10

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

13

14
/**
15
 * SQL Server based index text for searching in product tables.
16
 *
17
 * @package MShop
18
 * @subpackage Index
19
 */
20
class SQLSrv
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
                        'label' => 'Product texts, parameter(<language ID>,<search term>)',
27
                        'type' => 'float',
28
                        'public' => false,
29
                ),
30
                'sort:index.text:relevance' => array(
31
                        'code' => 'sort:index.text:relevance()',
32
                        'label' => 'Product text sorting, parameter(<language ID>,<search term>)',
33
                        'type' => 'float',
34
                        'public' => false,
35
                ),
36
        );
37

38

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

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

51
                if( $context->config()->get( 'mshop/index/manager/text/sqlsrv/fulltext', false ) )
1✔
52
                {
53
                        $search = ':site AND mindte."langid" = $1 AND (
×
54
                                SELECT mindte_ft.RANK
55
                                FROM CONTAINSTABLE("mshop_index_text", "content", $2) AS mindte_ft
56
                                WHERE mindte."id" = mindte_ft."KEY"
57
                        )';
×
58
                        $sort = 'mindte_ft.RANK * mpro."boost"';
×
59

60
                        $func = $this->getFunctionRelevance();
×
61
                }
62
                else
63
                {
64
                        $search = ':site AND mindte."langid" = $1 AND CHARINDEX( $2, content )';
1✔
65
                        $sort = '-CHARINDEX( $2, content ) * mpro."boost"';
1✔
66

67
                        $func = function( $source, array $params ) {
1✔
68

69
                                if( isset( $params[1] ) ) {
×
70
                                        $params[1] = mb_strtolower( $params[1] );
×
71
                                }
72

73
                                return $params;
×
74
                        };
1✔
75
                }
76

77
                $expr = $this->siteString( 'mindte."siteid"', $level );
1✔
78

79
                $this->searchConfig['index.text:relevance']['internalcode'] = str_replace( ':site', $expr, $search );
1✔
80
                $this->searchConfig['sort:index.text:relevance']['internalcode'] = $sort;
1✔
81
                $this->searchConfig['index.text:relevance']['function'] = $func;
1✔
82
        }
83

84

85
        /**
86
         * Returns a list of objects describing the available criterias for searching.
87
         *
88
         * @param bool $withsub Return also attributes of sub-managers if true
89
         * @return \Aimeos\Base\Criteria\Attribute\Iface[] List of search attriubte items
90
         */
91
        public function getSearchAttributes( bool $withsub = true ) : array
92
        {
93
                $list = parent::getSearchAttributes( $withsub );
×
94

95
                foreach( $this->searchConfig as $key => $fields ) {
×
96
                        $list[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $fields );
×
97
                }
98

99
                return $list;
×
100
        }
101

102

103
        /**
104
         * Returns the search function for searching by relevance
105
         *
106
         * @return \Closure Relevance search function
107
         */
108
        protected function getFunctionRelevance()
109
        {
110
                return function( $source, array $params ) {
1✔
111

112
                        if( isset( $params[1] ) )
×
113
                        {
114
                                $strings = [];
×
115
                                $regex = '/(\&|\||\!|\-|\+|\>|\<|\(|\)|\~|\*|\:|\"|\'|\@|\\| )+/';
×
116
                                $search = trim( mb_strtolower( preg_replace( $regex, ' ', $params[1] ) ), "' \t\n\r\0\x0B" );
×
117

118
                                foreach( explode( ' ', $search ) as $part )
×
119
                                {
120
                                        if( strlen( $part ) > 2 ) {
×
121
                                                $strings[] = '"' . $part . '*"';
×
122
                                        }
123
                                }
124

125
                                $params[1] = '\'' . join( ' | ', $strings ) . '\'';
×
126
                        }
127

128
                        return $params;
×
129
                };
1✔
130
        }
131
}
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

© 2026 Coveralls, Inc