Exemplo n.º 1
0
 /**
  * Test capitalizeRanges functionality.
  *
  * @return void
  */
 public function testCapitalizeRanges()
 {
     // Set up an array of expected inputs and outputs:
     // @codingStandardsIgnoreStart
     $tests = array(array('"{a to b}"', '"{a to b}"'), array('"[a to b]"', '"[a to b]"'), array('[a to b]', '([a TO b] OR [A TO B])'), array('[a TO b]', '([a TO b] OR [A TO B])'), array('[a To b]', '([a TO b] OR [A TO B])'), array('[a tO b]', '([a TO b] OR [A TO B])'), array('{a to b}', '({a TO b} OR {A TO B})'), array('{a TO b}', '({a TO b} OR {A TO B})'), array('{a To b}', '({a TO b} OR {A TO B})'), array('{a tO b}', '({a TO b} OR {A TO B})'), array('[1900 to 1910]', '[1900 TO 1910]'), array('[1900 TO 1910]', '[1900 TO 1910]'), array('{1900 to 1910}', '{1900 TO 1910}'), array('{1900 TO 1910}', '{1900 TO 1910}'), array('[a      to      b]', '([a TO b] OR [A TO B])'), array('[1900-01-01t00:00:00z to 1900-12-31t23:59:59z]', '[1900-01-01T00:00:00Z TO 1900-12-31T23:59:59Z]'), array('{1900-01-01T00:00:00Z       TO   1900-12-31T23:59:59Z}', '{1900-01-01T00:00:00Z TO 1900-12-31T23:59:59Z}'));
     // @codingStandardsIgnoreEnd
     // Test all the operations:
     foreach ($tests as $current) {
         $this->assertEquals(Utils::capitalizeRanges($current[0]), $current[1]);
     }
 }
Exemplo n.º 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;
     }
 }