예제 #1
0
 /**
  * Create a new query.
  *
  * @param $search_query string The query.  Syntax is as described above.
  * Note that an empty $search_query will match anything.
  * @param $case_exact boolean
  * @param $regex string one of 'auto', 'none', 'glob', 'posix', 'pcre', 'sql'
  * @see TextSearchQuery
  */
 function TextSearchQuery($search_query, $case_exact = false, $regex = 'auto')
 {
     if ($regex == 'none' or !$regex) {
         $this->_regex = 0;
     } elseif (defined("TSQ_REGEX_" . strtoupper($regex))) {
         $this->_regex = constant("TSQ_REGEX_" . strtoupper($regex));
     } else {
         trigger_error(fmt("Unsupported argument: %s=%s", 'regex', $regex));
         $this->_regex = 0;
     }
     $this->_case_exact = $case_exact;
     $parser = new TextSearchQuery_Parser();
     $this->_tree = $parser->parse($search_query, $case_exact, $this->_regex);
     $this->_optimize();
     // broken under certain circumstances: "word -word -word"
     $this->_stoplist = '(A|An|And|But|By|For|From|In|Is|It|Of|On|Or|The|To|With)';
 }
예제 #2
0
 /**
  * Create a new query.
  *
  * @param $search_query string The query.  Syntax is as described above.
  * Note that an empty $search_query will match anything.
  * @param $case_exact boolean
  * @param $regex string one of 'auto', 'none', 'glob', 'posix', 'pcre', 'sql'
  * @see TextSearchQuery
  */
 function TextSearchQuery($search_query, $case_exact = false, $regex = 'auto')
 {
     if ($regex == 'none' or !$regex) {
         $this->_regex = 0;
     } elseif (defined("TSQ_REGEX_" . strtoupper($regex))) {
         $this->_regex = constant("TSQ_REGEX_" . strtoupper($regex));
     } else {
         trigger_error(fmt("Unsupported argument: %s=%s", 'regex', $regex));
         $this->_regex = 0;
     }
     $this->_regex_modifier = ($case_exact ? '' : 'i') . 'sS';
     $this->_case_exact = $case_exact;
     if ($regex != 'pcre') {
         $parser = new TextSearchQuery_Parser();
         $this->_tree = $parser->parse($search_query, $case_exact, $this->_regex);
         $this->_optimize();
         // broken under certain circumstances: "word -word -word"
         if (defined("FULLTEXTSEARCH_STOPLIST")) {
             $this->_stoplist = FULLTEXTSEARCH_STOPLIST;
         } else {
             // default stoplist, localizable.
             $this->_stoplist = _("(A|An|And|But|By|For|From|In|Is|It|Of|On|Or|The|To|With)");
         }
     } else {
         $this->_tree = new TextSearchQuery_node_regex_pcre($search_query);
         if (preg_match("/^\\/(.*)\\/(\\w*)\$/", $search_query, $m)) {
             $this->_tree->word = $m[1];
             $this->_regex_modifier = $m[2];
             // overrides case_exact
         }
     }
 }