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

Keyword priority search??

Quote Reply
Keyword priority search??
Has anyone successfully implemented a keyword priority search (versus by category)?? I am thinking about offering keyword purchases and then giving them priority ranking within the search results.

Thanks.

Mark G.
OhioBiz
www.ohiobiz.com

Quote Reply
Re: Keyword priority search?? In reply to
Here are some suggestions:

1) Add a new field called Keywords in your Links and Validate tables and Links.def and Validate.def files. This should be an INDEX field.

2) Then in the editor.cgi script, increase the index value of the Keywords to 3.

3) Then in your add and modify templates, add the field "Keywords" as a text field.

4) Then you can re-index your Links and Categories tables.

Another suggestion is to simply increase the INDEX value of the Description field via the editor.cgi to a value of 3, then when people add words in the Description field, it will come up towards the top of the listings in the search.

Now in terms of "charging" for keywords, this would be a bit complex and I don't know if you have addressed back-end transaction issues or not...It would be quite difficult to gaurantee a top seat in your directory other than installing modifications like the Priority Mod, which only primarily helps with the CATEGORY pages, not with the search results.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

Thanks for you quick response.

I just have one remaining issue. It has to do with Links SQL not giving all the search results for the submitted keywords. As an example, you type in "Kent State" and it doesn't turn up any results when I know there are at least 6-10 links in my db that start with "Kent State". I must have something set incorrectly somehere. Would you have any suggestions on that? My site is www.ohiobiz.com.

Thanks in advance.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
Use the AND connector in the advanced search form. That WILL narrow your search results.

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

I tried that and it still doesn't work.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
And did you re-index your Links table after your edited the Table Definitions via the editor.cgi script...IF not, THEN you need to RE-INDEX your Links and Category tables as I mentioned above!

Remember, anytime that you edit field defitions, including INDEX values, you need to RE-INDEX your Links and Category tables!

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

I just tried re-indexing the Links and Category tables and I'm still not getting the proper results.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
How about linking your web directory that uses Links SQL? It may be a matter of improperly formatted HTML codes in your search form codes.

ARE you using the advaced search form??? Try that first.

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
I seem to be getting less results now than before re-indexing. I think i'm in over my head on this!!

Quote Reply
Re: Keyword priority search?? In reply to
Well, without seeing your search form...I am totally blind and guess what? I have nothing else to provide.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot my site is at www.ohiobiz.com.

Also, here is my search.cgi file:

#!/usr/local/bin/perl
#!/usr/local/bin/perl
# ==============================================================
# -------------
# Links SQL
# -------------
# Links Manager
#
# Author: Alex Krohn
# Email: alex@gossamer-threads.com
# Web: http://www.gossamer-threads.com/
# Version: 1.13
#
# COPYRIGHT NOTICE:
#
# Copyright 1999 Gossamer Threads Inc. All Rights Reserved.
# No redistribution of this script may be made without prior
# written consent.
#
# By using this program you agree to indemnify Gossamer Threads
# Inc. from any liability.
#
# Please see the README for full license details.
#
# ==============================================================

# Load required modules.
# ---------------------------------------------------
use CGI ();
use CGI::Carp qw/fatalsToBrowser/;
use lib 'admin';
use Links;
use Links::DBSQL;
use Links::DB_Utils;
use Links::HTML_Templates;
use strict;
$|++;

&main();

sub main {
# ---------------------------------------------------
# Determine what to do.
#
my $in = new CGI;
my $dynamic = $in->param('d') ? $in : undef;
print $in->header();

if ($in->param('query')) {
&search ($in, $dynamic);
}
else {
&site_html_search_form ( { query => '' }, $dynamic );
}
}
# ==============================================================

