by wgbbiao » Mon Feb 02, 2009 4:47 am
4.计算catetries 的数量;
plugins/sfLucenePlugin/lib/vendor/Zend/Search/Lucene.php
在797 行添加:
$catetries = array();//初始化数组
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if( $docScore != 0 ) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
break;
}
}
将此段代码改为:
foreach ($query->matchedDocs() as $id => $num) {
$docScore = $query->score($id, $this);
if( $docScore != 0 ) {
$hit = new Zend_Search_Lucene_Search_QueryHit($this);
$hit->id = $id;
$hit->score = $docScore;
//添加此段代码 开始
foreach (explode(',' , $hit->sfl_category) as $category)
{
$category = trim($category);
if (isset($catetries[$category])) {
$catetries[$category] ++;
}
else
{
$catetries[$category] = 1;
}
}
//添加此段代码 结束
$hits[] = $hit;
$ids[] = $id;
$scores[] = $docScore;
if ($docScore > $topScore) {
$topScore = $docScore;
}
}
if (self::$_resultSetLimit != 0 && count($hits) >= self::$_resultSetLimit) {
break;
}
}
在函数结束时添加:
$hits['catetries'] = $catetries; //添加此行
return $hits;
plugins/sfLucenePlugin/lib/results/sfLucenePager.class.php
添加函数:
public function getCatetries()
{
return $this->results['catetries'];
}
调用$pager->getCatetries() ($pager 为sfLucenePager 对象 ) 可得行类似:Array ( [saving] => 1 [search] => 1 [financing] => 1 [pursueFinacing] => 1 [compare] => 1 [gradeSearch] => 1 [searchOld] => 1 [searchcredit] => 1 [simpleSerarch] => 1 [select] => 1 [installment] => 1 [otherloans] => 1 [auto] => 1 [accredit] => 1 [otherinvestment] => 1 [fundfilter] => 1 [remit] => 1 [index] => 1 [foreign] => 1 [homeloan] => 1 [howLoan1] => 1 [common] => 1 [allBankHomeLoan] => 1 [assigendShop] => 1 [calc] => 1 [repaymentComparison] => 1 [lateRepayment] => 1 [installments] => 1 [DCwithdrawalsFee] => 1 [excessFee] => 1 [CCwithdrawalsFee] => 1 [overLimitFee] => 1 [latePayments] => 1 [onlineTransferFee] => 1 [transfersFee] => 1 [savingInt] => 1 [nationaldebt] => 1 [bankDebt] => 1 [result] => 1 [managementFees] => 1 [auditing] => 1 [searchOldFc] => 1 ) 的数组.
注:最后的数据会多一个 应该相应的减1
I did it like this!