Addshore has submitted this change and it was merged.

Change subject: Remove TermIndex::getMatchingIDs and final usages
......................................................................


Remove TermIndex::getMatchingIDs and final usages

Change-Id: I2d756b567faac38ed610f6e114cdb4801fccc32b
---
M lib/includes/TermIndexEntry.php
M lib/includes/store/TermIndex.php
M lib/includes/store/sql/TermSqlIndex.php
M lib/tests/phpunit/store/MockTermIndex.php
M lib/tests/phpunit/store/TermIndexTest.php
M repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
6 files changed, 6 insertions(+), 300 deletions(-)

Approvals:
  Daniel Kinzler: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/TermIndexEntry.php b/lib/includes/TermIndexEntry.php
index 925fa6c..b6e91e1 100644
--- a/lib/includes/TermIndexEntry.php
+++ b/lib/includes/TermIndexEntry.php
@@ -209,8 +209,6 @@
        }
 
        /**
-        * @see TermSqlIndex::getMatchingIDs
-        *
         * @since 0.2
         *
         * @return EntityId|null
diff --git a/lib/includes/store/TermIndex.php b/lib/includes/store/TermIndex.php
index 15616db..bc23748 100644
--- a/lib/includes/store/TermIndex.php
+++ b/lib/includes/store/TermIndex.php
@@ -141,28 +141,6 @@
        );
 
        /**
-        * Returns the IDs that match the provided conditions.
-        *
-        * $terms is an array of Term objects. Terms are joined by OR.
-        * The fields of the terms are joined by AND.
-        *
-        * A single entityType has to be provided.
-        *
-        * @since 0.4
-        *
-        * @param TermIndexEntry[] $terms
-        * @param string|null $entityType
-        * @param array $options
-        *        Accepted options are:
-        *        - caseSensitive: boolean, default true
-        *        - prefixSearch: boolean, default false
-        *        - LIMIT: int, defaults to none
-        *
-        * @return EntityId[]
-        */
-       public function getMatchingIDs( array $terms, $entityType = null, array 
$options = array() );
-
-       /**
         * Clears all terms from the cache.
         *
         * @since 0.2
diff --git a/lib/includes/store/sql/TermSqlIndex.php 
b/lib/includes/store/sql/TermSqlIndex.php
index aee62b0..24e88a8 100644
--- a/lib/includes/store/sql/TermSqlIndex.php
+++ b/lib/includes/store/sql/TermSqlIndex.php
@@ -10,7 +10,6 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
-use Wikibase\DataModel\LegacyIdInterpreter;
 use Wikibase\DataModel\Term\AliasGroup;
 use Wikibase\DataModel\Term\Fingerprint;
 use Wikibase\DataModel\Term\FingerprintProvider;
@@ -590,62 +589,6 @@
                }
 
                return array_values( $returnTermIndexEntries );
-       }
-
-       /**
-        * @see TermIndex::getMatchingIDs
-        *
-        * @since 0.4
-        *
-        * @param TermIndexEntry[] $terms
-        * @param string|null $entityType
-        * @param array $options There is an implicit LIMIT of 5000 items in 
this implementation
-        *
-        * @return EntityId[]
-        */
-       public function getMatchingIDs( array $terms, $entityType = null, array 
$options = array() ) {
-               if ( empty( $terms ) ) {
-                       return array();
-               }
-
-               // this is the maximum limit of search results
-               // TODO this should not be hardcoded
-               $internalLimit = 5000;
-
-               $dbr = $this->getReadDb();
-
-               $conditions = $this->termsToConditions( $dbr, $terms, null, 
$entityType, $options );
-
-               $requestedLimit = isset( $options['LIMIT'] ) ? max( 
(int)$options['LIMIT'], 0 ) : 0;
-
-               $rows = $dbr->select(
-                       $this->tableName,
-                       array_keys( $this->termFieldMap ),
-                       $dbr->makeList( $conditions, LIST_OR ),
-                       __METHOD__,
-                       array( 'LIMIT' => $internalLimit )
-               );
-
-               $hasLimit = $requestedLimit > 0;
-               $rows = $this->getRowsOrderedByWeight( $rows );
-               $entityIds = array();
-               $processedEntityIdSerializations = array();
-               foreach ( $rows as $row ) {
-                       // FIXME: this only works for items and properties
-                       $id = LegacyIdInterpreter::newIdFromTypeAndNumber( 
$row->term_entity_type, $row->term_entity_id );
-
-                       if( !in_array( $id->getSerialization(), 
$processedEntityIdSerializations ) ) {
-                               $entityIds[] = $id;
-                               $processedEntityIdSerializations[] = 
$id->getSerialization();
-                               if( $hasLimit && count( $entityIds ) == 
$requestedLimit ) {
-                                       continue;
-                               }
-                       }
-               }
-
-               $this->releaseConnection( $dbr );
-
-               return $entityIds;
        }
 
        /**
diff --git a/lib/tests/phpunit/store/MockTermIndex.php 
b/lib/tests/phpunit/store/MockTermIndex.php
index 45e294e..e0d8bcf 100644
--- a/lib/tests/phpunit/store/MockTermIndex.php
+++ b/lib/tests/phpunit/store/MockTermIndex.php
@@ -350,35 +350,6 @@
        }
 
        /**
-        * @param TermIndexEntry[] $terms
-        * @param string|null $entityType
-        * @param array $options
-        *
-        * @return EntityId[]
-        */
-       public function getMatchingIDs( array $terms, $entityType = null, array 
$options = array() ) {
-               // We can't pass the limit on to getMatchingTerms, since 
getMatchingTerms may
-               // return multiple terms for an EntityId.
-               $limit = isset( $options['LIMIT'] ) ? $options['LIMIT'] : 0;
-               unset( $options['LIMIT'] );
-
-               $terms = $this->getMatchingTerms( $terms, null, $entityType, 
$options );
-
-               $ids = array();
-               foreach ( $terms as $term ) {
-                       $id = $term->getEntityId();
-                       $key = $id->getSerialization();
-                       $ids[$key] = $id;
-               }
-
-               if ( $limit > 0 ) {
-                       $ids = array_slice( $ids, 0, $limit );
-               }
-
-               return $ids;
-       }
-
-       /**
         * @throws Exception always
         */
        public function clear() {
diff --git a/lib/tests/phpunit/store/TermIndexTest.php 
b/lib/tests/phpunit/store/TermIndexTest.php
index a9113c2..8dc3129 100644
--- a/lib/tests/phpunit/store/TermIndexTest.php
+++ b/lib/tests/phpunit/store/TermIndexTest.php
@@ -26,71 +26,6 @@
         */
        public abstract function getTermIndex();
 
-       public function provideGetMatchingIds() {
-               $id0 = new ItemId( 'Q10' );
-               $item0 = new Item( $id0 );
-
-               $item0->setLabel( 'en', 'foobar' );
-               $item0->setLabel( 'de', 'foobar' );
-               $item0->setLabel( 'nl', 'baz' );
-
-               $item1 = $item0->copy();
-               $id1 = new ItemId( 'Q11' );
-               $item1->setId( $id1 );
-
-               $item1->setLabel( 'nl', 'o_O' );
-               $item1->setLabel( 'pl', '<(^.^)>' );
-               $item1->setDescription( 'en', 'foo bar baz' );
-
-               $id2 = new ItemId( 'Q12' );
-               $item2 = new Item( $id2 );
-               $item2->setLabel( 'pt', 'fooKiTTens rock' );
-               $item2->setDescription( 'pt', 'fooKiTTens are the best' );
-
-               $item3 = $item2->copy();
-               $id3 = new ItemId( 'Q13' );
-               $item3->setId( $id3 );
-
-               return array(
-                       array(
-                               array( $item0, $item1 ),
-                               array( new TermIndexEntry( array( 'termType' => 
TermIndexEntry::TYPE_LABEL, 'termText' => 'foobar' ) ) ),
-                               array( $id1, $id0 ),
-                       ),
-                       array(
-                               array( $item0, $item1 ),
-                               array( new TermIndexEntry( array( 'termType' => 
TermIndexEntry::TYPE_LABEL, 'termText' => 'baz', 'termLanguage' => 'nl' ) ) ),
-                               array( $id0 ),
-                       ),
-                       array(
-                               array( $item0, $item1 ),
-                               array( new TermIndexEntry( array( 'termType' => 
TermIndexEntry::TYPE_LABEL, 'termText' => 'o_O', 'termLanguage' => 'nl' ) ) ),
-                               array( $id1 ),
-                       ),
-                       array(
-                               array( $item0, $item1, $item2 ),
-                               array( new TermIndexEntry( array( 'termType' => 
TermIndexEntry::TYPE_LABEL, 'termText' => 'foo' ) ) ),
-                               array( $id1, $id0, $id2 ),
-                               array( 'caseSensitive' => false, 'prefixSearch' 
=> true )
-                       ),
-               );
-       }
-
-       /**
-        * @dataProvider provideGetMatchingIds
-        */
-       public function testGetMatchingIDs( $items, $terms, $expectedIds, 
$options = array() ) {
-               $lookup = $this->getTermIndex();
-               foreach( $items as $item ) {
-                       $lookup->saveTermsOfEntity( $item );
-               }
-
-               $ids = $lookup->getMatchingIDs( $terms, Item::ENTITY_TYPE, 
$options );
-               $this->assertInternalType( 'array', $ids );
-               $this->assertContainsOnlyInstancesOf( 
'\Wikibase\DataModel\Entity\ItemId', $ids );
-               $this->assertEquals( $expectedIds, $ids );
-       }
-
        public function getTermKey( TermIndexEntry $term ) {
                $key = '';
 
@@ -414,9 +349,12 @@
                $this->assertNotTermExists( $lookup, 'testDeleteTermsForEntity' 
);
 
                $abc = new TermIndexEntry( array( 'termType' => 
TermIndexEntry::TYPE_LABEL, 'termText' => 'abc' ) );
-               $ids = $lookup->getMatchingIDs( array( $abc ), 
Item::ENTITY_TYPE );
-
-               $this->assertNotContains( $id, $ids );
+               $matchedTerms = $lookup->getMatchingTerms( array( $abc ), 
array( TermIndexEntry::TYPE_LABEL ), Item::ENTITY_TYPE );
+               foreach( $matchedTerms as $matchedTerm ) {
+                       if( $matchedTerm->getEntityId() === $id ) {
+                               $this->fail( 'Failed to delete term or entity: 
' . $id->getSerialization() );
+                       }
+               }
        }
 
        public function testSaveTermsOfEntity() {
diff --git a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php 
b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
index cc88c60..9945d6d 100644
--- a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
+++ b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php
@@ -167,128 +167,6 @@
                }
        }
 
-       /**
-        * @dataProvider termProvider
-        */
-       public function testGetMatchingTermsWeights( $languageCode, $termText, 
$searchText, $matches ) {
-               $termIndex = $this->getTermIndex();
-
-               $termIndex->clear();
-
-               $item1 = new Item( new ItemId( 'Q42' ) );
-               $item1->setLabel( $languageCode, $termText );
-               $item1->getSiteLinkList()->addNewSiteLink( 'enwiki', 'A' );
-
-               $termIndex->saveTermsOfEntity( $item1 );
-
-               $item2 = new Item( new ItemId( 'Q23' ) );
-               $item2->setLabel( $languageCode, $termText );
-               $item2->getSiteLinkList()->addNewSiteLink( 'enwiki', 'B' );
-               $item2->getSiteLinkList()->addNewSiteLink( 'dewiki', 'B' );
-               $item2->getSiteLinkList()->addNewSiteLink( 'hrwiki', 'B' );
-               $item2->getSiteLinkList()->addNewSiteLink( 'uzwiki', 'B' );
-
-               $termIndex->saveTermsOfEntity( $item2 );
-
-               // The number of labels counts too
-               $item3 = new Item( new ItemId( 'Q108' ) );
-               $item3->setLabel( $languageCode, $termText );
-               $item3->setLabel( 'qxy', $termText );
-               $item3->setLabel( 'qxz', $termText );
-
-               $termIndex->saveTermsOfEntity( $item3 );
-
-               $term = new TermIndexEntry();
-               $term->setLanguage( $languageCode );
-               $term->setText( $searchText );
-
-               $options = array(
-                       'caseSensitive' => false,
-               );
-
-               $obtainedIDs = $termIndex->getMatchingIDs( array( $term ), 
Item::ENTITY_TYPE, $options );
-
-               $this->assertEquals( $matches ? 3 : 0, count( $obtainedIDs ) );
-
-               if ( $matches ) {
-                       $expectedResult = array( $item2->getId(), 
$item3->getId(), $item1->getId() );
-                       $this->assertArrayEquals( $expectedResult, 
$obtainedIDs, true );
-               }
-       }
-
-       /**
-        * @dataProvider termProvider
-        */
-       public function testGetMatchingIDs_withoutEntityType( $languageCode, 
$termText, $searchText, $matches ) {
-               $termIndex = $this->getTermIndex();
-               $termIndex->clear();
-
-               $item1 = new Item( new ItemId( 'Q42' ) );
-               $item1->setLabel( $languageCode, $termText );
-
-               $termIndex->saveTermsOfEntity( $item1 );
-
-               $term = new TermIndexEntry();
-               $term->setLanguage( $languageCode );
-               $term->setText( $termText );
-
-               $obtainedIDs = $termIndex->getMatchingIDs( array( $term ) );
-
-               $this->assertNotEmpty( $obtainedIDs );
-       }
-
-       /**
-        * @dataProvider termProvider
-        */
-       public function testPrefixSearch( $languageCode, $termText, 
$searchText, $matches ) {
-               $termIndex = $this->getTermIndex();
-               $termIndex->clear();
-
-               $item1 = new Item( new ItemId( 'Q42' ) );
-               $item1->setLabel( $languageCode, $termText );
-
-               $termIndex->saveTermsOfEntity( $item1 );
-
-               $term = new TermIndexEntry();
-               $term->setLanguage( $languageCode );
-               $term->setText( substr( $termText, 0, -1 ) ); //last character 
stripped
-
-               $options = array(
-                       'caseSensitive' => false,
-                       'prefixSearch' => true,
-               );
-
-               $obtainedIDs = $termIndex->getMatchingIDs( array( $term ), 
Item::ENTITY_TYPE, $options );
-
-               $this->assertNotEmpty( $obtainedIDs );
-       }
-
-       /**
-        * @dataProvider termProvider
-        */
-       public function testPrefixSearchQuoting( $languageCode, $termText, 
$searchText, $matches ) {
-               $termIndex = $this->getTermIndex();
-               $termIndex->clear();
-
-               $item1 = new Item( new ItemId( 'Q42' ) );
-               $item1->setLabel( $languageCode, $termText );
-
-               $termIndex->saveTermsOfEntity( $item1 );
-
-               $term = new TermIndexEntry();
-               $term->setLanguage( $languageCode );
-               $term->setText( '%' . $termText ); //must be used as a 
character and no LIKE placeholder
-
-               $options = array(
-                       'caseSensitive' => false,
-                       'prefixSearch' => true,
-               );
-
-               $obtainedIDs = $termIndex->getMatchingIDs( array( $term ), 
Item::ENTITY_TYPE, $options );
-
-               $this->assertEmpty( $obtainedIDs );
-       }
-
        public function provideGetSearchKey() {
                return array(
                        array( // #0

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I2d756b567faac38ed610f6e114cdb4801fccc32b
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to