/** * @since 2.5 * * @param ValueDescription $description * * @return boolean */ public function canApplyFulltextSearchMatchCondition(ValueDescription $description) { if (!$this->isEnabled() || $description->getProperty() === null) { return false; } if ($this->searchTable->isExemptedProperty($description->getProperty())) { return false; } $matchableText = $this->getMatchableTextFromDescription($description); $comparator = $description->getComparator(); if ($matchableText && ($comparator === SMW_CMP_LIKE || $comparator === SMW_CMP_NLKE)) { return $this->hasMinTokenLength(str_replace('*', '', $matchableText)); } return false; }
/** * @since 2.2 * * @param ValueDescription $description * @param string &$value * * @return string * @throws RuntimeException */ public function mapComparator(ValueDescription $description, &$value) { $comparatorMap = array(SMW_CMP_EQ => '=', SMW_CMP_LESS => '<', SMW_CMP_GRTR => '>', SMW_CMP_LEQ => '<=', SMW_CMP_GEQ => '>=', SMW_CMP_NEQ => '!=', SMW_CMP_LIKE => ' LIKE ', SMW_CMP_NLKE => ' NOT LIKE '); $comparator = $description->getComparator(); if (!isset($comparatorMap[$comparator])) { throw new RuntimeException("Unsupported comparator '" . $comparator . "' in value description."); } if ($comparator === SMW_CMP_LIKE || $comparator === SMW_CMP_NLKE) { if ($description->getDataItem() instanceof DIUri) { $value = str_replace(array('http://', 'https://', '%2A'), array('', '', '*'), $value); } // Escape to prepare string matching: $value = str_replace(array('\\', '%', '_', '*', '?'), array('\\\\', '\\%', '\\_', '%', '_'), $value); } return $comparatorMap[$comparator]; }
/** * @since 2.5 * * @param ValueDescription $description * * @return boolean */ public function canApplyFulltextSearchMatchCondition(ValueDescription $description) { if (!$this->isEnabled() || $description->getProperty() === null) { return false; } if ($this->searchTable->isExemptedProperty($description->getProperty())) { return false; } $matchableText = $this->getMatchableTextFromDescription($description); $comparator = $description->getComparator(); if ($matchableText && ($comparator === SMW_CMP_LIKE || $comparator === SMW_CMP_NLKE)) { // http://dev.mysql.com/doc/refman/5.7/en/fulltext-boolean.html // innodb_ft_min_token_size and innodb_ft_max_token_size are used // for InnoDB search indexes. ft_min_word_len and ft_max_word_len // are used for MyISAM search indexes // Don't count any wildcard return $this->hasMinTokenLength(str_replace('*', '', $matchableText)); } return false; }
/** * @dataProvider valueDescriptionProvider */ public function testCommonMethods($dataItem, $property, $comparator, $expected) { $instance = new ValueDescription($dataItem, $property, $comparator); $this->assertEquals($expected['comparator'], $instance->getComparator()); $this->assertEquals($expected['dataItem'], $instance->getDataItem()); $this->assertEquals($expected['property'], $instance->getProperty()); $this->assertEquals($expected['queryString'], $instance->getQueryString()); $this->assertEquals($expected['queryStringAsValue'], $instance->getQueryString(true)); $this->assertEquals($expected['isSingleton'], $instance->isSingleton()); $this->assertEquals(array(), $instance->getPrintRequests()); $this->assertEquals(1, $instance->getSize()); $this->assertEquals(0, $instance->getDepth()); $this->assertEquals(0, $instance->getQueryFeatures()); }
private function doMapValueDescription(ValueDescription $description, &$exact) { if ($description->getComparator() === SMW_CMP_EQ) { $result = $this->exporter->getDataItemExpElement($description->getDataItem()); } else { // OWL cannot represent <= and >= ... $exact = false; $result = false; } return $result; }
/** * 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->queryBuilder->getStore()->getConnection('mw.db'); // 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->queryBuilder->getStore()->getConnection(DB_SLAVE)); } if ($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})"; } }