Gossamer Forum
Home : Products : DBMan : Installation :

keyword search

Quote Reply
keyword search
i have a keyword search function specified. this is different from the keyword search specified by alex as i dont want to search the whole database only two specific fields. At the same time I want to keep Alex's generic keyword search.

How can i specify this 2 field search in the search form, lets say we call the 2 fields 'keywords' and 'item'. I will rename alex's keyword to 'allwords' to save confusion.



------------------
cybergaz
Quote Reply
Re: keyword search In reply to
Whatever you do, don't rename Alex's "keyword" field to anything else! The db.cgi script uses this extensively and it won't work if you do.

To make sure I understand, you want users to be able to enter text into one text field, and the script will do a search for that text in two fields. Right? Do you want the search to return records where the text is in both fields or in either field? The code for "either field" is below, but marked. Take the line out if you want the text to be in both fields.

I'll stay with your choice of "keywords" and "item" for the field names, but you'll need to be careful about typos. Be sure you use the right fieldname.

Let's call your field for searching on two fields "keys2" to avoid confusion. If you name it something else in your form, change it in the code below as well.

In db.cgi, sub query

after

local (%sortby);

add

Code:
if ($in{'keys2'}) {
$in{'keywords'} = $in{'keys2'};
$in{'item'} = $in{'keys2'};
$in{'ma'} = "on"; # take this line out if you want the words to match on both fields
}



------------------
JPD





Quote Reply
Re: keyword search In reply to
thanks yet again JP

the function is indeed to search on either field as you surmised. can i actually prioritise this to search the 'item' field first, or is it just a case of first come first served.

many thanks again

------------------
cybergaz
Quote Reply
Re: keyword search In reply to
Sorry. There's no way to prioritize the search. That would take some mind-boggling scripting that my poor old brain can't even imagine right now. Smile



------------------
JPD





Quote Reply
Re: keyword search In reply to
Time for some debugging, then.

In html_view_failure, after

<BR>Please fix any errors and submit the record again.</p>

add (before the |; )

$in{'newkey'}\n
$in{'keywords'}\n
$in{'item'}

See if you get three rows of the same text that you entered into the "newkey" field. Let me know what happens.

Just in the offchance, are you sure your fields are named "keywords" and "item" and not something like "Keywords" and "Item"?


------------------
JPD





Quote Reply
Re: keyword search In reply to
JPD

i entered the code you gave me changing keys2 to newkey, unfortunately it does not seem to work as i get a search failed - no search terms specified message:

here is how i have input it in dg.cgi

# First let's get a list of database fields we want to search on and
# store it in @search_fields

my ($i, $column, @search_fields, @search_gt_fields, @search_lt_fields, $maxhits, $numhits, $nh,
$field, @regexp, $line, @values, $key_match, @hits, @sortedhits, $next_url, $next_hit, $prev_hit,
$first, $last, $upper, $lower, $left, $right, $restricted);
local (%sortby);

# keyword search on fields 'keywords' and 'item' using input 'newkey'
if ($in{'newkey'}) {
$in{'keywords'} = $in{'newkey'};
$in{'item'} = $in{'newkey'};
$in{'ma'} = "on";
}


and here is how i have specified it in html.pl

<input name="newkey" type="text" size=30 maxlength=255>

any ideas.

------------------
cybergaz
Quote Reply
Re: keyword search In reply to
blast blast and double blast.

nobody likes a clever clogs you know. except me. how stupid can i be. i should know better by now to check things like that. yes it was init caps in the .cfg file. i just followed alex's pattern of intit caps and forgot about it. normally i dont use caps, as you can see here.

i am now going to make a list of items to check for if things dont work.

thanks at least for focusing me jp.



------------------
cybergaz
Quote Reply
Re: keyword search In reply to
pursuant to the previous.

i had assumed that this function would mean that the 'newkey' search request would then only search on the two fields specified. however it is still searching every field in the database. how can i turn that off?



------------------
cybergaz
Quote Reply
Re: keyword search In reply to
It shouldn't be searching every field unless you have something in the "keyword" field.

To be sure, you can add another line.

After

$in{'ma'} = "on";

add

$in{'keyword'} = "";

Give that a shot.


------------------
JPD