public static function countUnassociated() { // There are three disjoint types of definitions: // (1) deleted -- these are never associated with lexems // (2) not deleted, associated // (3) not deleted, not associated // We compute (3) as (all definitions) - (1) - (2). $all = Model::factory('Definition')->count(); $deleted = Model::factory('Definition')->where('status', self::ST_DELETED)->count(); $associated = db_getSingleValue('select count(distinct definitionId) from LexemDefinitionMap'); return $all - $deleted - $associated; }
public static function countUnassociated() { // We compute this as (all lexems) - (lexems showing up in LexemDefinitionMap) $all = Model::factory('Lexem')->count(); $associated = db_getSingleValue('select count(distinct lexemId) from LexemDefinitionMap'); return $all - $associated; }
public static function countRegexpMatches($regexp, $hasDiacritics, $sourceId, $useMemcache) { if ($useMemcache) { $key = "regexpCount_" . ($hasDiacritics ? '1' : '0') . "_" . ($sourceId ? $sourceId : 0) . "_{$regexp}"; $result = mc_get($key); if ($result) { return $result; } } $mysqlRegexp = StringUtil::dexRegexpToMysqlRegexp($regexp); $field = $hasDiacritics ? 'formNoAccent' : 'formUtf8General'; $result = $sourceId ? db_getSingleValue("select count(distinct L.id) from Lexem L join LexemDefinitionMap on L.id = lexemId join Definition D on definitionId = D.id " . "where {$field} {$mysqlRegexp} and sourceId = {$sourceId} order by formNoAccent") : Model::factory('Lexem')->where_raw("{$field} {$mysqlRegexp}")->count(); if ($useMemcache) { mc_set($key, $result); } return $result; }
<?php require_once "../phplib/util.php"; util_assertModerator(PRIV_EDIT); # Select random definition to search. $count = db_getSingleValue("select count(*) from Definition where status = 0 and length(internalRep) > 250;"); $nr = rand(1, $count); $definition = db_getSingleValue("select htmlRep from Definition where status = 0 and length(internalRep) > 200 limit {$nr} ,1;"); # Parse definition and create string to search $v = explode(" ", strip_tags($definition)); $to_search = "\""; # Set string to search start + end $WORD_START = 5; $WORD_NO = 16; $to_search .= implode(" ", array_slice($v, $WORD_START, $WORD_NO)); $to_search .= "\""; $to_search = str_replace(array(",", "(", ")", "[", "]", "-", ";", "◊", "♦", "<", ">", "?", "\\", "/"), array_pad(array(), 14, ''), $to_search); $urlGoogle = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0"; $apiKey = pref_getServerPreference('googleSearchApiKey'); $url = $urlGoogle . "&q=" . urlencode($to_search) . "&key=" . $apiKey; $body = util_fetchUrl($url); # now, process the JSON string $json = json_decode($body); $rezultate = $json->responseData->results; $listAll = array(); $content = ""; $messageAlert = array(); $blackList = array(); foreach ($rezultate as $iter) { # Skip dexonline.ro from results #if(stripos($iter->url, "dexonline.ro") == true)
/** * Gets the table rows * @param boolean $string If true, then return the result as string instead of DOMDocument [OPTIONAL] * @access protected * @return DOMDocument | string **/ protected function getRows($string = true) { $limit_from = ($this->page - 1) * $this->limit; $limit_to = $this->limit + $limit_from; $sql = <<<sql select count(*) from {$this->sql_base} {$this->where_condition} sql; $count = db_getSingleValue($sql); $sql = <<<sql select {$this->sql_fields} from {$this->sql_base} {$this->where_condition} order by {$this->sidx} {$this->sord} limit {$limit_from}, {$limit_to} sql; $rows = db_execute($sql, PDO::FETCH_ASSOC); $doc = new DOMDocument('1.0', 'UTF-8'); $root = $doc->createElement('rows'); $root->appendChild($this->newNode('page', $this->page, $doc)); $root->appendChild($this->newNode('total', ceil($count / $this->limit), $doc)); $root->appendChild($this->newNode('records', $count, $doc)); foreach ($rows as $dbRow) { $row = $doc->createElement('row'); $row->setAttribute('id', $dbRow['id']); foreach ($dbRow as $key => $cell) { if (!is_numeric($key) && $key != 'id') { $row->appendChild($this->newNode('cell', $dbRow[$key], $doc, $key == 'htmlRep' ? true : false)); } } $root->appendChild($row); } $doc->appendChild($root); return $string ? $doc->saveXML() : $doc; }