コード例 #1
0
ファイル: Connector.php プロジェクト: jlehmus/NDL-VuFind2
 /**
  * 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 : '';
 }
コード例 #2
0
 /**
  * Return normalized input string.
  *
  * @param string $searchString Input search string
  *
  * @return string
  */
 public function normalizeSearchString($searchString)
 {
     $searchString = parent::normalizeSearchString($searchString);
     $searchString = $this->normalizeUnicodeForm($searchString);
     $searchString = $this->normalizeISBN($searchString);
     return $searchString;
 }
コード例 #3
0
 protected function prepareForLuceneSyntax($input)
 {
     $input = parent::prepareForLuceneSyntax($input);
     //user complained:
     //"Das medizinische Berlin – Ein Stadtführer durch 300 Jahre Geschichte" wasn't found because of the special character copied from Wikipedia
     //will be converted to:
     //"Das medizinische Berlin Ein Stadtführer durch 300 Jahre Geschichte"
     $patterns = array("/–/");
     //in case you want more patterns to remove
     //$patterns = array("/\xE2\x80\x93/", "/Das/");
     $input = preg_replace($patterns, ' ', $input);
     return $input;
 }
コード例 #4
0
ファイル: Params.php プロジェクト: grharry/vufind
 /**
  * Support method for initGenericRangeFilters() -- build a filter query based on
  * a range of values.
  *
  * @param string $field field to use for filtering.
  * @param string $from  start of range.
  * @param string $to    end of range.
  * @param bool   $cs    Should ranges be case-sensitive?
  *
  * @return string       filter query.
  */
 protected function buildGenericRangeFilter($field, $from, $to, $cs = true)
 {
     // Assume Solr syntax -- this should be overridden in child classes where
     // other indexing methodologies are used.
     $range = "{$field}:[{$from} TO {$to}]";
     if (!$cs) {
         // Flip values if out of order:
         if (strcmp(strtolower($from), strtolower($to)) > 0) {
             $range = "{$field}:[{$to} TO {$from}]";
         }
         $helper = new LuceneSyntaxHelper(false, false);
         $range = $helper->capitalizeRanges($range);
     }
     return $range;
 }
コード例 #5
0
 /**
  * Test case insensitive range normalization
  *
  * @return void
  */
 public function testCaseInsensitiveRangeNormalization()
 {
     $lh = new LuceneSyntaxHelper(false, false);
     $this->assertFalse($lh->hasCaseSensitiveRanges());
     $this->assertEquals('a:([b TO c] OR [B TO C])', $lh->normalizeSearchString('a:[b to c]'));
 }
コード例 #6
0
 /**
  * Test colon normalization
  *
  * @return void
  */
 public function testColonNormalization()
 {
     $lh = new LuceneSyntaxHelper(false, false);
     $tests = ['this : that' => 'this  that', 'this: that' => 'this that', 'this that:' => 'this that', ':this that' => 'this that', 'this :that' => 'this that', 'this:that' => 'this:that', 'this::::::that' => 'this:that', '"this : that"' => '"this : that"', '::::::::::::::::::::' => ''];
     foreach ($tests as $input => $expected) {
         $this->assertEquals($expected, $lh->normalizeSearchString($input));
     }
 }
コード例 #7
0
 /**
  * Test search term extraction
  *
  * @return void
  */
 public function testExtractSearchTerms()
 {
     $lh = new LuceneSyntaxHelper(false, false);
     $tests = ['keyword' => 'keyword', 'two keywords' => 'two keywords', 'index:keyword' => 'keyword', 'index:keyword anotherkeyword' => 'keyword anotherkeyword', 'index:keyword anotherindex:anotherkeyword' => 'keyword anotherkeyword', '(index:keyword)' => 'keyword', 'index:(keyword1 keyword2)' => '(keyword1 keyword2)', '{!local params}keyword' => 'keyword', 'keyword~' => 'keyword', 'keyword~0.8' => 'keyword', 'keyword keyword2^20' => 'keyword keyword2', '"keyword keyword2 keyword3"~2' => '"keyword keyword2 keyword3"', '"kw1 kw2 kw3"~2 kw4^200' => '"kw1 kw2 kw3" kw4', '+keyword -keyword2^20' => 'keyword keyword2', 'index:+keyword index2:-keyword2^20' => 'keyword keyword2', 'index:[start TO end]' => '[start TO end]', 'index:{start TO end}' => '{start TO end}', 'es\\"caped field:test' => 'es\\"caped test'];
     foreach ($tests as $input => $expected) {
         $this->assertEquals($expected, $lh->extractSearchTerms($input));
     }
 }