示例#1
0
 /**
  * Test capitalizeBooleans functionality.
  *
  * @return void
  */
 public function testCapitalizeBooleans()
 {
     // Set up an array of expected inputs and outputs:
     // @codingStandardsIgnoreStart
     $tests = array(array('this not that', 'this NOT that'), array('this and that', 'this AND that'), array('this or that', 'this OR that'), array('apples and oranges (not that)', 'apples AND oranges (NOT that)'), array('"this not that"', '"this not that"'), array('"this and that"', '"this and that"'), array('"this or that"', '"this or that"'), array('"apples and oranges (not that)"', '"apples and oranges (not that)"'), array('this AND that', 'this AND that'), array('and and and', 'and AND and'), array('andornot noted andy oranges', 'andornot noted andy oranges'), array('(this or that) and (apples not oranges)', '(this OR that) AND (apples NOT oranges)'), array('this aNd that', 'this AND that'), array('this nOt that', 'this NOT that'));
     // @codingStandardsIgnoreEnd
     // Test all the operations:
     foreach ($tests as $current) {
         $this->assertEquals(Utils::capitalizeBooleans($current[0]), $current[1]);
     }
 }
示例#2
0
 /**
  * Support method for initSearchParams() -- set up query, handler and filters.
  *
  * @return void
  */
 protected function initSearchQuery()
 {
     // Grab relevant user parameters:
     $query = $this->userSearchParams['query'];
     $filter = $this->userSearchParams['filter'];
     $handler = $this->userSearchParams['handler'];
     // Determine which handler to use
     if (!$this->isAdvanced($query)) {
         $ss = is_null($handler) ? null : $this->getSearchSpecs($handler);
         // Is this a Dismax search?
         if (isset($ss['DismaxFields'])) {
             // Specify the fields to do a Dismax search on and use the default
             // Dismax search handler so we can use appropriate user-specified
             // solrconfig.xml settings:
             $this->solrSearchParams['qf'] = implode(' ', $ss['DismaxFields']);
             $this->solrSearchParams['qt'] = 'dismax';
             // Load any custom Dismax parameters from the YAML search spec file:
             if (isset($ss['DismaxParams']) && is_array($ss['DismaxParams'])) {
                 foreach ($ss['DismaxParams'] as $current) {
                     $this->addSolrSearchParam($current[0], $current[1]);
                 }
             }
             // Apply search-specific filters if necessary:
             if (isset($ss['FilterQuery'])) {
                 if (is_array($filter)) {
                     $filter[] = $ss['FilterQuery'];
                 } else {
                     $filter = array($ss['FilterQuery']);
                 }
             }
         } else {
             // Not DisMax... but if we have a handler set, we may still need
             // to build a query using a setting in the YAML search specs or a
             // simple field name:
             if (!empty($handler)) {
                 $query = $this->buildQueryComponent($handler, $query);
             }
         }
     } else {
         // Force boolean operators and ranges to uppercase if we are in a
         // case-insensitive mode:
         if (!$this->caseSensitiveBooleans) {
             $query = SolrUtils::capitalizeBooleans($query);
         }
         if (!$this->caseSensitiveRanges) {
             $query = SolrUtils::capitalizeRanges($query);
         }
         // Process advanced search -- if a handler was specified, let's see
         // if we can adapt the search to work with the appropriate fields.
         if (!empty($handler)) {
             // If highlighting is enabled, we only want to use the inner query
             // for highlighting; anything added outside of this is a boost and
             // should be ignored for highlighting purposes!
             if ($this->userSearchParams['highlight']) {
                 $this->solrSearchParams['hl.q'] = $this->buildAdvancedInnerQuery($handler, $query);
             }
             $query = $this->buildAdvancedQuery($handler, $query);
         }
     }
     // Now that query and filters are fully processed, add them to the params:
     $this->solrSearchParams['q'] = $query;
     if (is_array($filter) && count($filter)) {
         $this->solrSearchParams['fq'] = $filter;
     }
 }
示例#3
0
 /**
  * Build basic Query string from search parameters (support method for
  * buildQuery)
  *
  * @param array $params An array of search parameters
  *
  * @return string
  */
 protected function buildBasicQuery($params)
 {
     // Clean and validate input -- note that index may be in a
     // different field depending on whether this is a basic or
     // advanced search.
     $lookfor = $params['lookfor'];
     if (isset($params['field'])) {
         $index = $params['field'];
     } else {
         if (isset($params['index'])) {
             $index = $params['index'];
         } else {
             $index = 'AllFields';
         }
     }
     // Force boolean operators to uppercase if we are in a
     // case-insensitive mode:
     if (!$this->caseSensitiveBooleans) {
         $lookfor = SolrUtils::capitalizeBooleans($lookfor);
     }
     // Prepend the index name, unless it's the special "AllFields"
     // index:
     return $index != 'AllFields' ? "{$index}:({$lookfor})" : $lookfor;
 }