This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

How to count several items with sfLucene!

Questions relating to sfLucenePlugin, sfSearch etc

How to count several items with sfLucene!

by wgbbiao » Thu Jan 22, 2009 9:18 am

我可做一个像淘一样的搜索吗?用sfLucene!


Can I make a web like www.taobao.com with sfLucene!

[Mod: renamed post - halfer]
wgbbiao
Junior Member
 
Posts: 15
Joined: Sun Sep 23, 2007 5:23 am

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by halfer » Thu Jan 22, 2009 11:28 am

Probably. What functionality is it that you want to replicate? sfLucene will give you a complex search facility, which you can interrogate using the default search page, or you can create your own. The best thing here is to give it a go, and drop a line here if you run into problem. Don't forget to search the fora first though, as many common questions have already been asked.
halfer
Faithful Member
 
Posts: 10148
Joined: Mon Jan 30, 2006 1:16 pm
Location: West Midlands, UK

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by wgbbiao » Fri Jan 23, 2009 4:13 am

I want to get the number
Attachments
无标题.jpg
无标题.jpg (32.72 KiB) Viewed 3437 times
wgbbiao
Junior Member
 
Posts: 15
Joined: Sun Sep 23, 2007 5:23 am

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by halfer » Fri Jan 23, 2009 1:22 pm

I can't read the text on that image, but it looks like they are categories of some kind. My guess is that this would be done with a database, not Lucene. Counting Lucene searches ten or 15 times in a single page would be, to my mind, far too slow.

Perhaps if you can indicate the nature of the "counted things" on that page, someone could give you a more accurate answer?
halfer
Faithful Member
 
Posts: 10148
Joined: Mon Jan 30, 2006 1:16 pm
Location: West Midlands, UK

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

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!
wgbbiao
Junior Member
 
Posts: 15
Joined: Sun Sep 23, 2007 5:23 am

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by wgbbiao » Tue Feb 03, 2009 4:55 am

添加上段代码后,速度提升了很多!
wgbbiao
Junior Member
 
Posts: 15
Joined: Sun Sep 23, 2007 5:23 am

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by assassinann » Thu Apr 09, 2009 5:57 am

首先您很有性格啊···在英文论坛里面发中文 贴···哈哈··
我就不用英文请教您了啊··
现在我到一个问题想请教您一下·
我按照jobeet中的search那一章做了一个搜索栏
但是搜索中文的时候搜索不到结果啊·?
我使用的数据库是MySQL,建立数据库时使用的编 码是utf8_bin,在建立索引文件文件时在索引文
assassinann
Junior Member
 
Posts: 28
Joined: Wed Feb 11, 2009 9:29 am
Location: china

Re: 我可做一个像淘一样的搜索吗?用sfLucene!

by wgbbiao » Thu Dec 17, 2009 4:58 am

好像不看了。。
不知道你的问题解决了没有。
只要设置了编码,应该没有什么问题。


我现在遇到了一个问题:
现在索引文件很大了,400多M,搜一个词用OR的 关系去搜时就会很慢。20秒以上吧。。
相当烦人。


你有什么好招吗?
wgbbiao
Junior Member
 
Posts: 15
Joined: Sun Sep 23, 2007 5:23 am