/** * @since 2.5 * * @param ValueDescription $description * @param string $temporaryTable * * @return string */ public function getWhereCondition(ValueDescription $description, $temporaryTable = '') { $affix = ''; $matchableText = $this->getMatchableTextFromDescription($description); // Any query modifier? Take care of it before any tokenizer or ngrams // distort the marker if (($pos = strrpos($matchableText, '&BOL')) !== false || ($pos = strrpos($matchableText, '&INL')) !== false || ($pos = strrpos($matchableText, '&QEX')) !== false) { $affix = mb_strcut($matchableText, $pos); $matchableText = str_replace($affix, '', $matchableText); } $value = $this->textSanitizer->sanitize($matchableText, true); $value .= $affix; // A leading or trailing minus sign indicates that this word must not // be present in any of the rows that are returned. // InnoDB only supports leading minus signs. if ($description->getComparator() === SMW_CMP_NLKE) { $value = '-' . $value; } $temporaryTable = $temporaryTable !== '' ? $temporaryTable . '.' : ''; $column = $temporaryTable . $this->searchTable->getIndexField(); $property = $description->getProperty(); $propertyCondition = ''; // Full text is collected in a single table therefore limit the match // process by adding the PID as an additional condition if ($property !== null) { $propertyCondition = 'AND ' . $temporaryTable . 'p_id=' . $this->searchTable->getPropertyIdBy($property); } $querySearchModifier = $this->getQuerySearchModifier($value); return "MATCH({$column}) AGAINST (" . $this->searchTable->addQuotes($value) . " {$querySearchModifier}) {$propertyCondition}"; }
/** * @since 2.5 * * @param ValueDescription $description * @param string $temporaryTable * * @return string */ public function getWhereCondition(ValueDescription $description, $temporaryTable = '') { $matchableText = $this->getMatchableTextFromDescription($description); $value = $this->textSanitizer->sanitize($matchableText, true); // A leading or trailing minus sign indicates that this word must not // be present in any of the rows that are returned. // InnoDB only supports leading minus signs. if ($description->getComparator() === SMW_CMP_NLKE) { $value = '-' . $value; } // Something like [[Has text::!~database]] will cause a // "malformed MATCH expression" due to "An FTS query may not consist // entirely of terms or term-prefix queries with unary "-" operators // attached to them." and doing "NOT database" will result in an empty // result set $temporaryTable = $temporaryTable !== '' ? $temporaryTable . '.' : ''; $column = $temporaryTable . $this->searchTable->getIndexField(); $property = $description->getProperty(); $propertyCondition = ''; // Full text is collected in a single table therefore limit the match // process by adding the PID as an additional condition if ($property !== null) { $propertyCondition = ' AND ' . $temporaryTable . 'p_id=' . $this->searchTable->addQuotes($this->searchTable->getPropertyIdBy($property)); } return $column . " MATCH " . $this->searchTable->addQuotes($value) . "{$propertyCondition}"; }