Example #1
0
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);
}
Example #2
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = SearchPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setLabel($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setApplicationNumber($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setRegisterNumber($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setRegistrationDate($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setApplicationDate($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setExpiresOn($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setViennaClasses($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setNiceClasses($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setRightsOwner($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setRightsRepresentative($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setOfficeOfOrigin($arr[$keys[11]]);
     }
     if (array_key_exists($keys[12], $arr)) {
         $this->setDesignatedContractingParty($arr[$keys[12]]);
     }
     if (array_key_exists($keys[13], $arr)) {
         $this->setCreatedAt($arr[$keys[13]]);
     }
     if (array_key_exists($keys[14], $arr)) {
         $this->setUpdatedAt($arr[$keys[14]]);
     }
     if (array_key_exists($keys[15], $arr)) {
         $this->setPublicationStatus($arr[$keys[15]]);
     }
 }
Example #3
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(SearchPeer::ID, $pks, Criteria::IN);
         $objs = SearchPeer::doSelect($criteria, $con);
     }
     return $objs;
 }