sub search {
# ---------------------------------------------------
# Performs the actual search.
#
my ($in, $dynamic) = @_;
my ($mh, $bool, $nh, $ww, $order, $query, $ignored, %seen, $next, $catid, $sub_list, $cat_name,
$catdb, $cat_hits, $category_results, $cat_count, $cat_errors, $linkdb, $link_hits, $link_results, $link_count, $link_errors);
my %in = %{&cgi_to_hash($in)};

# Get/Set the search options.
($in->param('mh') =~ /^(10|25|50|100)$/) ? ($mh = $1) : ($mh = 25);
($in->param('bool') =~ /^(and|or)$/i) ? ($bool = uc $1) : ($bool = 'OR');
($in->param('nh') =~ /^(\d+)$/) ? ($nh = $1) : ($nh = 1);
($in->param('substring')) ? ($ww = 0) : ($ww = 1);
($in->param('order') =~ /^(score|category)$/i) ? ($order = uc $1) : ($order = 'CATEGORY');

$catid = $in->param('catid');
# Get a list of catgeory ID's for 'only this cat' type of search
if ($catid eq ""){$cat_name=""} else {
# Get Category Name
$cat_name = &get_category_name ($catid);
# Get a list of category IDs where the name starts with $cat_name
$sub_list = &get_category_id_list ($cat_name);
chop($sub_list);
$in->param ( 'CategoryID' => $sub_list );
}

# Split up the search term.
$query = $in->param('query');
$query or &site_html_search_failure ( { error => "No search term entered.", %in }, $dynamic) and return;
$in{'term'} = $in->escape ($query);

# Search the category listings.
my %catfilter = ();
%catfilter->{'ID'}=$sub_list;
$catdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Category.def";
$cat_hits = $catdb->query ( { query => $query, mh => $mh, nh => $nh, ww => $ww, filter => \%catfilter} );
$cat_count = $catdb->hits || 0;
$cat_errors = $catdb->query_errors;

# Now let's search the links table, but first figure out any filters.
$linkdb = new Links::DBSQL "$LINKS{admin_root_path}/defs/Links.def";
my %filter = ();
foreach my $col (@{$linkdb->{db_cols}}) {
if ($in->param($col)) {
$filter{$col} = $in->param($col);
}
}
$link_hits = $linkdb->query ( { query => $query, mh => $mh, nh => $nh, filter => \%filter, ww => $ww, bool => $bool } );
$link_count = $linkdb->hits || 0;
$link_errors = $linkdb->query_errors;

# Format the errors (if any)
if (ref $link_errors eq 'HASH') {
foreach my $word (keys %$link_errors) {
next if ($seen{$word}++);
$ignored .= "<li>$word - " . $link_errors->{$word};
}
}
if (ref $cat_errors eq 'HASH') {
foreach my $word (keys %$cat_errors) {
next if ($seen{$word}++);
$ignored .= "<li>$word - " . $cat_errors->{$word};
}
}

# Return if we don't have any matches.
unless ($link_count or $cat_count) {
&log_query ($in->param('query'), 0);
&site_html_search_failure ({ error => "No matching links.", ignored => $ignored, %in }, $dynamic);
return;
}

# Only display the category output on the first page.
if ($nh == 1) {
if ($cat_hits) {
foreach my $hit (@$cat_hits) {
$hit = $catdb->array_to_hash($hit);
$category_results .= "<li>" . &search_build_linked_title ($hit->{Name}) . "\n";
}
}
}

# Build the list of link results.
if ($link_hits) {
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}
foreach my $hit (@$link_hits) {
next if ($displayed{$hit->{CategoryID}}++);
$name = &get_category_name ($hit->{CategoryID});
$link_results .= "<p>" . &search_build_linked_title ($name) . "</p>";
$link_results .= $link_results{$hit->{CategoryID}};
}
}

# Log the search results.
&log_query ($in->param('query'), $link_count + $cat_count);

# If we want to bold the search terms...
if ($LINKS{search_bold}) {
my $tempquery = $query;
$tempquery =~ s/[+\-"']//g;
my @terms = split /\s/, $tempquery;
foreach (@terms) {
if (s/(.+)\*(.*)/$1/) {
push @terms, $2 if ($2);
$link_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
$category_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
}
else {
$link_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
$category_results =~ s,(<[^>]+>)|(\Q$_\E),defined($1) ? $1 : "<B>$2</B>",gie;
}
}
}

# Search toolbar.
($link_count > $mh) and ($next = $linkdb->toolbar());

# Print out the HTML results.
&site_html_search_results ( { link_results => $link_results, category_results => $category_results,
link_hits => $link_count, cat_hits => $cat_count, next => $next, ignored => $ignored, %in }, $dynamic );
}

