示例#1
0
 public function addFilter($object, $attribute, $value)
 {
     if (strlen($value) > 0) {
         $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter();
         $code = $attribute->getAttributeCode();
         $items = $typeConverter->getItems();
         $field = $items[$attribute->getFrontend()->getInputType()]['solr_index_prefix'] . $typeConverter::SUBPREFIX_INDEX . $attribute->getAttributeCode();
         if (is_array($value) && (isset($value['from']) || isset($value['to']))) {
             if (isset($value['from']) && !empty($value['from'])) {
                 $from = $value['from'];
             } else {
                 $from = '*';
             }
             if (isset($value['to']) && !empty($value['to'])) {
                 $to = $value['to'];
             } else {
                 $to = '*';
             }
             $select->where($field . ':[' . $from . ' TO ' . $to . ']');
             return true;
         } else {
             if (is_array($value)) {
                 $value = implode(' ', $value);
             } else {
                 $value = Apache_Solr_Service::escape($value);
                 $value = $this->addFuzzySearch($value);
             }
         }
         $object->getProductCollection()->getSelect()->where($field . ':' . $value);
         return true;
     }
     return false;
 }
 /**
  * Escape all special characters in a query string
  *
  * @access	public
  *
  * @param	string		$query: The query string
  *
  * @return	string		The escaped query string
  */
 public static function escapeQuery($query)
 {
     // Load class.
     if (!class_exists('Apache_Solr_Service')) {
         require_once t3lib_div::getFileAbsFileName('EXT:' . self::$extKey . '/lib/SolrPhpClient/Apache/Solr/Service.php');
     }
     // Escape query phrase or term.
     if (preg_match('/^".*"$/', $query)) {
         return '"' . Apache_Solr_Service::escapePhrase(trim($query, '"')) . '"';
     } else {
         return Apache_Solr_Service::escape($query);
     }
 }
 /**
  * Escape a value for special query characters such as ':', '(', ')', '*',
  * '?', etc.
  *
  * NOTE: inside a phrase fewer characters need escaped, use {@link
  * Apache_Solr_Service::escapePhrase()} instead
  *
  * @param string $value            
  * @return string
  */
 public static function escape($value)
 {
     return parent::escape($value);
 }
示例#4
0
 /**
  * Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
  *
  * NOTE: inside a phrase fewer characters need escaped, use {@link Apache_Solr_Service::escapePhrase()} instead
  *
  * @param string $value
  * @return string
  */
 public static function escape($value)
 {
     return Apache_Solr_Service::escape($value);
 }
示例#5
0
 /**
  * Add search query filter
  *
  * @param   Mage_CatalogSearch_Model_Query $query
  * @return  Mage_CatalogSearch_Model_Mysql4_Search_Collection
  */
 public function addSearchFilter($query = NULL)
 {
     if (is_null($query)) {
         $query = Mage::helper('solr')->getQuery();
     }
     $where = '';
     $query = Apache_Solr_Service::escape($query);
     //$query = $this->addFuzzySearch($query);
     $where = 'attr_t_search_content_heading:' . $query . '*';
     $where .= ' OR attr_t_search_content:' . $query . '*';
     $where .= ' OR attr_t_search_title:' . $query . '*';
     $this->getSelect()->where($where);
     return $this;
 }
 /**
  * Add search query filter
  *
  * @param   Mage_CatalogSearch_Model_Query $query
  * @return  Mage_CatalogSearch_Model_Mysql4_Search_Collection
  */
 public function addSearchFilter($query = NULL)
 {
     if (is_null($query)) {
         $query = Mage::helper('solr')->getQuery();
     }
     $where = '';
     $query = Apache_Solr_Service::escape($query);
     $query = $this->addFuzzySearch($query);
     foreach ($this->_searchableAttributes as $attribute) {
         $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter($attribute->getFrontend()->getInputType());
         if (isset($typeConverter->solr_search) && $typeConverter->solr_search) {
             $code = $attribute->getAttributeCode();
             $field = $typeConverter->solr_search_prefix . DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter::SUBPREFIX_SEARCH . $attribute->getAttributeCode();
             $where = strlen($where) ? $where . ' OR ' . $field . ':' . $query : $field . ':' . $query;
         }
     }
     $this->getSelect()->where($where);
     return $this;
 }
