Gossamer Forum
Home : Products : DBMan : Customization :

Boolean MOD cross-fields fix?

Quote Reply
Boolean MOD cross-fields fix?
I think I might have a solution to those who are having problems with the Boolean MOD and the ability to search for "AND" across fields.

As I understand it, the MOD only allows people to find things like "cats AND dogs" if "cats / dogs" appears in the same field. It would not find something like Field1=Cat and Field2=Dog because it doesn't search across fields (please let me know if this has been fixed).

Anyway, since I have a very real need for a search engine that can go across fields with an AND (I don't really care about OR or anything else), I've put together a rather simple modification (I think).

I should note here one important thing--I have never programmed in PERL before. I'm not a script genius or anything. I just bought the Perl Camel book last night and went through the db.cgi script line by line looking up everything I didn't understand (kind of like reading a foreign newspaper with a dictionary--very slow).

Anyway, the suggestions offered in the BOOLEAN thread were helpful, that of smushing all fields into one line and then searching that line for the data. But in reading through the code, I found that the dbman program split the LINE into several different VALUES and then searched the VALUES against the keyword input. I just decided to skip that step.

Here's what the db.cgi file says "out of the box"

# Now we go through the database and do the actual searching.
# First figure out which records we want:
$first = ($maxhits * ($nh - 1));
$last = $first + $maxhits - 1;

open (DB, "<$db_file_name") or &cgierr("error in search. unable to open
database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);


Now, what I did was change the last line so that it doesn't access the subroutine:

@values = ($line);

If you load that up and do a search, it will find the records you want, across all fields, BUT it will print out the records with all the data in one field (not very attractive). Thus I had to find a place to split the data again before printing. What I did is added it at at this point:

# Did we find a match? We only add the hit to the @hits array if we need it. We can
# skip it if we are not sorting and it's not in our first < > last range.
if ($key_match || (!($in{'keyword'}) && !($in{'ma'}))) {{@values = &split_decode($line);
}


I added {@values = &split_decode($line);
} into that line and that handles the spliting up of the values prior to the printout.

I think this works for AND searches (which is what I needed). I don't know how this will affect other searches (I think it might really mess them up) but you could just run two copies of dbman (dbman1 and dbman2--one for keyword boolean searches and another for searches within fields).

Like I said, I've never done stuff like this before, so I'm more than happy to hear any suggestions or comments. I just wanted to make this work.

Andrew



Quote Reply
Re: Boolean MOD cross-fields fix? In reply to
Andrew,

Could I get a copy of the Boolean Mod 1.1 or whatever version you feel is best? The mod is no longer available on the forum from leisurelee.net.

Thanks very much for your help!

Tommy
tgardner@tgardner.com

Quote Reply
Re: [penguinradio] Boolean MOD cross-fields fix? In reply to
Great mod penguinradio . One slight caveat...

If you have two different types of search, one for the default user (i.e. keyword only) and an advance search (individual fields) for say admin, then you need to enclosed your last 2 changes with "if" statements. e.g.


Code:
if($in{'bool'}) {
@values = ($line);
}else{
@values = &split_decode($line);
}
and

Code:


if($in{'bool'}) {
if ($key_match || (!($in{'keyword'}) && !($in{'ma'}))) {{@values = &split_decode($line);
}
if (exists $in{'sb'}) {
$sortby{(($#hits+1) / ($#db_cols+1))} = $values[$in{'sb'}];
push (@hits, @values);
} else {
(($numhits >= $first) and ($numhits <= $last)) and push (@hits, @values);
}
$numhits++; # But we always count it!
}
}else{
if ($key_match || (!($in{'keyword'}) && !($in{'ma'}))) {
if (exists $in{'sb'}) {
$sortby{(($#hits+1) / ($#db_cols+1))} = $values[$in{'sb'}];
push (@hits, @values);
} else {
(($numhits >= $first) and ($numhits <= $last)) and push (@hits, @values);
}
$numhits++; # But we always count it!
}
}


That way you get the best of both worlds.

If using this, then in the html.pl file (sub html_search_options), you should set bool="" as the default for the advanced user (indivual fields) search.

Brian
Quote Reply
Re: [omegadm] Boolean MOD cross-fields fix? In reply to
This looks lke something i'd like to use. I tried it but where mine went wrong is this: if one of the fields is a keyword field, it will just show everyting, even if it says AND for the boolean thing.

For example: show me all items in the category 'fairytales' that have te word "apple" in them. The result will give me all apples, as well the ones in "fruit", and not stick to just snow white etc.

I guess that's because of some special status for keyword searches, I'll try fnding it but maybe someone here knows this and can point me in the right direction.