public function testCanConstructValueMatchConditionBuilderOnMySQLConnectionType()
 {
     $connection = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock();
     $connection->expects($this->once())->method('getType')->will($this->returnValue('mysql'));
     $this->store->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($connection));
     $instance = new FulltextSearchTableFactory();
     $this->assertInstanceOf('\\SMW\\SQLStore\\QueryEngine\\Fulltext\\MySQLValueMatchConditionBuilder', $instance->newValueMatchConditionBuilderByType($this->store));
 }
 private function addFulltextSearchCondition($query, $comparator, &$value)
 {
     // Remove remaining ~ from the search string
     $value = str_replace('~', '', $value);
     $valueMatchConditionBuilder = $this->fulltextSearchTableFactory->newValueMatchConditionBuilderByType($this->querySegmentListBuilder->getStore());
     if (!$valueMatchConditionBuilder->isEnabled() || !$valueMatchConditionBuilder->hasMinTokenLength($value)) {
         return false;
     }
     $query->joinTable = $valueMatchConditionBuilder->getTableName();
     $query->joinfield = "{$query->alias}.s_id";
     $query->components = array();
     $query->where = $valueMatchConditionBuilder->getWhereCondition(new ValueDescription(new DIBlob($value), null, $comparator), $query->alias);
     return $query;
 }
 /**
  * Given an Description that is just a conjunction or disjunction of
  * ValueDescription objects, create and return a plain WHERE condition
  * string for it.
  *
  * @param $query
  * @param ValueDescription $description
  * @param DataItemHandler $diHandler for that table
  * @param string $operator SQL operator "AND" or "OR"
  */
 private function mapValueDescription($query, ValueDescription $description, DataItemHandler $diHandler, $operator)
 {
     $where = '';
     $dataItem = $description->getDataItem();
     $db = $this->querySegmentListBuilder->getStore()->getConnection('mw.db.queryengine');
     $valueMatchConditionBuilder = $this->fulltextSearchTableFactory->newValueMatchConditionBuilderByType($this->querySegmentListBuilder->getStore());
     // TODO Better get the handle from the property type
     // Some comparators (e.g. LIKE) could use DI values of
     // a different type; we care about the property table, not
     // about the value
     // Do not support smw_id joined data for now.
     $indexField = $diHandler->getIndexField();
     //Hack to get to the field used as index
     $keys = $diHandler->getWhereConds($dataItem);
     $value = $keys[$indexField];
     // See if the getSQLCondition method exists and call it if this is the case.
     // Invoked by SMAreaValueDescription, SMGeoCoordsValueDescription
     if (method_exists($description, 'getSQLCondition')) {
         $fields = $diHandler->getTableFields();
         $where = $description->getSQLCondition($query->alias, array_keys($fields), $this->querySegmentListBuilder->getStore()->getConnection(DB_SLAVE));
     }
     if ($where == '' && $valueMatchConditionBuilder->canApplyFulltextSearchMatchCondition($description)) {
         $query->joinTable = $valueMatchConditionBuilder->getTableName();
         $query->sortIndexField = $valueMatchConditionBuilder->getSortIndexField($query->alias);
         $query->components = array();
         $where = $valueMatchConditionBuilder->getWhereCondition($description, $query->alias);
     } elseif ($where == '') {
         $comparator = $this->comparatorMapper->mapComparator($description, $value);
         $where = "{$query->alias}.{$indexField}{$comparator}" . $db->addQuotes($value);
     }
     if ($where !== '') {
         if ($query->where && substr($query->where, -1) != '(') {
             $query->where .= " {$operator} ";
         }
         $query->where .= "({$where})";
     }
 }