Esempio n. 1
0
 /**
  * Return advanced inner search string based on input and handler.
  *
  * @param string        $string  Input search string
  * @param SearchHandler $handler Search handler
  *
  * @return string
  */
 protected function createAdvancedInnerSearchString($string, SearchHandler $handler)
 {
     // Special case -- if the user wants all records but the current handler
     // has a filter query, apply the filter query:
     if (trim($string) === '*:*' && $handler && $handler->hasFilterQuery()) {
         return $handler->getFilterQuery();
     }
     // If the query already includes field specifications, we can't easily
     // apply it to other fields through our defined handlers, so we'll leave
     // it as-is:
     if (strstr($string, ':')) {
         return $string;
     }
     // If the query ends in a non-escaped question mark, the user may not really
     // intend to use the question mark as a wildcard -- let's account for that
     // possibility
     if (substr($string, -1) == '?' && substr($string, -2) != '\\?') {
         // Make sure all question marks are properly escaped (first unescape
         // any that are already escaped to prevent double-escapes, then escape
         // all of them):
         $strippedQuery = str_replace('?', '\\?', str_replace('\\?', '?', $string));
         $string = "({$string}) OR (" . $strippedQuery . ")";
     }
     return $handler ? $handler->createAdvancedQueryString($string, false) : $string;
 }
Esempio n. 2
0
 /**
  * Test custom munge rules.
  *
  * @return void
  */
 public function testCustomMunge()
 {
     // fake munge rules based on a simplified version of default searchspecs.yaml
     $spec = ['CustomMunge' => ['callnumber_exact' => [['uppercase'], ['preg_replace', '/[ "]/', ""], ['preg_replace', '/\\*+$/', ""]], 'callnumber_fuzzy' => [['uppercase'], ['preg_replace', '/[ "]/', ""], ['preg_replace', '/\\*+$/', ""], ['append', '*']]], 'QueryFields' => ['callnumber' => [['callnumber_exact', 1000], ['callnumber_fuzzy', '~']], 'dewey-full' => [['callnumber_exact', 1000], ['callnumber_fuzzy', '~']]]];
     $hndl = new SearchHandler($spec);
     $this->assertEquals('(callnumber:(ABC123)^1000 OR callnumber:(ABC123*) OR dewey-full:(ABC123)^1000 OR dewey-full:(ABC123*))', $hndl->createSimpleQueryString('abc"123*'));
 }
Esempio n. 3
0
 /**
  * Return advanced inner search string based on input and handler.
  *
  * @param string        $string  Input search string
  * @param SearchHandler $handler Search handler
  *
  * @return string
  */
 protected function createAdvancedInnerSearchString($string, SearchHandler $handler)
 {
     // Special case -- if the user wants all records but the current handler
     // has a filter query, apply the filter query:
     if (trim($string) === '*:*' && $handler && $handler->hasFilterQuery()) {
         return $handler->getFilterQuery();
     }
     // If the query already includes field specifications, we can't easily
     // apply it to other fields through our defined handlers, so we'll leave
     // it as-is:
     if (strstr($string, ':')) {
         return $string;
     }
     // Account for trailing question marks:
     $string = $this->fixTrailingQuestionMarks($string);
     return $handler ? $handler->createAdvancedQueryString($string, false) : $string;
 }