/**
  * Method to set search criteria
  *
  * @param   string  $str_criteria
  * @return  void
  */
 public function setSQLcriteria($str_criteria)
 {
     // defaults
     $_sql_criteria = '';
     $_searched_fields = array();
     $_title_buffer = '';
     $_previous_field = '';
     $_boolean = '';
     // parse query
     $this->orig_query = $str_criteria;
     $_queries = simbio_tokenizeCQL($str_criteria, $this->searchable_fields, $this->stop_words, $this->queries_word_num_allowed);
     // var_dump($_queries);
     if (count($_queries) < 1) {
         return null;
     }
     // loop each query
     foreach ($_queries as $_num => $_query) {
         // field
         $_field = $_query['f'];
         // for debugging purpose only
         // echo "<p>$_num. $_field -> $_boolean -> $_sql_criteria</p><p>&nbsp;</p>";
         // boolean
         if ($_title_buffer == '' && $_field != 'boolean') {
             $_sql_criteria .= " {$_boolean} ";
         }
         // $_sql_criteria .= " $_boolean ";
         // flush title string concatenation
         if ($_field != 'title' && $_title_buffer != '') {
             $_title_buffer = trim($_title_buffer);
             $_sql_criteria .= " biblio.biblio_id IN(SELECT DISTINCT biblio_id FROM biblio WHERE MATCH (title, series_title) AGAINST ('{$_title_buffer}' IN BOOLEAN MODE)) ";
             // reset title buffer
             $_title_buffer = '';
         }
         //  break the loop if we meet `cql_end` field
         if ($_field == 'cql_end') {
             break;
         }
         // boolean mode
         $_b = isset($_query['b']) ? $_query['b'] : $_query;
         if ($_b == '*') {
             $_boolean = 'OR';
         } else {
             $_boolean = 'AND';
         }
         // search value
         $_q = @$this->obj_db->escape_string($_query['q']);
         // searched fields flag set
         $_searched_fields[$_field] = 1;
         $_previous_field = $_field;
         // check field
         if ($_field == 'title') {
             if (strlen($_q) < 4) {
                 $_previous_field = 'title_short';
                 $_sql_criteria .= " biblio.title LIKE '%{$_q}%' ";
                 $_title_buffer = '';
             } else {
                 if (isset($_query['is_phrase'])) {
                     $_title_buffer .= ' ' . $_b . '"' . $_q . '"';
                 } else {
                     $_title_buffer .= ' ' . $_b . $_q;
                 }
             }
         } else {
             if ($_field == 'author') {
                 if ($_b == '-') {
                     $_sql_criteria .= " biblio.biblio_id NOT IN(SELECT ba.biblio_id FROM biblio_author AS ba" . " LEFT JOIN mst_author AS a ON ba.author_id=a.author_id" . " WHERE author_name LIKE '%{$_q}%')";
                 } else {
                     $_sql_criteria .= " biblio.biblio_id IN(SELECT ba.biblio_id FROM biblio_author AS ba" . " LEFT JOIN mst_author AS a ON ba.author_id=a.author_id" . " WHERE author_name LIKE '%{$_q}%')";
                 }
             } else {
                 if ($_field == 'subject') {
                     if ($_b == '-') {
                         $_sql_criteria .= " biblio.biblio_id NOT IN(SELECT bt.biblio_id FROM biblio_topic AS bt" . " LEFT JOIN mst_topic AS t ON bt.topic_id=t.topic_id" . " WHERE topic LIKE '%{$_q}%')";
                     } else {
                         $_sql_criteria .= " biblio.biblio_id IN(SELECT bt.biblio_id FROM biblio_topic AS bt" . " LEFT JOIN mst_topic AS t ON bt.topic_id=t.topic_id" . " WHERE topic LIKE '%{$_q}%')";
                     }
                     // reset title buffer
                     $_title_buffer = '';
                 } else {
                     switch ($_field) {
                         case 'location':
                             $_subquery = 'SELECT location_id FROM mst_location WHERE location_name=\'' . $_q . '\'';
                             if ($_b == '-') {
                                 $_sql_criteria .= " item.location_id NOT IN ({$_subquery})";
                             } else {
                                 $_sql_criteria .= " item.location_id IN ({$_subquery})";
                             }
                             break;
                         case 'colltype':
                             $_subquery = 'SELECT coll_type_id FROM mst_coll_type WHERE coll_type_name=\'' . $_q . '\'';
                             if ($_b == '-') {
                                 $_sql_criteria .= " item.coll_type_id NOT IN ({$_subquery})";
                             } else {
                                 $_sql_criteria .= " item.coll_type_id IN ({$_subquery})";
                             }
                             break;
                         case 'itemcode':
                             if ($_b == '-') {
                                 $_sql_criteria .= " item.item_code != '{$_q}'";
                             } else {
                                 $_sql_criteria .= " item.item_code LIKE '{$_q}%'";
                             }
                             break;
                         case 'callnumber':
                             if ($_b == '-') {
                                 $_sql_criteria .= ' AND biblio.call_number NOT LIKE \'' . $_q . '%\'';
                             } else {
                                 $_sql_criteria .= ' biblio.call_number LIKE \'' . $_q . '%\'';
                             }
                             break;
                         case 'itemcallnumber':
                             if ($_b == '-') {
                                 $_sql_criteria .= ' AND item.call_number NOT LIKE \'' . $_q . '%\'';
                             } else {
                                 $_sql_criteria .= ' item.call_number LIKE \'' . $_q . '%\'';
                             }
                             break;
                         case 'class':
                             if ($_b == '-') {
                                 $_sql_criteria .= ' AND biblio.classification NOT LIKE \'' . $_q . '%\'';
                             } else {
                                 $_sql_criteria .= ' biblio.classification LIKE \'' . $_q . '%\'';
                             }
                             break;
                         case 'isbn':
                             if ($_b == '-') {
                                 $_sql_criteria .= ' AND biblio.isbn_issn!=\'' . $_q . '\'';
                             } else {
                                 $_sql_criteria .= ' biblio.isbn_issn=\'' . $_q . '\'';
                             }
                             break;
                         case 'publisher':
                             $_subquery = 'SELECT publisher_id FROM mst_publisher WHERE publisher_name=\'' . $_q . '\'';
                             if ($_b == '-') {
                                 $_sql_criteria .= " biblio.publisher_id NOT IN ({$_subquery})";
                             } else {
                                 $_sql_criteria .= " biblio.publisher_id IN ({$_subquery})";
                             }
                             break;
                         case 'gmd':
                             $_subquery = 'SELECT gmd_id FROM mst_gmd WHERE gmd_name=\'' . $_q . '\'';
                             if ($_b == '-') {
                                 $_sql_criteria .= " biblio.gmd_id NOT IN ({$_subquery})";
                             } else {
                                 $_sql_criteria .= " biblio.gmd_id IN ({$_subquery})";
                             }
                             break;
                         case 'notes':
                             if ($_b == '-') {
                                 $_sql_criteria .= " NOT (MATCH (biblio.notes) AGAINST ('" . $_q . "', IN BOOLEAN MODE))";
                             } else {
                                 $_sql_criteria .= " (MATCH (biblio.notes) AGAINST ('" . $_q . "', IN BOOLEAN MODE))";
                             }
                             break;
                     }
                 }
             }
         }
     }
     // remove boolean's logic symbol prefix and suffix
     $_sql_criteria = preg_replace('@^(AND|OR|NOT)\\s*|\\s+(AND|OR|NOT)$@i', '', trim($_sql_criteria));
     // below for debugging purpose only
     // echo "<div style=\"border: 1px solid #ff0000; padding: 5px; color: #ff0000; margin: 5px;\">$_sql_criteria</div>";
     $this->criteria = array('sql_criteria' => $_sql_criteria, 'searched_fields' => $_searched_fields);
     return $this->criteria;
 }
 /**
  * Method to set search criteria
  *
  * @param   string  $str_criteria
  * @return  void
  */
 public function setSQLcriteria($str_criteria)
 {
     if (!$str_criteria) {
         return null;
     }
     // defaults
     $_query_str = '';
     $_searched_fields = array();
     $_previous_field = '';
     $_boolean = '';
     $_b = '';
     // parse query
     $this->orig_query = $str_criteria;
     $_queries = simbio_tokenizeCQL($str_criteria, $this->searchable_fields, $this->stop_words, $this->queries_word_num_allowed);
     // var_dump($_queries);
     if (count($_queries) < 1) {
         return null;
     }
     // loop each query
     // echo '<pre>'; var_dump($_queries); echo '</pre>';
     foreach ($_queries as $_num => $_query) {
         // field
         $_field = $_query['f'];
         if ($_previous_field != $_field) {
             if ($_field != 'boolean') {
                 $_query_str .= '';
             } else {
                 $_query_str .= ')';
             }
         }
         //  break the loop if we meet `cql_end` field
         if ($_field == 'cql_end') {
             continue;
         }
         // if field is boolean
         if ($_field == 'boolean') {
             if ($_query['b'] == '*') {
                 $_query_str .= ' | ';
             } else {
                 $_query_str .= ' & ';
             }
             continue;
         } else {
             if ($_query['b'] == '-') {
                 $_query_str .= ' -';
             } else {
                 if ($_query['b'] == '*') {
                     $_query_str .= ' | ';
                 } else {
                     $_query_str .= ' ';
                 }
             }
             $_q = @$this->obj_db->escape_string($_query['q']);
             $_q = isset($_query['is_phrase']) ? '"' . $_q . '"' : $_q;
             $_boolean = '';
         }
         if ($_previous_field == $_field) {
             $_query_str .= $_q;
             continue;
         }
         $_previous_field = $_field;
         // for debugging purpose only
         // echo "<p>$_num. $_field -> $_boolean -> $_query_str</p><p>&nbsp;</p>";
         // check fields
         $_q = $_b . $_q;
         switch ($_field) {
             case 'author':
                 $_query_str .= " (@author {$_q}";
                 break;
             case 'subject':
                 $_query_str .= " (@topic {$_q}";
                 break;
             case 'location':
                 $_query_str .= " (@location {$_q}";
                 break;
             case 'colltype':
                 $_query_str .= " (@collection_types {$_q}";
                 break;
             case 'itemcode':
                 $_query_str .= " (@items {$_q}";
                 break;
             case 'callnumber':
                 $_query_str .= " (@call_number {$_q}";
                 break;
             case 'itemcallnumber':
                 $_query_str .= " (@item_call_number {$_q}";
                 break;
             case 'class':
                 $_query_str .= " (@classification {$_q}";
                 break;
             case 'isbn':
                 $_query_str .= " (@isbn_issn {$_q}";
                 break;
             case 'publisher':
                 $_query_str .= " (@publisher {$_q}";
                 break;
             case 'publishyear':
                 $_query_str .= " (@publish_year {$_q}";
                 break;
             case 'gmd':
                 $_query_str .= " (@gmd {$_q}";
                 break;
             case 'notes':
                 $_query_str .= " (@notes {$_q}";
                 break;
             default:
                 $_query_str .= " (@title {$_q}";
                 break;
         }
     }
     $_query_str .= ')';
     // check if query is empty
     if (!$_query_str) {
         $this->no_query = true;
         $_sql_criteria = 'index.biblio_id IS NOT NULL';
         $this->criteria = array('sql_criteria' => $_sql_criteria, 'searched_fields' => $_searched_fields);
         return $this->criteria;
     }
     // set options
     $this->sphinx->SetServer($this->options['host'], $this->options['port']);
     $this->sphinx->SetConnectTimeout($this->options['timeout']);
     $this->sphinx->SetArrayResult(true);
     $this->sphinx->SetWeights(array(100, 1));
     $this->sphinx->SetMatchMode($this->options['mode']);
     if (count($this->options['filtervals'])) {
         $this->sphinx->SetFilter($this->options['filter'], $this->options['filtervals']);
     }
     if ($this->options['groupby']) {
         $this->sphinx->SetGroupBy($this->options['groupby'], SPH_GROUPBY_ATTR, $this->options['groupsort']);
     }
     if ($this->options['sortby']) {
         $this->sphinx->SetSortMode(SPH_SORT_EXTENDED, $this->options['sortby']);
         $this->sphinx->SetSortMode(SPH_SORT_EXPR, $this->options['sortexpr']);
     }
     $this->sphinx->SetGroupDistinct($this->options['distinct']);
     if ($this->options['select']) {
         $this->sphinx->SetSelect($this->options['select']);
     }
     $this->sphinx->SetLimits($this->offset, $this->num2show ? $this->num2show : $this->options['limit'], $this->options['max_limit']);
     $this->sphinx->SetRankingMode($this->options['ranker']);
     // invoke sphinx query
     $_search_result = $this->sphinx->Query($_query_str, $this->options['index']);
     // echo '<pre>'; var_dump($_search_result); echo '</pre>'; die();
     if ($_search_result === false) {
         $this->sphinx_error = true;
         $this->query_error = $this->sphinx->GetLastError();
         return false;
     }
     if (isset($_search_result['matches']) && is_array($_search_result['matches'])) {
         $_matched_ids = '(';
         foreach ($_search_result['matches'] as $_match) {
             $_matched_ids .= $_match['id'] . ',';
         }
         // remove last comma
         $_matched_ids = substr_replace($_matched_ids, '', -1);
         $_matched_ids .= ')';
         $_sql_criteria = "index.biblio_id IN {$_matched_ids}";
         $this->num_rows = $_search_result['total_found'];
         $this->query_time = $_search_result['time'];
         $this->criteria = array('sql_criteria' => $_sql_criteria, 'searched_fields' => $_searched_fields);
         return $this->criteria;
     } else {
         $this->sphinx_no_result = true;
         return false;
     }
 }
 /**
  * Method to set search criteria
  *
  * @param   string  $str_criteria
  * @return  void
  */
 public function setSQLcriteria($str_criteria)
 {
     if (!$str_criteria) {
         return null;
     }
     // defaults
     $_query_str = '';
     $_searched_fields = array();
     $_previous_field = '';
     $_boolean = '';
     $_last_field = 'title';
     $_field = 'title';
     $_field_str = '';
     $_mongo_boolean_top = false;
     // parse query
     $this->orig_query = $str_criteria;
     $_queries = simbio_tokenizeCQL($str_criteria, $this->searchable_fields, $this->stop_words, $this->queries_word_num_allowed);
     if (count($_queries) < 1) {
         return null;
     }
     // loop each query
     // echo '<pre>'; var_dump($_queries); echo '</pre>';
     $_mongo_search = array();
     foreach ($_queries as $_num => $_query) {
         // field
         $_field = $_query['f'];
         $_q = trim($_query['q']);
         //  break the loop if we meet `cql_end` field
         if ($_field == 'cql_end') {
             continue;
         }
         // if field is boolean
         if ($_field == 'boolean') {
             if ($_query['b'] == '*') {
                 $_mongo_boolean_top = '$or';
             } else {
                 if ($_query['b'] == '-') {
                     $_mongo_boolean_top = '$not';
                 } else {
                     $_mongo_boolean_top = '$and';
                 }
             }
             continue;
         }
         if ($_query['b'] == '*') {
             $_mongo_boolean_field = '$or';
         } else {
             if ($_query['b'] == '-') {
                 $_mongo_boolean_field = '$not';
             } else {
                 $_mongo_boolean_field = '$and';
             }
         }
         $_mongo_search[$_field][$_mongo_boolean_field][] = array($_field => array('$regex' => new MongoRegex('/.*' . $_q . '.*/i')));
         $_searched_fields[$_field] = $_field;
     }
     // preproccess search criteria to match Mongodb arrays
     $_mongo_search_tmp = $_mongo_search;
     $_mongo_search = array();
     if ($_mongo_boolean_top) {
         foreach ($_mongo_search_tmp as $_search_field => $_search_criteria) {
             foreach ($_search_criteria as $_logic => $_search_expr) {
                 $_mongo_search[$_mongo_boolean_top][][$_logic] = $_search_expr;
             }
         }
     } else {
         foreach ($_mongo_search_tmp as $_search_field => $_search_criteria) {
             foreach ($_search_criteria as $_logic => $_search_expr) {
                 $_mongo_search[$_logic][] = $_search_expr;
             }
         }
     }
     unset($_mongo_search_tmp);
     // echo '<pre>'; var_dump($_mongo_search); echo '</pre>';
     // check if query is empty
     if (!$_mongo_search) {
         $this->no_query = true;
         $_mongo_search['biblio_id'] = array('$gt' => 0);
     }
     $this->criteria = array('sql_criteria' => $_mongo_search, 'searched_fields' => $_searched_fields);
     return $this->criteria;
 }
