/** * Test replaceTerm() method * * @return void */ public function testReplaceTerm() { $q = new Query('test query we<(ird and/or'); $q->replaceTerm('we<(ird', 'we>(ird'); $q->replaceTerm('and/or', 'and-or'); $this->assertEquals('test query we>(ird and-or', $q->getString()); $q = new Query('test query we<(ird and/or'); $q->replaceTerm('and', 'not'); $this->assertEquals('test query we<(ird not/or', $q->getString()); }
/** * Convert a single Query object to an eds api query array * * @param Query $query Query to convert * @param string $operator Operator to apply * * @return string */ protected function queryToEdsQuery(Query $query, $operator = 'AND') { $expression = str_replace('"', '', $query->getString()); $expression = SearchRequestModel::escapeSpecialCharacters($expression); $fieldCode = $query->getHandler() == 'AllFields' ? '' : $query->getHandler(); //fieldcode if (!empty($fieldCode)) { $expression = $fieldCode . ':' . $expression; } if (!empty($operator)) { $expression = $operator . ',' . $expression; } return $expression; }
/** * Convert a single Query object to a query string. * * @param Query $query Query to convert * * @return string */ protected function queryToString(Query $query) { // Clean and validate input: $index = $query->getHandler(); $lookfor = $query->getString(); // Force boolean operators to uppercase if we are in a // case-insensitive mode: $lookfor = $this->getLuceneHelper()->capitalizeCaseInsensitiveBooleans($lookfor); // Prepend the index name, unless it's the special "AllFields" // index: return $index != 'AllFields' ? "{$index}:({$lookfor})" : $lookfor; }
/** * Convert a single Query object to a query string. * * @param Query $query Query to convert * * @return string */ protected function queryToString(Query $query) { // Clean and validate input: $index = $query->getHandler(); if (empty($index)) { // No handler? Just accept query string as-is; no modifications needed. return $query->getString(); } $lookfor = str_replace('"', '', $query->getString()); // The index may contain multiple parts -- we want to search all listed index // fields: $index = explode(':', $index); $clauses = []; foreach ($index as $currentIndex) { $clauses[] = "{$currentIndex} all \"{$lookfor}\""; } return '(' . implode(' OR ', $clauses) . ')'; }
/** * Convert a single Query object to a query string. * * @param Query $query Query to convert * * @return string */ protected function queryToString(Query $query) { return strtolower($query->getString()); }
/** * Convert a single Query object to a query string. * * @param Query $query Query to convert * * @return array */ protected function queryToArray(Query $query) { // Clean and validate input: $index = $query->getHandler(); $lookfor = $query->getString(); return [compact('index', 'lookfor')]; }