示例#7
0
 public function facetprofileAction()
 {
     $request = $this->getRequest();
     $q = $wq = $request->getParam('q');
     $category = $request->getParam('category');
     $clinic_selected = $request->getParam('clinic_selected');
     $putusanselected = $request->getParam('putusanSelected');
     if ($q) {
         if (!preg_match("/(id:|shortTitle:|profile:|publishedDate:|expiredDate:|createdDate:|modifiedDate:|createdBy:|modifiedBy:|status:|author:|fixedDate:|regulationType:|regulationOrder:|kategori:|kategoriklinik:|kontributor:|sumber:|year:|number:|title:)/i", $q)) {
             require_once 'Apache/Solr/Service.php';
             $q = Apache_Solr_Service::escape($q);
         }
         $query = $q;
     } else {
         $query = "";
     }
     $query = str_replace('\\', '', $query);
     $indexingEngine = Pandamp_Search::manager();
     $hits = $indexingEngine->find($query, 0, 1);
     if (isset($hits->response->docs[0])) {
         $content = 0;
         $data = array();
         foreach ($hits->facet_counts->facet_fields->profile as $facet => $count) {
             if ($count == 0 || in_array($facet, array('comment', 'partner', 'kategoriklinik', 'kutu_signup'))) {
                 continue;
             } else {
                 $f = str_replace(array('kutu_'), "", $facet);
                 $f = str_replace("peraturan_kolonial", "peraturan kolonial", $f);
                 $f = str_replace("rancangan_peraturan", "rancangan peraturan", $f);
                 $f = str_replace("about_us", "tentang kami", $f);
                 $f = str_replace("kotik", "kode etik jurnalis", $f);
                 $f = str_replace("kategoriklinik", "kategori klinik", $f);
                 $f = str_replace("mitra", "mitra hukumonline", $f);
                 $f = str_replace("partner", "mitra klinik", $f);
                 $f = str_replace("author", "penjawab klinik", $f);
                 //$f = str_replace("article","artikel",$f);
                 $f = str_replace("comment", "komentar", $f);
                 $f = str_replace("doc", "pelengkap", $f);
                 $f = str_replace("signup", "pendaftaran", $f);
                 $f = str_replace("financial_services", "financial services", $f);
                 $f = str_replace("general_corporate", "general corporate", $f);
                 $f = str_replace("oil_and_gas", "oil and gas", $f);
                 $f = str_replace("executive_alert", "executive alert", $f);
                 $f = str_replace("manufacturing_&_industry", "manufacturing & industry", $f);
                 $f = str_replace("consumer_goods", "consumer goods", $f);
                 $f = str_replace("telecommunications_and_media", "telecommunications and media", $f);
                 $f = str_replace("executive_summary", "executive summary", $f);
                 $f = str_replace("hot_news", "hot news", $f);
                 $f = str_replace("hot_issue_ile", "hot issue ILE", $f);
                 $f = str_replace("hot_issue_ild", "hot issue ILD", $f);
                 $f = str_replace("hot_issue_ilb", "hot issue ILB", $f);
                 $data[$content]['facet'] = $f;
                 $data[$content]['profile'] = $facet;
                 $data[$content]['count'] = $count;
             }
             $content++;
         }
         $this->view->assign('aData', $data);
         $this->view->assign('category', $category);
         $this->view->assign('clinic_selected', $clinic_selected);
         $this->view->assign('putusanSelected', $putusanselected);
         $this->view->assign('query', urlencode($wq));
     }
 }
<?php

require dirname(__FILE__) . '/../../bootstrap/unit.php';
$t = new limeade_test(3, limeade_output::get());
$val = "this is my+ es\\caped ?*string";
$escaped = Apache_Solr_Service::escape($val);
$expected = 'this is my\\+ es\\\\caped \\?\\*string';
$t->cmp_ok($escaped, '===', $expected, "::escape  ok");
$val = "this is \"my escaped\" phrase";
$escaped = Apache_Solr_Service::escapePhrase($val);
$expected = 'this is \\"my escaped\\" phrase';
$t->cmp_ok($escaped, '===', $expected, "::escapePhrase  ok");
$escaped = Apache_Solr_Service::phrase($val);
$expected = '"this is \\"my escaped\\" phrase"';
$t->cmp_ok($escaped, '===', $expected, "::phrase  ok");
 /**
  * Quote and escape search strings
  *
  * @param	string	the search string
  * @return	string	the escaped/quoted string
  */
 public function escape($string)
 {
     if (!is_numeric($string)) {
         if (preg_match('/\\W/', $string) == 1) {
             // multiple words
             $stringLength = strlen($string);
             if ($string[0] == '"' && $string[$stringLength - 1] == '"') {
                 // phrase
                 $string = trim($string, '"');
                 $string = Apache_Solr_Service::phrase($string);
             } else {
                 $string = Apache_Solr_Service::escape($string);
             }
         } else {
             $string = Apache_Solr_Service::escape($string);
         }
     }
     return $string;
 }