Gossamer Forum
Home : Products : Links 2.0 : Customization :

Improving Search Results - Yet, Again

Quote Reply
Improving Search Results - Yet, Again
Does anyone have a fix for search.cgi to return exact words? To use an example from an old thread here (http://gossamer-threads.com/...guest=10225382#33242) if you search on "ham" you get "champion" returned. A fix was suggested in that thread, but it doesn't work. At least, not for me.

I've just started taking a look at search.cgi, considering ways to improve search results, so I'm not yet very familiar with that part of the script. Any suggestions, advice or pointers to helpful threads would be really appreciated.

Thanks in advance,
Kathy

Last edited by:

KM: Jan 8, 2005, 11:22 AM
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
I found what I was looking for (sort of) at http://gossamer-threads.com/...guest=10227549#33264. It puts a radio button on the search.html form, but you could also easily add the "exact word" field as a hidden field in all search forms if you want search to always return exact words.

Also used this to stop search results from listing according to category: http://gossamer-threads.com/...guest=10227549#42330. It completely removes categories from the search results page.

Problem is, now I have to list the category under each link that search returns (still, it looks rather nice, I think). I followed this mod at http://gossamer-threads.com/...uest=10227160#149181 to put in the categories, but I can't figure out how to make them linked. The advice given was:

With regards to the linked title in the search results, add another chop ($output); before the chop ($output);.

I've played around with this bit in search.cgi, trying different things, but I am absolutely clueless. What does he mean? I assume I need to somehow "copy" this to build a linked catgeory, but I don't know enough perl to figure it out. Can someone help? Please?

Finally, I tried running the very nice Search Relevency Mod. Does exactly what I want. Only problem - yikes! - is that I'm using the Editor's Picks mod with an if/endif and an image. Every single link is adorned with the Pick image in search results. I'm not sure how to solve this. Should I try to run the searchlink.html through site_html_templates to sort the links that are picks? Or would it make more sense to try to put the <%relevancy%> tag on the regular link.html and try to run that through the sorthit process? (Actually, I was wondering why the Relevency Mod requires a separate links template at all--is that necessary?)

I realize I'm asking an awful lot of questions, and I apologize. I guess it's time I took a class, if I ever want to stop bumbling around.

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Sounds like you've been looking at a screen all day! Instead of the chop chop stuff, just use Paul's code in that thread:

http://www.gossamer-threads.com/...i?post=149228#149228

More specificall, in site_html_templates.pl, sub site_html_link, add this under

my %rec = @_;

# Put linked-cat in link
$cat_url = &urlencode($rec{Category});
$cat_clean = &build_clean($rec{Category});


Then before the %rec put these:

cat_clean => $cat_clean,
cat_url => $cat_url,


Then in your link.html template put this:

<a href="<%build_root_url%>/<%cat_url%>"><%cat_clean%></a>

That works! Wink

What code did you use for the checkbox for the exact match mod?


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
Yes, Saturday's just another normal work day. Until I get this directory up and running, anyway. Thanks for the code. It works perfect. I hadn't figured on having categories listed under links on category pages as well, though. I don't know why I didn't expect it. Makes sense. But I'm not sure I like the look on category pages. Any ideas about getting rid of them? (Ah, yes. searchlink.html... it grows clearer to me, now).

The code? I used Chidlow's. Or do you mean on the search form? In search.html (where I want it to be an option):

exact word:<input type="RADIO" name="exact" value="exact" CHECKED>
any form of word:<input type="RADIO" name="exact" value="any">

On other search forms throughout site:

<form action="cgi-bin/x/search.cgi" method="GET">
<input type="hidden" name="exact" value="exact">


Not pretty, but it works.

I'm still at a loss about how to run the Search Relevency Mod and yet have it recognize my if/endif on links.html. Any ideas?

None of this shows up on the JCC site yet. We passed 10,000 links this week (yippee), so I'm working out the problems on all mods on a test site. By the way, your site is really nice. I've gone to look a few times when I got stuck on something.

Thanks again for your help. It's very, very much appreciated.

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Just an update. I never did figure out how to get the Pick image from appearing on all links returned on the search results pages. Only solution was to remove it entirely. But I decided to take lemons and make lemonade. If links on category pages and search pages were going to look different, then I'd really make them different.

So in this way the Relevency Search Mod is really cool--even if you don't care about how search returns are sorted. It lets you create a different "style" for links on category and search pages. Neat.

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Did you include this in the sub site_html_searchlink:

($rec{'isPick'} eq 'Yes') ? ($rec{'isPick'} = 1) : (delete $rec{'isPick'});

Quote:

So in this way the Relevency Search Mod is really cool--even if you don't care about how search returns are sorted. It lets you create a different "style" for links on category and search pages. Neat.


Actually, you don't need to use whole mod to have different templates, just the part of search.cgi that says
$link_output{$setoflinks) .= &site_html_searchlink(%temp). "\n";

And add the new sub to site_html_templates.pl (and the new template). I agree thats a good change to make. And as you noted, this also lets you put the linked cat with each link result, and not have it appear in the regular category pages.


---------------------

I still get champion even if 'Exact Match' is checked, if 'Match ANY word' is also checked. Or is this supposed to replace that radio set?

When the mod instructions are unclear, much experimentation is required... Unsure


Leonard
aka PerlFlunkie

Last edited by:

PerlFlunkie: Jan 9, 2005, 12:20 PM
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
That's weird. It's working great on my test site. Make sure you use a radio button, so only "exact" or "any" can be checked by user, never both, and only put the one hidden field on forms. Here's the code from my search.cgi, although it has other modifications in there, too (I think relevency mod changes):

#Count the number of words put in
$maxrelevent = 0;

$or_match = $bool ne 'and';
if ($or_match) {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words.
$maxrelevent++;
$in{'exact'} ?
$tmp .= "m/\\b\Q${$search_terms}[$_]\E\\b/io &#0124; &#0124;" :
$tmp .= "m/\Q${$search_terms}[$_]\E/io &#0124; &#0124;" ;
}
}
else {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words
$maxrelevent++;
$in{'exact'} ?
$tmp .= "m/\\b\Q${$search_terms}[$_]\E\\b/io &&":
$tmp .= "m/\Q${$search_terms}[$_]\E/io &&" ;
}
}
chop ($tmp); chop ($tmp);
my $relvar = (($maxrelevent) * 4);


