Page 1 of 1

Search results with hits in each category

Posted: Wed May 12, 2004 7:57 pm
by ppeddi
Hello,
I have a profile with 5 categories in it. When user selects -Everything- option, I want to display number of results from each category at the top of the results page which shold be a link to those results.

How can I put a check box for each category, instead of a dropdown list?

thanks in advance

Search results with hits in each category

Posted: Thu May 13, 2004 10:18 am
by mark
You'd need to <loop> over the desired categories and do count() queries for each one to get the count. The link could be to a regular search of the selected category.

Where the form has <select ..><options ...></select> use <checkbox ...> or <radiobutton ...> instead. See
http://thunderstone.master.com/texis/ma ... ckbox&s=.2
for info about <checkbox>.

Search results with hits in each category

Posted: Thu Oct 21, 2004 3:39 pm
by mark
Here's a basic version. Place this code right after the
<showform refine=y>
line of the "search" function in the search script.

<if $scq eq '' and $savenext eq 1>
<LOCAL scq cq ic close>
<$ic=$indexcount>
<sql ROW "select distinct Catno scq,Category from categories order by convert(scq,'int')">
<SQL "select count(*) N " $sql>
<if $N gt 0>
<if $close eq "">
<$close="</ul>">
<ul>
</if>
<$cq=$scq><li><A HREF="$url$urlq$mltvar">$Category ($N)</A><BR>
</if>
</SQL>
</sql>
<send $close>
<$indexcount=$ic>
</LOCAL>
</if>

Disclaimer: the above is based on the 5.1.3 scripts but should work with most 4 or 5 scripts but has not been tried with those.

Search results with hits in each category

Posted: Tue Nov 16, 2004 1:03 am
by ppeddi
Hi Mark,

I used the following script in search function to get the number of hits in each category

<if $scq eq ''>
<LOCAL scq cq ic>
<$ic=$indexcount>
<BR>
<sql ROW "select distinct Catno scq,Category from categories order by convert(scq,'int')">
<SQL "select count(*) N " $sql>
<$cq=$scq>    $scq,m <A HREF="$url$urlq$mltvar">$Category</A> $N  
</SQL>
</sql>
<BR><BR>
<$indexcount=$ic>
</LOCAL>
</if>

Now I modified the search function little more so that the search form can accept more than one category. I modified it as follow:

<$cqq=>
<loop $cq>
<if $cq ne "">
<if $cqq eq "">
<$cqq=" and (">
<else>
<$cqq=$cqq " or">
</if>
<rex "\digit+" $cq>
<$cqq=$cqq " Catno matches '" $ret "'">
</if>
</loop>
<if $cqq ne ""><sum "%s" $cqq ")"><$cqq=$ret></if>
<$sql="from html
where Title\Description\Keywords\Meta\Body " $liketype " $$sq
and Title like $$stq
and Url matches $$suq
and Depth <= $$sdq
" $cqq>

Now thinkgs are working fine, I mean I can select multiple categories at a time and getting the results right. (I modified the script so that instead of dropdown list I have checkboxes for each category)

I am getting the search result all right except in the results per category. Instead of showing results in a particular category, I am getting total number of hits for the search in all the categories.

In my search file, first I have the code for accepting multiple categories then I have the code for hits in each category.

Can you please help.

thanks
Praveen