Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Category Search

Quote Reply
Category Search
Ok.. using this
Code:
($in->param('category') =~ /^(\d+)$/) ? ($category = $1) : ($category = 0);

AND

Code:
$sth = $db->prepare ( " SELECT SubCategoryID FROM CategoryHeiarchy WHERE CategoryID = ? ");
$sth->execute($category) or die $DBI::errstr;
$categories = $category;
while (my $cat = ($sth->fetchrow_array)[0]) {
$categories .= ",$cat";
}

in search.cgi i was easily able to get links in certain categories by changing the search.cgi links query to

Code:
$query = qq!
SELECT SUM(Weight) AS score, COUNT(*) AS hits, l.*, c.Name
FROM Links_Index AS s,
Links AS l,
Category AS c
WHERE $search_words
s.ID = l.ID AND
l.CategoryID = c.ID!;
$query .= qq! AND
CategoryID IN ($categories)! if ($categories);
$query .= qq!
GROUP BY s.ID
$having
$relevance
LIMIT $offset, 500
!;

now.. categories...

i will continue to try and rewrite the query.. but as i learned from the last time i did a multiple database query.. i suck! Smile

anyways..
jerry
Quote Reply
Re: Category Search In reply to
ok.. i changed the category query to

Code:
$query = qq!
SELECT COUNT(*) as hits, c.ID, c.Name
FROM Category_Index as s, Category as c
WHERE ($where) AND s.ID = c.ID!;
$query .= qq! AND
c.ID IN ($categories)! if ($categories);
$query .= qq!
GROUP BY s.ID
ORDER BY c.Name ASC
LIMIT 50
!;

and it worked.. so now that's over with..

jerry
Quote Reply
Re: Category Search In reply to
Hello Widgetz!

Thats nice of you.

I was thinking of something similar.

What about searching in this way the category
in the add.cgi? This will help in not generating a kilometer long category listings?

My problem is that not only it creates a long listing in the add.cgi for 4600 categories per user, but for each link it downloads all 4600 categories in the admin form twice. Only with ten links I was forced to download two megabytes of that admin page for Validation! So having a field of Categoriy Alternates, every link is downloading twice the categories.

Therefore I have 4600 categories. So :

each links downloads 9200 category listings. Fo ten links, I downloaded 92,000 category listings PER PAGE. Receiving submissions of 300 links request per day, I will be forced to download 2,76 Million Category listings per day.

Thats the reason why I was thinking of finding a way of searching a category, if there, insert it in the add.cgi field, if not offer a blank field for the user to fill out as that would bring a new category suggestion.

I am not that far to reach the add.cgi part. However if you know how to do it, I would appreciate.

Thanks










------------------
rajani











Quote Reply
Re: Category Search In reply to
Hi Widgets,

What is the function of your mod?
Does it do a "search only this category" ?
Quote Reply
Re: Category Search In reply to
yea.. it searches the category you select PLUS it's subcategories..

for both category and search results..

if you are interested.. i will post more detailed instructions..

jerry
Quote Reply
Re: Category Search In reply to
On my old site (Links1.1) I have a search on the main page which searches whole site, but each category page has a checkbox under the search which says "Search only in this category".

If this is that, then YES please post insructions.

Chris
Quote Reply
Re: Category Search In reply to
ok.. all in search.cgi

IN SUB SEARCH ADD:

Code:
, $category, $categories

into the list of variables.. (the my declaration).. there are 2.. choose any Wink

UNDER this:

Code:
($in->param('order') =~ /^(score|category)$/i) ? ($order = uc $1) : ($order = 'CATEGORY');

ADD this:

Code:
($in->param('category') =~ /^(\d+)$/) ? ($category = $1) : (undef $category);

UNDER:

Code:
$db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";

ADD THIS:

Code:
if ($category) {
$categories = $category;
$sth = $db->prepare (" SELECT SubCategoryID FROM CategoryHeiarchy WHERE CategoryID = $category ");
$sth->execute();
while (my $cat = ($sth->fetchrow_array)[0]) {
$categories .= ",$cat";
}
}

CHANGE

Code:
$query = qq!
SELECT COUNT(*) as hits, c.ID, c.Name
FROM Category_Index as s, Category as c
WHERE ($where) AND s.ID = c.ID
GROUP BY s.ID
ORDER BY c.Name ASC
LIMIT 50
!;

TO this:

Code:
$query = qq!
SELECT COUNT(*) as hits, c.ID, c.Name
FROM Category_Index as s, Category as c
WHERE ($where) AND s.ID = c.ID!;
$query .= qq! AND
c.ID IN ($categories)! if ($categories);
$query .= qq!
GROUP BY s.ID
ORDER BY c.Name ASC
LIMIT 50
!;

CHANGE this:

Code:
$query = qq!
SELECT SUM(Weight) AS score, COUNT(*) AS hits, l.*, c.Name
FROM Links_Index AS s,
Links AS l,
Category AS c
WHERE $search_words
s.ID = l.ID AND
l.CategoryID = c.ID
GROUP BY s.ID
$having
$relevance
LIMIT $offset, 500
!;

TO this:

Code:
$query = qq!
SELECT SUM(Weight) AS score, COUNT(*) AS hits, l.*, c.Name
FROM Links_Index AS s,
Links AS l,
Category AS c
WHERE $search_words
s.ID = l.ID AND
l.CategoryID = c.ID!;
$query .= qq! AND
CategoryID IN ($categories)! if ($categories);
$query .= qq!
GROUP BY s.ID
$having
$relevance
LIMIT $offset, 500
!;

then the rest.. i don't know what to tell you.. but it's easy.. just add like a checkbox field to the form or something

Code:
<input type="checkbox" name="category" value="##ID##"> Search this category

jerry

[This message has been edited by widgetz (edited October 29, 1999).]
Quote Reply
Re: Category Search In reply to
search.cgi has nothing to do with category pages Wink

jerry
Quote Reply
Re: Category Search In reply to
No...but if you put a search box and a "search this category only" check box option....it wont work.
The variables for the checkbox have to be renamed.
Quote Reply
Re: Category Search In reply to
oh i get you..

but why don't you just use

Code:
<INPUT TYPE="CHECKBOX" NAME="category" VALUE="<%category_id%>">

Wink

jerry
Quote Reply
Re: Category Search In reply to
Found a bug in the code.... Frown

Change all references of $category to another var name...like $category_id

Then your checkbox should be:
<INPUT TYPE="CHECKBOX" NAME="category_id" VALUE="<%category_id%>">Only in this category

I had it exactly the way you have it here, but it plays havoc with the category pages, as $category is the html coded category list for the category pages.

Chris
Quote Reply
Re: Category Search In reply to
Thats what I originally had, but saw when I viewed source, it said "unknown tag". So I changed to category and saw everything screwed up. SO I changed "$category" to "$category_id" and everything works perfect.

Chris
Quote Reply
Re: Category Search In reply to
Think you are talking about a beta-version; couldn“t find parts of your code in my 1.1?

So please be so kind to tell us the changes for the latest final?

Robert
Quote Reply
Re: Category Search In reply to
Well, I bet this codes are for version 1.02
Has someone already done this for version 1.1?

Thanks...
Quote Reply
Re: Category Search In reply to
Ok Jerry!

Thank you for the attention, and as soon as you liberate the code please it informs me.

Hug
Elijānio
Quote Reply
Re: Category Search In reply to
Did anybody already make this mod to work with the version 1.11?
in case the answer is yes finds out as doing.