예제 #1
0
 /**
  * Whether this search term has an operator of type MCL_OPERATOR_FILTER
  */
 public function isFilter()
 {
     if (!$this->search_operator) {
         return false;
     }
     $cstf = new ConceptSearchTermFactory();
     return $cstf->isFilterOperator($this->search_operator);
 }
예제 #2
0
 /**
  * Parses the search group into ConceptSearchTermCollection 
  * and ConceptSearchTerm objects. Returns true if the query contains
  * one or more search terms; false otherwise.
  */
 public function parse($q)
 {
     $this->query = $q;
     if (!$q) {
         return false;
     }
     /*
      * Split into search terms. There are 5 types of terms currently supported:
      *		text_or_integer
      *		operator:text_or_integer
      *		"text in, quotes with separators"
      *		operator:"text in, quotes with separators"
      * Terms can be split by whitespace or commas. Quotes may be single or double.
      *
      * TODO: Support for functions or lists. e.g. fxn_name(fxn_param)
      */
     $regexp = '~(?:(?:([\\w-]+):)?)(?:(?:"([^\\v"]*)")|(?:\'([^\\v\']*)\')|([\\w.-]+|\\*))(?=\\s|,|$)~';
     $arr_matches = array();
     $result = preg_match_all($regexp, $q, $arr_matches);
     // Create ConceptSearchTermCollection objects
     $this->cstc_top = new ConceptSearchTermCollection();
     // top-level OR cstc
     $this->cstc_top->glue = MCL_CONCEPT_SEARCH_GLUE_OR;
     $cstc_and = new ConceptSearchTermCollection();
     // child AND cstc for text searches
     $cstc_and->glue = MCL_CONCEPT_SEARCH_GLUE_AND;
     /**
      * Create search terms and add to appropriate CSTC.
      * Top-level CSTC has 'OR' glue and has one-child 'AND' CSTC for
      * text/name/desc search terms.
      */
     $cstf = new ConceptSearchTermFactory();
     $num_search_terms_created = 0;
     foreach ($arr_matches[0] as $str_search_term) {
         $arr_cst = $cstf->parse($str_search_term);
         foreach (array_keys($arr_cst) as $i) {
             $num_search_terms_created++;
             if ($arr_cst[$i]->term_type == MCL_SEARCH_TERM_TYPE_TEXT || $arr_cst[$i]->term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_NAME || $arr_cst[$i]->term_type == MCL_SEARCH_TERM_TYPE_CONCEPT_DESCRIPTION) {
                 $cstc_and->addSearchTerm($arr_cst[$i]);
             } else {
                 $this->cstc_top->addSearchTerm($arr_cst[$i]);
             }
         }
     }
     if ($cstc_and->Count()) {
         $this->cstc_top->addSearchTermCollection($cstc_and);
     }
     return (bool) count($num_search_terms_created);
 }