Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/202399

Change subject: Introduce TermSqlIndex::supportsSearchKeys
......................................................................

Introduce TermSqlIndex::supportsSearchKeys

This avoids accessing the global option all over the place.

This patch also includes some basic refactoring.

Bug: T94404
Change-Id: I56e76cde4984cc46c868abd4559cff6e7432c0de
---
M lib/includes/store/sql/TermSqlIndex.php
M repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php
M repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
3 files changed, 23 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/99/202399/1

diff --git a/lib/includes/store/sql/TermSqlIndex.php 
b/lib/includes/store/sql/TermSqlIndex.php
index 535d2ec..d9a1286 100644
--- a/lib/includes/store/sql/TermSqlIndex.php
+++ b/lib/includes/store/sql/TermSqlIndex.php
@@ -312,7 +312,7 @@
         *
         * @param Term $term
         *
-        * @return array
+        * @return string[]
         */
        private function getTermFields( Term $term ) {
                $fields = array(
@@ -321,7 +321,7 @@
                        'term_text' => $term->getText(),
                );
 
-               if ( !Settings::get( 'withoutTermSearchKey' ) ) {
+               if ( $this->supportsSearchKeys() ) {
                        $fields['term_search_key'] = $this->getSearchKey( 
$term->getText(), $term->getLanguage() );
                }
 
@@ -561,9 +561,7 @@
 
                $selectionFields = array( 'term_entity_id' );
 
-               // TODO instead of a DB query, get a setting. Should save on a 
few Database round trips.
                $hasWeight = $this->supportsWeight();
-
                if ( $hasWeight ) {
                        $selectionFields[] = 'term_weight';
                }
@@ -686,35 +684,31 @@
                $text = $term->getText();
 
                if ( $text !== null ) {
-                       if ( $options['caseSensitive']
-                               || Settings::get( 'withoutTermSearchKey' ) ) {
-                               //NOTE: whether this match is *actually* case 
sensitive depends on the collation used in the database.
-                               $textField = 'term_text';
-                       }
-                       else {
+                       // NOTE: Whether this match is *actually* case 
sensitive depends on the collation
+                       // used in the database.
+                       $textField = 'term_text';
+
+                       if ( !$options['caseSensitive'] && 
$this->supportsSearchKeys() ) {
                                $textField = 'term_search_key';
                                $text = $this->getSearchKey( $term->getText(), 
$term->getLanguage() );
                        }
 
                        if ( $options['prefixSearch'] ) {
                                $conditions[] = $textField . $db->buildLike( 
$text, $db->anyString() );
-                       }
-                       else {
+                       } else {
                                $conditions[$textField] = $text;
                        }
                }
 
                if ( $term->getType() !== null ) {
                        $conditions['term_type'] = $term->getType();
-               }
-               elseif ( $termType !== null ) {
+               } elseif ( $termType !== null ) {
                        $conditions['term_type'] = $termType;
                }
 
                if ( $term->getEntityType() !== null ) {
                        $conditions['term_entity_type'] = 
$term->getEntityType();
-               }
-               elseif ( $entityType !== null ) {
+               } elseif ( $entityType !== null ) {
                        $conditions['term_entity_type'] = $entityType;
                }
 
@@ -973,7 +967,14 @@
        }
 
        /**
-        * @return mixed
+        * @return bool
+        */
+       public function supportsSearchKeys() {
+               return !Settings::get( 'withoutTermSearchKey' );
+       }
+
+       /**
+        * @return bool
         */
        public function supportsWeight() {
                return !Settings::get( 'withoutTermWeight' );
diff --git a/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php 
b/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php
index 4e9461d..629b437 100644
--- a/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php
+++ b/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php
@@ -44,10 +44,10 @@
         * @param boolean $matches
         */
        public function testRebuildSearchKey( $languageCode, $termText, 
$searchText, $matches ) {
-               $withoutTermSearchKey = WikibaseRepo::getDefaultInstance()->
-                       getSettings()->getSetting( 'withoutTermSearchKey' );
+               /* @var TermSqlIndex $termCache */
+               $termCache = 
WikibaseRepo::getDefaultInstance()->getStore()->getTermIndex();
 
-               if ( $withoutTermSearchKey ) {
+               if ( !$termCache->supportsSearchKeys() ) {
                        $this->markTestSkipped( "can't test search key if 
withoutTermSearchKey option is set." );
                }
 
@@ -56,8 +56,6 @@
                $item->setLabel( $languageCode, $termText );
 
                // save term
-               /* @var TermSqlIndex $termCache */
-               $termCache = 
WikibaseRepo::getDefaultInstance()->getStore()->getTermIndex();
                $termCache->clear();
                $termCache->saveTermsOfEntity( $item );
 
diff --git a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php 
b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
index 847fc24..61b8c10 100644
--- a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
+++ b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
@@ -8,7 +8,6 @@
 use Wikibase\DataModel\Term\AliasGroupList;
 use Wikibase\DataModel\Term\Fingerprint;
 use Wikibase\DataModel\Term\TermList;
-use Wikibase\Repo\WikibaseRepo;
 use Wikibase\StringNormalizer;
 use Wikibase\Term;
 use Wikibase\TermSqlIndex;
@@ -58,14 +57,12 @@
         * @dataProvider termProvider
         */
        public function testGetMatchingTerms2( $languageCode, $termText, 
$searchText, $matches ) {
-               $withoutTermSearchKey = WikibaseRepo::getDefaultInstance()->
-                       getSettings()->getSetting( 'withoutTermSearchKey' );
+               $termIndex = $this->getTermIndex();
 
-               if ( $withoutTermSearchKey ) {
+               if ( !$termIndex->supportsSearchKeys() ) {
                        $this->markTestSkipped( "can't test search key if 
withoutTermSearchKey option is set." );
                }
 
-               $termIndex = $this->getTermIndex();
                $termIndex->clear();
 
                $item = new Item( new ItemId( 'Q42' ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/202399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I56e76cde4984cc46c868abd4559cff6e7432c0de
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to