Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Return a query string for the current search with a search term replaced.
  *
  * @param string $oldTerm The old term to replace
  * @param string $newTerm The new term to search
  *
  * @return string         query string
  */
 public function getDisplayQueryWithReplacedTerm($oldTerm, $newTerm)
 {
     // Stash our old data for a minute
     $oldTerms = clone $this->query;
     // Replace the search term
     $this->query->replaceTerm($oldTerm, $newTerm);
     // Get the new query string
     $query = $this->getDisplayQuery();
     // Restore the old data
     $this->query = $oldTerms;
     // Return the query string
     return $query;
 }
Example #3
0
 /**
  * Test setOperator() method
  *
  * @return void
  */
 public function testSetOperator()
 {
     $q = new Query('foo', 'bar');
     $q->setOperator('baz');
     $this->assertEquals('baz', $q->getOperator());
 }
Example #4
0
 /**
  * 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;
 }
Example #5
0
 /**
  * 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) . ')';
 }
Example #6
0
 /**
  * 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());
 }
Example #7
0
 /**
  * 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')];
 }