If I remember right, I added the codes just as Chidlow gave them, without any changes. Also added his code to make search terms bold, also as is given. It works really well. When I search on "table" I no longer get things like "established" returned. However, it really means business--when I search on "schools" I no longer get instances of "school." It depends on which is more important to you, I think.

Kathy

Last edited by:

KM: Jan 9, 2005, 9:14 PM
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Oops. Found a glitch. "Exact word" is searched for, even when "any" is checked instead. Here's the fix to the radio buttons:

exact word:<input type="RADIO" name="exact" value="exact" CHECKED
any form of word:<input type="RADIO" name="exact" value="">

Sorry. Hope I didn't mess anyone up.

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Your site is looking great! Just a note about your add page:

Quote:
Optional: To also be listed in the Regions section, please complete:


You're missing the 'in'.

Then on your search form, if I search (for 'table') with these selections:

keywords, any word, exact word

I get an error:

Error Message : Can't compile reg exp: m/\btable\b/io | |m/table/io | ! Reason: syntax error at (eval 1) line 2, at EOF
Missing right curly or square bracket at (eval 1) line 2, at end of line

And it's the very descriptive error message, with all your paths, etc...

Form Variables
-------------------------------------------
bool : or
exact : exact
mh : 25
query : table
this cat :
type : keyword


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
Yikes. I get the same error message. I looked over the code, though, and can't find brackets--curly or straight--missing. Everything looks okay to me. What am I missing?

Also, all that info in the error message is pretty scary. How do I keep that from appearing? Should I call my webhost?

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Called my webhost and they said that the detailed (with paths, etc.) CGI Error message I'm getting isn't generated by them but by the script. I'm out of my depth here. Has anyone else seen such detailed error messages? My admin is password protected, and nothing really vital (like passwords) is revealed. Should I be worried about so much info on these error messges?

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
I remembered seeing something about that in another file, and found this in add.cgi:

