Gossamer Forum
Home : Products : DBMan : Customization :

Category and keyword question

Quote Reply
Category and keyword question
Is it possible in the HTML form to input one expression that will be compared against all fields except say a category field, so that the result output will be all incidents of the expression, but only for the specified category. Inputing 'keyword' seems to compare all fields and using any specified filed only allows comparison against the one field. I want to setup a simple form that will allow searches against one expression for all fields except the catgory field to allow users a selection of categories plus a * selection for all categories. How can I do this?

Thanks in advance
Greg
Quote Reply
Re: Category and keyword question In reply to
You would have to make a change to sub query in db.cgi.

Look for

Code:
if ($in{'keyword'}) { # If this is a keyword search, we are searching the same
$i = 0; # thing in all fields. Make sure "match any" option is
$in{'ma'} = "on"; # on, otherwise this will almost always fail.
foreach $column (@db_cols) {
if (($db_sort{$column} eq 'date') or &date_to_unix($in{'keyword'})) { $i++; next; }
if ($i == $auth_user_field) { $i++; next; }
push (@search_fields, $i); # Search every column
$in{$column} = $in{'keyword'}; # Fill %in with keyword we are looking for.
$i++;
}
}

Change it to

Code:
if ($in{'keyword'}) { # If this is a keyword search, we are searching the same
$i = 0; # thing in all fields. Make sure "match any" option is
$in{'ma'} = "on"; # on, otherwise this will almost always fail.
foreach $column (@db_cols) {
if (($db_sort{$column} eq 'date') or &date_to_unix($in{'keyword'})) { $i++; next; }
if ($i == $auth_user_field) { $i++; next; }
push (@search_fields, $i); # Search every column
unless ($column eq "Category") {
$in{$column} = $in{'keyword'}; # Fill %in with keyword we are looking for.
}
$i++;
}
}

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







[This message has been edited by JPDeni (edited July 11, 1999).]
Quote Reply
Re: Category and keyword question In reply to
Thanks for the prompt response. I really appreciate the assistance Smile.

The patch outputs both incidents of the keyword and category, which gives me a list of where either appears. I need both to be equal.

My apologies. Perhaps I have not explained myself correctly. I would like an option to search within a particular category only, so that the result is a list of records where keyword appears in any other field, but only within the the specified category.

An example would be.

Give me the records within Real Estate where the word 'beachfront' appears, even though 'beachfront' may appear in Name, Address, Description etc.

The result does not display records where 'beachfront' appears within the say Accommodation or Business category.

I hope this is easier to understand.
Thanks in advance again.
Greg



Quote Reply
Re: Category and keyword question In reply to
No. My apologies. Smile I realized just today when I woke up that the code I gave you wouldn't work.

I'm not sure how to get it to work. The keyword search has to have "Match Any" set, which will give you what you got from my wrong code.

I'm afraid that the searching section of db.cgi is the one part of the script I don't fully understand as yet. If I come up with a solution, I'll let you know.


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





Quote Reply
Re: Category and keyword question In reply to
Thanks for the assistance so far. I have in the meantime created a page that allows user selection of town and category and then I input the name. This is not ideal, but it works well. I do need to ask you one more question though if I may.

In a previous posting you incliude the following code to assist with phrase searching:

foreach $column (@db_cols) {
if ($in{$column} =~ / or /) {
$in{$column} =~ s/ or /\|/;
$in{'re'} = 'on';
}
}
if ($in{'keyword'} =~ / or /)
{
$in{'keyword'} =~ s/ or /\|/;
$in{'re'} = 'on';}

It work fine except if you include say a '+' in the seach phrase. The '+' crashes the cgi. Have you done any changes to the code since posting this code?
Thanks in advance
Greg

Quote Reply
Re: Category and keyword question In reply to
No. I didn't have any thought about adding a "+". What are you trying to accomplish?

Is there likely to be a "+" in the field value?

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





Quote Reply
Re: Category and keyword question In reply to
Hi Again,

I setup a results page with access to a flat file database for a local cycle race. Within the first hour 5 guys had type "name + surname" in the keyword field even though I specified: Search by name, surmane or number.

It's a given that users will type in excatly what you don't want them to or am I missing something here Smile.

I did solve the original problem temporarily by creating an additional field called 'search'. This field contains a copy of all fileds. In this way I can search one field for all words and being a regular feild search the 'By category or twon' works well.

Given time I will add to the script to add these fields automatically when you add and modify so it won't have to be done manually.

If you do have a modification the your original 'phrase' code that discards or includes the + please let me know.

I do use htdig and I'm sure there is a routine in there wrapper script that does this. I'll see if I can hack it out.

Thanks again. Till later
Greg
Quote Reply
Re: Category and keyword question In reply to
Well, if you just want to strip out a +, you can do that.

In db.cgi, sub parse_form, after

Code:
$value =~ s/<!--(.|\n)*-->//g; # Remove SSI.

add

Code:
$value =~ s/\+//g;

That should make it so no + signs get through at all.


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