/** * 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; }
/** * Support method for initSearch() -- handle advanced settings. Advanced * searches have numeric subscripts on the lookfor and type parameters -- * this is how they are distinguished from basic searches. * * @param \Zend\StdLib\Parameters $request Parameter object representing user * request. * * @return void */ protected function initAdvancedSearch($request) { $this->query = QueryAdapter::fromRequest($request, $this->getOptions()->getDefaultHandler()); $this->searchType = $this->query instanceof Query ? 'basic' : 'advanced'; // If we ended up with a basic search, set the default handler if necessary: if ($this->searchType == 'basic' && $this->query->getHandler() === null) { $this->query->setHandler($this->getOptions()->getDefaultHandler()); } }
/** * Support method for initSearch() -- handle advanced settings. Advanced * searches have numeric subscripts on the lookfor and type parameters -- * this is how they are distinguished from basic searches. * * @param \Zend\StdLib\Parameters $request Parameter object representing user * request. * * @return void */ protected function initAdvancedSearch($request) { $this->query = QueryAdapter::fromRequest($request, $this->getOptions()->getDefaultHandler()); $this->searchType = $this->query instanceof Query ? 'basic' : 'advanced'; // If we ended up with a basic search, it's probably the result of // submitting an empty form, and more processing may be needed: if ($this->searchType == 'basic') { // Set a default handler if necessary: if ($this->query->getHandler() === null) { $this->query->setHandler($this->getOptions()->getDefaultHandler()); } // If the user submitted the advanced search form, we want to treat // the search as advanced even if it evaluated to a basic search. if ($request->offsetExists('lookfor0')) { $this->convertToAdvancedSearch(); } } }
/** * Test setHandler() method * * @return void */ public function testSetHandler() { $q = new Query('foo', 'bar'); $q->setHandler('baz'); $this->assertEquals('baz', $q->getHandler()); }
/** * 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 array */ protected function queryToArray(Query $query) { // Clean and validate input: $index = $query->getHandler(); $lookfor = $query->getString(); return [compact('index', 'lookfor')]; }