sub send_email {
# --------------------------------------------------------
# Sends an email to the admin, letting him know that there is
# a new link waiting to be validated. No error checking as we don't
# want users to see the informative &cgierr output.
# Check to make sure that there is an admin email address defined.
$db_admin_email or &cgierr("Admin Email Address Not Defined in config file!");

Seems if a specific error message is not defined ("Admin Email Address Not Defined in config file!"), then the big list is shown. But, you would need to know what error to expect; in the above example, if no admin email adress was entered in links.cfg, the specific error message is given.

I was wondering about how to call the Exact Word mod, and it looks like how you have it set is conflicting with one of the other radio button sets. Possibly the code is looping somewhere due to the selections made, and only then does it find itself missing a bracket...

Eliot (Stealth) had asked, "could the radio buttons: 1) Keywords, and 2) As Phrase conflict with this mod?"

Chidlow (mod author) replied, "When the check box is checked..."

And Sergio provided his code:
<select name="type">
<option value="phrase" selected>Phrase</option>
<option value="keyword">Word</option>
</select>
<br>
<input type="CHECKBOX" name="exact" value="yes">Search exact

So, I think a checkbox is the way to go, not a radio set... I will experiment some.
Funny, I had just been working on this mod when you posted your first question. Tongue


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
Well, I have tried several things, both in the search form and in search.cgi, but I always get these results:

You searched for ham. Displaying results 1 - 3 of 3.
  • test one
    ham

  • test two
    ham champion
  • test three
    champion

Does anyone have this mod working like it should:

Quote:

If you have 3 links, one with the word 'ham', one with the word 'champ' and the third with both words. If you do an exact search right now on 'ham', you will get two links, not three.
http://www.gossamer-threads.com/...cgi?post=33260#33260


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
As long as boolean AND is checked, I get exact words everytime. But...

So, I tried:
<input type="CHECKBOX" name="exact" value="yes">
and
<input type="CHECKBOX" name="exact" value="exact">
snd
<input type="RADIO" name="exact" value="exact" CHECKED>
<input type="RADIO" name="exact" value="">
and
<input type="RADIO" name="exact" value="exact" CHECKED>
<input type="RADIO" name="" value="">

It doesn't matter. Even when I take it the whole "exact" field out, if the boolean OR is checked, I get the error. It's something in the code. Must be in here:

#Count the number of words put in
$maxrelevent = 0;
$or_match = $bool ne 'and';
if ($or_match) {
for (0 .. $#{$search_terms}) {
next if (length ${$search_terms}[$_] < 2); # Skip single letter words.
$maxrelevent++;
$in{'exact'} ?
$tmp .= "m/\\b\Q${$search_terms}[$_]\E\\b/io &#0124; &#0124;" :
$tmp .= "m/\Q${$search_terms}[$_]\E/io &#0124; &#0124;" ;
}
}


For the life of me, I can't see it, though. I've counted brackets and recounted them. They're okay. I really hope you're not right. If I have to choose exact words or boolean, it's going to be a tough one. Without exact word, I got 67 results for the word "table"--as opposed to 7 with it. Man, I really need exact words. If you figure this out, please let me know. I'll keep working on it, too (for whatever that's worth).

Anyone out there who can lend a hand?

Kathy
Quote Reply
Re: [KM] Improving Search Results - Yet, Again In reply to
Here ya go... (change the &#0124; to |)

$tmp .= "m/\\b\Q${$search_terms}[$_]\E\\b/io ||" :
$tmp .= "m/\Q${$search_terms}[$_]\E/io ||" ;


Do you really get exact words only? Do the test like I showed above, then search for 'ham' and see what happens. If you only get two links, and only 'ham' is bolded, I'll kick myself for missing something...Mad


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Improving Search Results - Yet, Again In reply to
Thank you so much!! That got rid of the error message. Okay, I tried searching on a single word and a phrase. I get exact words unless boolean OR is checked. Then I get everything. Sigh. Still it's an improvement over what I had...as long as everyone searches with AND/all words. Crazy

Unfiortunately I've come up with another problem. (Ah, yes. Naturally.) I'm getting returns on words like "the". What's happening?! Doesn't Links have a too common serach words bit?

****
I'm starting a new thread on this, as it seems to be a unique problem.
****

Kathy

Last edited by:

KM: Jan 11, 2005, 11:49 PM