Beispiel #1
0
 /**
  * Support method for buildQuery() -- Build a basic query
  *
  * @param array $params Search parameters
  *
  * @return string Query
  */
 protected function buildBasicQuery($params)
 {
     $query = '';
     if (!empty($params['lookfor'])) {
         // Basic Search
         // 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'];
         $index = !empty($params['index']) ? $params['index'] : 'AllFields';
         // Force boolean operators to uppercase if we are in a
         // case-insensitive mode:
         if ($this->luceneHelper) {
             $lookfor = $this->luceneHelper->capitalizeBooleans($lookfor);
         }
         $map = ['AllFields' => 'WRD', 'Title' => 'WTI', 'Author' => 'WAU', 'Subject' => 'WSU', 'isbn' => 'ISBN', 'issn' => 'ISSN'];
         if (isset($map[$index])) {
             $index = $map[$index];
         } else {
             if (!array_key_exists($index, $map)) {
                 $index = 'WRD';
             }
         }
         $query .= "{$index}=({$lookfor})";
     }
     // Ensure we have a valid query to this point
     return isset($query) ? $query : '';
 }
 /**
  * Test the selective capitalization functionality of capitalizeBooleans.
  *
  * @return void
  */
 public function testSelectiveBooleanCapitalization()
 {
     $lh = new LuceneSyntaxHelper();
     $in = 'this or that and the other not everything else (not me)';
     $this->assertEquals('this OR that AND the other NOT everything else (NOT me)', $lh->capitalizeBooleans($in, ['AND', 'OR', 'NOT']));
     $this->assertEquals('this OR that and the other NOT everything else (NOT me)', $lh->capitalizeBooleans($in, ['OR', 'NOT']));
     $this->assertEquals('this or that and the other NOT everything else (NOT me)', $lh->capitalizeBooleans($in, ['NOT']));
     $this->assertEquals('this or that AND the other not everything else (not me)', $lh->capitalizeBooleans($in, ['AND']));
     $this->assertEquals('this OR that and the other not everything else (not me)', $lh->capitalizeBooleans($in, ['OR']));
 }