function run_session_search($task, $args) { ini_set("memory_limit", "8192M"); ini_set("display_errors", 1); define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', true); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); //sfConfig::set('sf_cache_objects', false); //sfConfig::set('sf_cache_relations', false); //sfConfig::set('sf_use_relations_cache', false); //get all serch templates $c = new Criteria(); $searcheTemplates = SearchPeer::doSelect($c); //$searcheTemplates = array($st); $fields = array('Label', 'ApplicationNumber', 'RegisterNumber', 'RegistrationDate', 'ApplicationDate', 'ExpiresOn', 'ViennaClasses', 'NiceClasses', 'RightsOwner', 'RightsRepresentative', 'OfficeOfOrigin', 'DesignatedContractingParty'); $c = new Criteria(); //$c->add(ImportSessionPeer::CREATED_AT, "2014-11-03", Criteria::GREATER_EQUAL ); $importSessions = ImportSessionPeer::doSelect($c); /*if($args[0] == "-d") { foreach ($importSessions as $importSession) { $res = Document::getChildrenOf($importSession->getId(), "SearchMatch"); foreach ($res as $r) { $r->delete(); echo "."; } } exit(); }*/ $ind = 0; foreach ($importSessions as $importSession) { $found = false; if ($importSession->getTmCount() == 0) { continue; } $searchMatches = Document::getChildrenOf($importSession->getId(), "SearchMatch", false); //if($importSession->getId() == 552172) continue; if (count($searchMatches) > 0) { continue; } echo ">>> searching session: " . $importSession->getId() . "\n"; try { $sti = 1; foreach ($searcheTemplates as $searcheTemplate) { $searchOf = array(); foreach ($fields as $field) { $getter = "get" . $field; $param = $searcheTemplate->{$getter}(); if ($param) { $param = str_replace(array('+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', ':', '\\', '.', '/'), array('\\+', '\\-', '\\&&', '\\||', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\"', '\\~', '\\:', '\\\\', '\\.', '\\/'), $param); $searchOf[$field] = trim($param); } } /////////////////////// QUERY BUILDING ////////////////////////// $q = new Zend_Search_Lucene_Search_Query_Boolean(); $queryTerms = explode(" ", strtolower($query)); $i = 0; $query = ""; foreach ($searchOf as $field => $term) { if ($i > 0) { $query .= ' AND '; } if ($field == "NiceClasses" || $field == "ViennaClasses") { $query .= '('; $parts = explode(",", $term); foreach ($parts as $el) { for ($e = 1; $e < 15; $e++) { $query .= $field . $e . ':"' . trim($el) . '" OR '; } } $query = substr($query, 0, -4) . ')'; } elseif ($field == "ApplicationNumber" || $field == "RegisterNumber") { $query .= $field . ':'; $query .= trim($term); } else { $query .= $field . ':'; if (strpos($term, "*") !== false || strpos($term, "?") !== false) { $query .= trim(UtilsHelper::cyrillicConvert($term)); } else { $query .= trim(UtilsHelper::cyrillicConvert($term)) . '~0.7'; } } $i++; } $q = Zend_Search_Lucene_Search_QueryParser::parse($query); //////////////////////// SEARCH EXECUTION //////////////////// echo " | " . $sti . " > " . $searcheTemplate->getId(); $searchIndex = Zend_Search_Lucene::open(sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'search/' . $importSession->getId() . "/"); $searchResults = $searchIndex->find($q); $brandId = Document::getParentOf($searcheTemplate->getId(), "Brand", false); foreach ($searchResults as $searchResult) { if ($foundEls[$searchResult->did] == $brandId) { continue; } $foundEls[$searchResult->did] = $brandId; $found = true; $sm = new SearchMatch(); $sm->setLabel("Match"); $sm->setImportSession($importSession->getId()); $sm->setSearch($searcheTemplate->getId()); $sm->setTrademark($searchResult->did); $sm->save(null, $importSession); } $sti++; } if ($found) { UtilsHelper::sendEmail(UtilsHelper::Settings('main_email'), "Matches have been found, click below to see them <br> <a href='http://www.tm-smart.com/import-session-report.html?is=" . $importSession->getId() . "'>http://www.tm-smart.com/import-session-report.html?is=" . $importSession->getId() . "</a>", "TM Smart - Matches foud"); $ind++; } else { // UtilsHelper::sendEmail(UtilsHelper::Settings('main_email'), "No matches have been found", "TM Smart - No matches foud"); } } catch (Exception $e) { echo ">>>>>>>>>> Error on Session " . $importSession->getId() . "\n" . $e->getMessage(); continue; //echo_cms_error("ERROR: ".$e->getMessage()); } if ($ind > 10) { break; } } //sfConfig::set('sf_cache_objects', true); //sfConfig::set('sf_cache_relations', true); //sfConfig::set('sf_use_relations_cache', true); }
function run_index_documents($task, $args) { try { define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'backend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; ini_set("memory_limit", "2048M"); ini_set("display_errors", 1); $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $search_config_file = SF_ROOT_DIR . '/config/search.xml'; $documents = simplexml_load_file($search_config_file); $all = 0; $search_index_path = SF_ROOT_DIR . '/cache/search/'; if (is_dir($search_index_path)) { $index_files = glob($search_index_path . '/*'); foreach ($index_files as $index_file) { if (is_file($index_file)) { unlink($index_file); } } } $search_index = Zend_Search_Lucene::create($search_index_path); $search_index->setMaxBufferedDocs(20000); Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()); $ndoc = 0; foreach ($documents as $document) { $document_name = $document->attributes(); if (array_key_exists(0, $args) && $document_name != $args[0]) { continue; } echo "Indexing " . $document_name . "\n"; $classPeer = $document_name . 'Peer'; $c = new Criteria(); $document_instances = call_user_func(array($classPeer, 'doSelect'), $c); foreach ($document_instances as $document_instance) { $common_field_val = ""; $id = $document_instance->getId(); $search_doc = new Zend_Search_Lucene_Document(); $date = $document_instance->getCreatedAt(); $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('did', $id, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('ddate', $date, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dtype', $document_name, 'utf-8')); $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed('dstatus', $document_instance->getPublicationStatus(), 'utf-8')); foreach ($document as $field_name) { $attr = get_object_vars($field_name); $attributes = $attr['@attributes']; $getFunction = 'get' . $attributes['name']; $fieldContent = ""; $fieldContent = $document_instance->{$getFunction}(); if ($attributes['name'] == "Label" and substr($fieldContent, 0, 8) == "no label") { $fieldContent = ""; } if ($attributes['name'] == "ViennaClasses" || $attributes['name'] == "NiceClasses") { $parts = explode(",", $fieldContent); $nbr = count($parts); //echo "============>".$nbr."\n"; $search_doc->addField(Zend_Search_Lucene_Field::UnIndexed($attributes['name'] . "_cnt", $nbr, 'utf-8')); //$e = 1; for ($e = 0; $e < 15; $e++) { if (empty($parts[$e])) { $parts[$e] = "---"; } $search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'] . $e, trim($parts[$e]), 'utf-8')); $e++; } } elseif ($attributes['name'] == "ApplicationNumber" || $attributes['name'] == "RegisterNumber") { $search_doc->addField(Zend_Search_Lucene_Field::keyword($attributes['name'], $fieldContent, 'utf-8')); } else { $search_doc->addField(Zend_Search_Lucene_Field::text($attributes['name'], UtilsHelper::cyrillicConvert($fieldContent), 'utf-8')); } } $search_index->addDocument($search_doc); $ndoc++; echo $ndoc . "\t\t\r"; } } echo echo_cms_line(" " . $ndoc . " documents indexed\n"); $search_index->commit(); $search_index->optimize(); } catch (Exception $e) { echo_cms_error("ERROR ADD_DOCUMENT : " . $e->getMessage()); } echo echo_cms_sep(); exit; }
public function executeWebSearch() { $this->setLayout(false); $request = $this->getRequest(); $params = $request->getParameterHolder()->getAll(); if ($this->getRequestParameter('submitted') == "submitted") { try { $searchOf = array(); foreach ($params as $key => $param) { $parts = explode("-", $key); if ($parts[0] == "field" && !empty($param)) { $param = str_replace(array('+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', ':', '\\', '.', '/'), array('\\+', '\\-', '\\&&', '\\||', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\"', '\\~', '\\:', '\\\\', '\\.', '\\/'), $param); $searchOf[$parts[1]] = trim($param); } } $this->searchOf = $searchOf; /////////////////////// QUERY BUILDING ////////////////////////// $q = new Zend_Search_Lucene_Search_Query_Boolean(); $queryTerms = explode(" ", strtolower($query)); $i = 0; $query = ""; foreach ($searchOf as $field => $term) { if ($i > 0) { $query .= ' AND '; } if ($field == "NiceClasses" || $field == "ViennaClasses") { $query .= '('; $parts = explode(",", $term); foreach ($parts as $el) { for ($e = 1; $e < 15; $e++) { $query .= $field . $e . ':"' . trim($el) . '" OR '; } } $query = substr($query, 0, -4) . ')'; } elseif ($field == "ApplicationNumber" || $field == "RegisterNumber") { $query .= $field . ':'; $query .= trim($term); } else { $query .= $field . ':'; if (strpos($term, "*") !== false || strpos($term, "?") !== false) { $query .= trim(UtilsHelper::cyrillicConvert($term)); } else { $query .= trim(UtilsHelper::cyrillicConvert($term)) . '~0.7'; } } $i++; } //echo "QUERY: ".$query; $q = Zend_Search_Lucene_Search_QueryParser::parse($query); //////////////////////// SEARCH EXECUTION //////////////////// $searchIndex = Zend_Search_Lucene::open(sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'search/'); //Zend_Search_Lucene::setResultSetLimit(100); $searchResults = $searchIndex->find($q); //var_dump(get_class_methods($searchResults)); //exit(); //$this->count = count($searchResults); //$this->results = $searchResults; $this->pager = UtilsHelper::pager("Trademark", $searchResults, 1000); $this->count = $this->pager->getNbResults(); $this->paging = $this->pager->paging(); if ($this->count) { return "Results"; } else { UtilsHelper::setFlashMsg("Няма намерени резултати", UtilsHelper::MSG_SUCCESS); } } catch (Exception $e) { $this->error = $e->getMessage(); UtilsHelper::setFlashMsg($e->getMessage(), UtilsHelper::MSG_ERROR); } } $this->countries = $arr = array("BG" => "БЪЛГАРИЯ", "AF" => "AFGHANISTAN", "OA" => "AFRICAN INTELLECTUAL PROPERTY ORGANIZATION (OAPI)", "AP" => "AFRICAN REGIONAL INDUSTRIAL PROPERTY ORGANIZATION (ARIPO)", "AL" => "ALBANIA", "DZ" => "ALGERIA", "AS" => "AMERICAN SAMOA", "AD" => "ANDORRA", "AO" => "ANGOLA", "AI" => "ANGUILLA", "AQ" => "ANTARCTICA", "AG" => "ANTIGUA AND BARBUDA", "AR" => "ARGENTINA", "AM" => "ARMENIA", "AW" => "ARUBA", "AU" => "AUSTRALIA", "AT" => "AUSTRIA", "AZ" => "AZERBAIJAN", "BS" => "BAHAMAS", "BH" => "BAHRAIN", "BD" => "BANGLADESH", "BB" => "BARBADOS", "BY" => "BELARUS", "BE" => "BELGIUM", "BZ" => "BELIZE", "BX" => "BENELUX", "BJ" => "BENIN", "BM" => "BERMUDA", "BT" => "BHUTAN", "BO" => "BOLIVIA", "BA" => "BOSNIA AND HERZEGOVINA", "BW" => "BOTSWANA", "BV" => "BOUVET ISLAND", "BR" => "BRAZIL", "BN" => "BRUNEI DARUSSALAM", "BF" => "BURKINA FASO", "BI" => "BURUNDI", "KH" => "CAMBODIA", "CM" => "CAMEROON", "CA" => "CANADA", "CV" => "CAPE VERDE", "KY" => "CAYMAN ISLANDS", "CF" => "CENTRAL AFRICAN REPUBLIC", "TD" => "CHAD", "CS" => "Channel Islands", "CL" => "CHILE", "CN" => "CHINA", "CX" => "CHRISTMAS,INSULE", "CC" => "COCOS,INSULE", "CO" => "COLOMBIA", "KM" => "COMOROS", "CG" => "CONGO", "CK" => "COOK ISLANDS", "CR" => "COSTA RICA", "CI" => "COTE D'IVOIRE", "HR" => "CROATIA", "CU" => "CUBA", "CW" => "CURACAO", "CY" => "CYPRUS", "CZ" => "CZECH REPUBLIC", "KP" => "DEMOCRATIC PEOPLE'S REPUBLIC OF KOREA", "DK" => "DENMARK", "DJ" => "DJIBOUTI", "DM" => "DOMINICA", "DO" => "DOMINICAN REPUBLIC", "TP" => "EAST TIMOR", "EC" => "ECUADOR", "EG" => "EGYPT", "SV" => "EL SALVADOR", "GQ" => "EQUATORIAL GUINEA", "ER" => "ERITREA", "EE" => "ESTONIA", "ET" => "ETHIOPIA", "EA" => "EURASIAN PATENT ORGANIZATION (EAPO)", "EP" => "EUROPEAN PATENT OFFICE (EPO)", "FK" => "FALKLAND ISLANDS (MALVINAS)", "FO" => "FAROE ISLANDS", "FJ" => "FIJI", "FI" => "FINLAND", "FR" => "FRANCE", "GA" => "GABON", "GM" => "GAMBIA", "GE" => "GEORGIA", "DE" => "GERMANY", "GH" => "GHANA", "GI" => "GIBRALTAR", "GR" => "GREECE", "GL" => "GREENLAND", "GD" => "GRENADA", "GP" => "GUADELUPA", "GU" => "GUAM", "GT" => "GUATEMALA", "GN" => "GUINEA", "GW" => "GUINEA-BISSAU", "GY" => "GUYANA", "GF" => "GUYANA FRANCEZA", "HT" => "HAITI", "VA" => "HOLY SEE", "HN" => "HONDURAS", "HK" => "HONG KONG", "HU" => "HUNGARY", "IS" => "ICELAND", "IN" => "INDIA", "ID" => "INDONESIA", "UM" => "INSULELE MINORE INDEPARTATE ALE STATELOR UNITE", "IB" => "INTERNATIONAL BUREAU OF THE WORLD INTELLECTUAL PROPERTY ORGANIZATION (WIPO)", "IR" => "IRAN (ISLAMIC REPUBLIC OF)", "IQ" => "IRAQ", "IE" => "IRELAND", "IM" => "ISLE OF MAN", "IL" => "ISRAEL", "IT" => "ITALY", "JM" => "JAMAICA", "JP" => "JAPAN", "JO" => "JORDAN", "KZ" => "KAZAKSTAN", "KE" => "KENYA", "KI" => "KIRIBATI", "KW" => "KUWAIT", "KG" => "KYRGYZSTAN", "LA" => "LAOS", "LV" => "LATVIA", "LB" => "LEBANON", "LS" => "LESOTHO", "LR" => "LIBERIA", "LY" => "LIBYA", "LI" => "LIECHTENSTEIN", "LT" => "LITHUANIA", "LU" => "LUXEMBOURG", "MO" => "MACAU", "MG" => "MADAGASCAR", "MW" => "MALAWI", "MY" => "MALAYSIA", "MV" => "MALDIVES", "ML" => "MALI", "MT" => "MALTA", "MH" => "MARCHALL ISLANDS", "MQ" => "MARTINICA", "MR" => "MAURITANIA", "MU" => "MAURITIUS", "MX" => "MEXICO", "FM" => "MICRONESIA (FEDERATED STATES OF)", "MC" => "MONACO", "MN" => "MONGOLIA", "ME" => "MONTENEGRO", "MS" => "MONTSERRAT", "MA" => "MOROCCO", "MZ" => "MOZAMBIQUE", "MM" => "MYANMAR", "NA" => "NAMIBIA", "NR" => "NAURU", "NP" => "NEPAL", "NL" => "NETHERLANDS", "AN" => "NETHERLANDS ANTILLES", "NZ" => "NEW ZEALAND", "NI" => "NICARAGUA", "NE" => "NIGER", "NG" => "NIGERIA", "NU" => "NIOUE", "NF" => "NORFOLK,INSULE", "MP" => "NORTHERN MARIANA ISLANDS", "NO" => "NORWAY", "NC" => "NOUA CALEDONIE", "EM" => "OFFICE FOR HARMONIZATION IN THE INTERNAL MARKET (TRADEMARKS AND DESIGNS)", "OM" => "OMAN", "PK" => "PAKISTAN", "PW" => "PALAU", "PA" => "PANAMA", "PG" => "PAPUA NEW GUINEA", "PY" => "PARAGUAY", "PE" => "PERU", "PH" => "PHILIPPINES", "PN" => "PITCAIRN", "PL" => "POLAND", "PF" => "POLINEZIA FRANCEZA", "PT" => "PORTUGAL", "PR" => "PUERTO RICO", "QA" => "QATAR", "KR" => "REPUBLIC OF KOREA", "MD" => "REPUBLIC OF MOLDOVA", "RE" => "REUNION", "RO" => "ROMANIA", "RU" => "RUSSIAN FEDERATION", "RW" => "RWANDA", "SH" => "SAINT HELENA", "KN" => "SAINT KITTS AND NEVIS", "LC" => "SAINT LUCIA", "VC" => "SAINT VINCENT AND THE GRENADINES", "WS" => "SAMOA", "SM" => "SAN MARINO", "ST" => "SAO TOME AND PRINCIPE", "SA" => "SAUDI ARABIA", "SN" => "SENEGAL", "RS" => "SERBIA", "SC" => "SEYCHELLES", "PM" => "SF.PETRE SI MIQUELON", "SL" => "SIERRA LEONE", "SG" => "SINGAPORE", "SK" => "SLOVAKIA", "SI" => "SLOVENIA", "SB" => "SOLOMON ISLANDS", "SO" => "SOMALIA", "ZA" => "SOUTH AFRICA", "GS" => "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS", "ES" => "SPAIN", "LK" => "SRI LANKA", "SD" => "SUDAN", "SR" => "SURINAME", "SJ" => "SVALBARD SI INSULA JAN MAYEN", "SZ" => "SWAZILAND", "SE" => "SWEDEN", "CH" => "SWITZERLAND", "SY" => "SYRIA", "TW" => "TAIWAN, PROVINCE OF CHINA", "TJ" => "TAJIKISTAN", "TF" => "TERITORIILE AUSTRALE FRANCEZE", "TH" => "THAILAND", "MK" => "THE FORMER YUGOSLAV REPUBLIC OF MACEDONIA", "TG" => "TOGO", "TK" => "TOKELAU", "TO" => "TONGA", "TT" => "TRINIDAD AND TOBAGO", "TN" => "TUNISIA", "TR" => "TURKEY", "TM" => "TURKMENISTAN", "TC" => "TURKS AND CAICOS ISLANDS", "TV" => "TUVALU", "UG" => "UGANDA", "UA" => "UKRAINE", "AE" => "UNITED ARAB EMIRATES", "GB" => "UNITED KINGDOM", "TZ" => "UNITED REPUBLIC OF TANZANIA", "US" => "UNITED STATES OF AMERICA", "UY" => "URUGUAY", "UZ" => "UZBEKISTAN", "VU" => "VANUATU", "VE" => "VENEZUELA", "VN" => "VIET NAM", "VG" => "VIRGIN ISLANDS (BRITISH)", "VI" => "VIRGIN ISLANDS OF THE UNITED STATES", "WF" => "WALLIS SI FUTUNA,INSULE", "EH" => "WESTERN SAHARA", "WO" => "WIPO", "YE" => "YEMEN", "YU" => "YUGOSLAVIA", "ZR" => "ZAIRE", "ZM" => "ZAMBIA", "ZW" => "ZIMBABWE", "NT" => "ZONA NEUTRA"); }