Exemplo n.º 4
0
 /**
  * Method to set search criteria
  *
  * @param   string  $str_criteria
  * @return  void
  */
 public function setSQLcriteria($str_criteria)
 {
     if (!$str_criteria) {
         return null;
     }
     // defaults
     $_sql_criteria = '';
     $_searched_fields = array();
     $_previous_field = '';
     $_boolean = '';
     // parse query
     $this->orig_query = $str_criteria;
     $_queries = simbio_tokenizeCQL($str_criteria, $this->searchable_fields, $this->stop_words, $this->queries_word_num_allowed);
     // var_dump($_queries);
     if (count($_queries) < 1) {
         return null;
     }
     // loop each query
     // echo '<pre>'; var_dump($_queries); echo '</pre>';
     foreach ($_queries as $_num => $_query) {
         // field
         $_field = $_query['f'];
         $_is_phrase = isset($_query['is_phrase']);
         //  break the loop if we meet `cql_end` field
         if ($_field == 'cql_end') {
             break;
         }
         // if field is boolean
         if ($_field == 'boolean') {
             if ($_query['b'] == '*') {
                 $_boolean = 'OR';
             } else {
                 $_boolean = 'AND';
             }
             continue;
         } else {
             if ($_boolean) {
                 $_sql_criteria .= " {$_boolean} ";
             } else {
                 if ($_query['b'] == '*') {
                     $_sql_criteria .= " OR ";
                 } else {
                     $_sql_criteria .= " AND ";
                 }
             }
             $_b = $_query['b'];
             $_q = @$this->obj_db->escape_string(trim($_query['q']));
             if (in_array($_field, array('title', 'author', 'subject', 'notes'))) {
                 $_q = '+' . ($_is_phrase ? '"' . $_q . '"' : $_q);
                 if (!$_is_phrase) {
                     $_q = preg_replace('@\\s+@i', ' +', $_q);
                 }
             }
             $_boolean = '';
         }
         // for debugging purpose only
         // echo "<p>$_num. $_field -> $_boolean -> $_sql_criteria</p><p>&nbsp;</p>";
         // check fields
         switch ($_field) {
             case 'author':
                 if ($_b == '-') {
                     $_sql_criteria .= " NOT (MATCH (index.author) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 } else {
                     $_sql_criteria .= " (MATCH (index.author) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 }
                 break;
             case 'subject':
                 if ($_b == '-') {
                     $_sql_criteria .= " NOT (MATCH (index.topic) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 } else {
                     $_sql_criteria .= " (MATCH (index.topic) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 }
                 break;
             case 'location':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " NOT (MATCH (index.location) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                     } else {
                         $_sql_criteria .= " (MATCH (index.location) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                     }
                 } else {
                     if ($_b == '-') {
                         $_sql_criteria .= " index.node !='{$_q}'";
                     } else {
                         $_sql_criteria .= " index.node = '{$_q}'";
                     }
                 }
                 break;
             case 'colltype':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " NOT (MATCH (index.collection_types) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                     } else {
                         $_sql_criteria .= " MATCH (index.collection_types) AGAINST ('{$_q}' IN BOOLEAN MODE)";
                     }
                 }
                 break;
             case 'itemcode':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " NOT (MATCH (index.items) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                     } else {
                         $_sql_criteria .= " MATCH (index.items) AGAINST ('{$_q}' IN BOOLEAN MODE)";
                     }
                 }
                 break;
             case 'callnumber':
                 if ($_b == '-') {
                     $_sql_criteria .= ' biblio.call_number NOT LIKE \'' . $_q . '%\'';
                 } else {
                     $_sql_criteria .= ' index.call_number LIKE \'' . $_q . '%\'';
                 }
                 break;
             case 'itemcallnumber':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= ' item.call_number NOT LIKE \'' . $_q . '%\'';
                     } else {
                         $_sql_criteria .= ' item.call_number LIKE \'' . $_q . '%\'';
                     }
                 }
                 break;
             case 'class':
                 if ($_b == '-') {
                     $_sql_criteria .= ' index.classification NOT LIKE \'' . $_q . '%\'';
                 } else {
                     $_sql_criteria .= ' index.classification LIKE \'' . $_q . '%\'';
                 }
                 break;
             case 'isbn':
                 if ($_b == '-') {
                     $_sql_criteria .= ' index.isbn_issn NOT LIKE \'' . $_q . '%\'';
                 } else {
                     $_sql_criteria .= ' index.isbn_issn LIKE \'' . $_q . '%\'';
                 }
                 break;
             case 'publisher':
                 if ($_b == '-') {
                     $_sql_criteria .= " index.publisher!='{$_q}'";
                 } else {
                     $_sql_criteria .= " index.publisher LIKE '{$_q}%'";
                 }
                 break;
             case 'publishyear':
                 if ($_b == '-') {
                     $_sql_criteria .= ' index.publish_year!=\'' . $_q . '\'';
                 } else {
                     $_sql_criteria .= ' index.publish_year LIKE \'' . $_q . '\'';
                 }
                 break;
             case 'gmd':
                 if ($_b == '-') {
                     $_sql_criteria .= " index.gmd!='{$_q}'";
                 } else {
                     $_sql_criteria .= " index.gmd='{$_q}'";
                 }
                 break;
             case 'notes':
                 if ($_b == '-') {
                     $_sql_criteria .= " NOT (MATCH (index.notes) AGAINST ('" . $_q . "' IN BOOLEAN MODE))";
                 } else {
                     $_sql_criteria .= " (MATCH (index.notes) AGAINST ('" . $_q . "' IN BOOLEAN MODE))";
                 }
                 break;
             default:
                 if ($_b == '-') {
                     $_sql_criteria .= " NOT (MATCH (index.title, index.series_title) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 } else {
                     $_sql_criteria .= " (MATCH (index.title, index.series_title) AGAINST ('{$_q}' IN BOOLEAN MODE))";
                 }
                 break;
         }
     }
     // remove boolean's logic symbol prefix and suffix
     $_sql_criteria = preg_replace('@^(AND|OR|NOT)\\s*|\\s+(AND|OR|NOT)$@i', '', trim($_sql_criteria));
     // below for debugging purpose only
     // echo "<div style=\"border: 1px solid #f00; padding: 5px; color: #f00; margin: 5px;\">$_sql_criteria</div>";
     $this->criteria = array('sql_criteria' => $_sql_criteria, 'searched_fields' => $_searched_fields);
     return $this->criteria;
 }
 /**
  * Method to set search criteria
  *
  * @param   string  $str_criteria
  * @return  void
  */
 public function setSQLcriteria($str_criteria)
 {
     if (!$str_criteria) {
         return null;
     }
     // defaults
     $_sql_criteria = '';
     $_searched_fields = array();
     $_title_buffer = '';
     $_previous_field = '';
     $_boolean = '';
     // parse query
     $this->orig_query = $str_criteria;
     $_queries = simbio_tokenizeCQL($str_criteria, $this->searchable_fields, $this->stop_words, $this->queries_word_num_allowed);
     // echo '<pre>'; var_dump($_queries); echo '</pre>';
     if (count($_queries) < 1) {
         return null;
     }
     // loop each query
     foreach ($_queries as $_num => $_query) {
         // field
         $_field = $_query['f'];
         // boolean
         if ($_title_buffer == '' && $_field != 'boolean') {
             $_sql_criteria .= " {$_boolean} ";
         }
         //  break the loop if we meet `cql_end` field
         if ($_field == 'cql_end') {
             break;
         }
         // boolean mode
         $_b = isset($_query['b']) ? $_query['b'] : $_query;
         if ($_b == '*') {
             $_boolean = 'OR';
         } else {
             $_boolean = 'AND';
         }
         // search value
         $_q = @$this->obj_db->escape_string($_query['q']);
         // searched fields flag set
         $_searched_fields[$_field] = 1;
         $_previous_field = $_field;
         switch ($_field) {
             case 'location':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " biblio.location NOT LIKE '%{$_q}%'";
                     } else {
                         $_sql_criteria .= " biblio.location LIKE '%{$_q}%'";
                     }
                 }
                 break;
             case 'colltype':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " biblio.collection_types NOT LIKE '%{$_q}%'";
                     } else {
                         $_sql_criteria .= " biblio.collection_types NOT LIKE ({$_subquery})";
                     }
                 }
                 break;
             case 'itemcode':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= " biblio.items NOT LIKE '%{$_q}%'";
                     } else {
                         $_sql_criteria .= " biblio.items LIKE '%{$_q}%'";
                     }
                 }
                 break;
             case 'callnumber':
                 if ($_b == '-') {
                     $_sql_criteria .= ' biblio.call_number NOT LIKE \'' . $_q . '%\'';
                 } else {
                     $_sql_criteria .= ' biblio.call_number LIKE \'' . $_q . '%\'';
                 }
                 break;
             case 'itemcallnumber':
                 if (!$this->disable_item_data) {
                     if ($_b == '-') {
                         $_sql_criteria .= ' item.call_number NOT LIKE \'' . $_q . '%\'';
                     } else {
                         $_sql_criteria .= ' item.call_number LIKE \'' . $_q . '%\'';
                     }
                 }
                 break;
             case 'class':
                 if ($_b == '-') {
                     $_sql_criteria .= ' biblio.classification NOT LIKE \'' . $_q . '%\'';
                 } else {
                     $_sql_criteria .= ' biblio.classification LIKE \'' . $_q . '%\'';
                 }
                 break;
             case 'isbn':
                 if ($_b == '-') {
                     $_sql_criteria .= ' biblio.isbn_issn!=\'' . $_q . '\'';
                 } else {
                     $_sql_criteria .= ' biblio.isbn_issn=\'' . $_q . '\'';
                 }
                 break;
             case 'publisher':
                 $_subquery = 'SELECT publisher_id FROM mst_publisher WHERE publisher_name LIKE \'%' . $_q . '%\'';
                 if ($_b == '-') {
                     $_sql_criteria .= " biblio.publisher_id NOT IN ({$_subquery})";
                 } else {
                     $_sql_criteria .= " biblio.publisher_id IN ({$_subquery})";
                 }
                 break;
             case 'publishyear':
                 if ($_b == '-') {
                     $_sql_criteria .= ' biblio.publish_year!=\'' . $_q . '\'';
                 } else {
                     $_sql_criteria .= ' biblio.publish_year=\'' . $_q . '\'';
                 }
                 break;
             case 'gmd':
                 $_subquery = 'SELECT gmd_id FROM mst_gmd WHERE gmd_name=\'' . $_q . '\'';
                 if ($_b == '-') {
                     $_sql_criteria .= " biblio.gmd_id NOT IN ({$_subquery})";
                 } else {
                     $_sql_criteria .= " biblio.gmd_id IN ({$_subquery})";
                 }
                 break;
             case 'notes':
                 $_q = isset($_query['is_phrase']) ? '"' . $_q . '"' : $_q;
                 if ($_b == '-') {
                     $_sql_criteria .= " NOT (MATCH (biblio.notes) AGAINST ('" . $_q . "' IN BOOLEAN MODE))";
                 } else {
                     $_sql_criteria .= " (MATCH (biblio.notes) AGAINST ('" . $_q . "' IN BOOLEAN MODE))";
                 }
                 break;
         }
     }
     // remove boolean's logic symbol prefix and suffix
     $_sql_criteria = preg_replace('@^(AND|OR|NOT)\\s*|\\s+(AND|OR|NOT)$@i', '', trim($_sql_criteria));
     // below for debugging purpose only
     // echo "<div style=\"border: 1px solid #f00; padding: 5px; color: #f00; margin: 5px;\">$_sql_criteria</div>";
     $this->criteria = array('sql_criteria' => $_sql_criteria, 'searched_fields' => $_searched_fields);
     return $this->criteria;
 }