sub search_build_linked_title {
# --------------------------------------------------------
# Returns a string of the current category broken up
# by section, with each part linked to the respective section.
#
my $input = shift;
my (@dirs, $dir, $output, $path);

@dirs = split (/\//, $input);
$output = qq| <A HREF="$LINKS{build_root_url}/">Top</A> :|;
for (0 .. $#dirs) {
$path = "/" . &build_clean_name( join "/", @dirs[0 .. $_] );
$output .= qq| <A HREF="$LINKS{build_root_url}$path/">$dirs[$_]</A> :|;
}
chop $output;
return $output;
}

sub log_query {
# --------------------------------------------------------
# Logs the search term.
#
my ($query, $results) = @_;
my $db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Search_Log.def";
$query =~ s/^\s*//g; $query =~ s/\s*$//g;
$query = lc $query;
$query = substr ($query, 0, 24);
my $hit = $db->get_record ( $query, 'HASH' );
my $time = $db->get_date . " " . $db->get_time;
if ($hit) {
$hit->{Count}++;
$hit->{Last_Hit} = $time;
$hit->{Results} = $results;
$db->modify_record ($hit);
}
else {
$db->add_record ( { Term => $query, Count => 1, Last_Hit => $time, Results => $results } );
}
}



Thanks.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
I did NOT say that there was problems with your search.cgi BUT may be with the H T M L codes in your SEARCH FORMS.

Do you understand?????

Anyway...I checked the HTML codes in your search form and everything looks okay...although when I searched for Kent State and then Kent I got no results, which means that you have probably not edited the LINKS table definitions correctly. Keep in mind that clicking on Re-sync is NOT the button you should use since values will default back to their original value.

Do me a favor, okay? LOOK in your Links_Scores_Index and Links_Word_Index tables. HOW MANY records do you have in each???



Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Please excuse my ignorance, I'm new at working with mySQL - I'm at the Table Maintenance - Links screen (Edit Link Definitions screen). From there, how do I find my Links_Scores_Index and Links_Word_Index tables?

Thanks.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
Unfortunately, you will not be able to see the records in those tables via the editor.cgi or admin.cgi scripts...(I would recommend at some point downloading and installing the MySQLMan product from this web site. MySQLMAN is a more robust MySQL admin application.)

Okay...let's do this...CHECK the Links table definitions...What are the INDEX values for URL, Description, and Keywords??? If you do NOT have a value of 3 in the latter two fields, then you have not properly edited the table definition. Remember that you have to CHECK each of the fields that you edit IN ORDER for the changes to stick. Then when you have successfully edited the table definitions...it is OFF to re-indexing your LINKS and CATEGORY tables.

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

It is currently "0" for URL, "1" for Description and I don't have a Keywords.

ID
Title
URL
Add_DAte
Mod_DAte
CategoryID
Description
Contact_Name
Contact_Email
Hits
isNew
isChanged
isPopular
Rating
Votes
ReceiveMail
Status
Date_Checked
Priority

Everything is "0" except for Title and Description.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

Meta_Keywords in Category Table Maintenance area is "0", everything else in the Category area is "0" except Name - "3" and Description - "1".

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
UGH! I thought you stated in an earlier message that you had added the Keywords field.

Okay...by what you have told me...you HAVE not properly changed the Table Definitions for the Links table...

I will walk you through the steps:

1) CLICK on the Links under Table Maintenance in the admin.cgi script.

2) Then CLICK on the Edit Table Definitions link.

3) Then CLICK on the CHECKBOXES next to the URL, Title, and Description fields.

4) Then in the Index Weight column, type in 2 for the URL field, 3 for the Description field, and 2 for the Title field.

5) Then (and this is very important), CLICK on the Update Changes NOT Resync.

NOW your INDEX WEIGHT values are updated.

Then you will have to RE-INDEX your Links and Category tables....

Do you understand now???

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
I am not concerned about the CATEGORY table at this time...but you should consider also updating the INDEX WEIGHTS for the IMPORTANT fields (like the META fields) in the CATEGORY table.

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

Is the proper way of re-indexing just clicking on the "Re-Index" Link under the "Building" section in admin.cgi. I've tried it thru the Web interface and the indexing "pooped out" around 3,090 of the 6,076 links. Should this be done via telnet? If so, what is the comand?

Thanks so much! I really do appreciate your time and effort.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
Yea...you simply click on the Re-index link AFTER you update the Index Weights. You can execute the script via HTTP (web browser) OR telnet (using UNIX commands)...like the following:

1) Connect to the directory where the nph-index.cgi script is located.

Code:

cd /cgi-bin/links/admin/


2) Then EXECUTE the nph-index.cgi file:

Code:

perl nph-index.cgi


Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

Again, thanks so much! It's been a real education!

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
Eliot,

One last question and then I'll shut up for the night -
I tried - perl nph-index.cgi at the prompt and get the following: "(offline mode: enter name=value pairs on standard input)"

What do I need to include here?

Thanks.

Mark G.

Quote Reply
Re: Keyword priority search?? In reply to
I figured it out ....Ctrl-D.

Mark G.