Optimization 5属性计数
我们用最初在Joomla开发的混凝土5建造了一个场地。我们的工作是把一切都带过来并具体化。这个网站的主要部分是大约1200个音频教学,每个教学都有不同的属性,如主题、作者、节目、地点等 有些教学可能会指定多个属性,比如多个关键字或主题 我想对所有属性进行计数,以便访问者可以一眼看到某个作者的多少教导,或某个特定主题的多少教导,即:Optimization 5属性计数,optimization,concrete5,Optimization,Concrete5,我们用最初在Joomla开发的混凝土5建造了一个场地。我们的工作是把一切都带过来并具体化。这个网站的主要部分是大约1200个音频教学,每个教学都有不同的属性,如主题、作者、节目、地点等 有些教学可能会指定多个属性,比如多个关键字或主题 我想对所有属性进行计数,以便访问者可以一眼看到某个作者的多少教导,或某个特定主题的多少教导,即: 道德(20) 恐惧(42) 感恩(55) 我的原始代码被证明有太多的被偷听到的东西,对于这么多的教导和这么多的属性来说是不实用的。基本上,我遍历了每个属性,并根据
- 道德(20)
- 恐惧(42)
- 感恩(55)
[Collection | File]SearchIndexAttributes
表。(我不确定教学内容是文件还是页面。如果是页面,则需要通过仪表板中的作业定期对其重新编制索引。)查看索引表比在属性值表中加入最新版本要容易得多。一旦看到该表,就可以在SQL中进行一些简单的分组
如果您想使用API,可以像今天一样批量执行,进行适当的计算,然后缓存它
缓存没有理由不工作,但是第一次命中(当缓存处于冷态时)当然会占用全部时间。你应该缓存我的IndexAttributes想法(一个完整的表读取和循环并不是一件小事),但至少使用一个冷缓存,它应该只需要几分之一秒,而不是数百个页面列表调用可能需要的10秒或更长时间。我在一个工作站点上做了类似的事情5,通过显示每个部门的职位数量 i、 e.人力资源(32)、销售(12)等 这是从帮助器获取的代码,帮助器实现了这一点(这只是包含的相关函数):
<?php
class JobHelper {
/**
* GetDepartmentJobsCount
* Returns array of Department names with job count based on input Pages
* @param Array(Pages) - Result of a PageList->getPages
* @return Array
*/
public function getDepartmentJobsCount($pages) {
$depts = $this->getDepartments();
$cj = $this->setCounts($depts);
$cj = $this->setAttributeCounts($cj, $pages,'job_department');
return $cj;
}
/**
* GetDepartments
* Return all available Departments
* @return Array(Page)
*/
public function getDepartmentPages(){
$pld = new PageList();
$pld->filterByPath('/working-lv'); //the path that your Teachings all sit under
$pld->setItemsPerPage(0);
$res = $this->getPage();
$depts = array();
foreach($res as $jp){
$depts[$jp->getCollectionName()] = $jp;
}
ksort($depts);
return $depts;
}
/**
* PopulateCounts
* Returns array of page names and counts
* @param Array - Array to feed from
* @return Array
*/
public function setCounts($v){
foreach($v as $w){
$a[$w]['count'] = 0;
}
return $a;
}
/**
* PopulateCounts
* Returns array of page names, with counts added from attribute, and paths
* @param Array - Array to add counts and paths in to
* @param Array(Pages) - Pages to run through
* @param String - Attribute to also add to counts
* @param String - Optional - Job Search parameter, leave blank to get Page URL
* @return Array
*/
public function setAttributeCounts($cj, $pages, $attr){
foreach($pages as $p) {
$pLoc = explode('|',$p->getAttribute($attr)); // Our pages could have multiple departments pipe separated
foreach($pLoc as $locName){
$cj[$locName]['count']++;
}
}
return $cj;
}
$jh = Loader::helper('job');
$deptCounts = $jh->getDepartmentJobsCount($pages);
foreach($deptCounts as $dept => $data) {
echo $dept . '(' . $data['count] . ')';
}