Gossamer Forum
Home : Products : DBMan SQL : Discussion :

searching for multiple words

Quote Reply
searching for multiple words
Hello,

I've just realized that I can only search for one word, or more than one word as long as these words are in the right sequence, in other words, they are treated like a phrase. If I search for multiple words that are not adjacent to each other, it returns nothing. This is not supposed to be the way, is it? Am I missing something important?

Thanks
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] searching for multiple words In reply to
Hi,

Just modify letter_search subroutine in LetterSearch plugin which I sent you:

....
my $db = $home->{cgi}->{db};
my $table = $DB->table($db);
$table->select_options("Order by $column",$limit);
my $cond;
my $words = [split /\s/,$letter];
$cond = GT::SQL::Condition->new ();
$cond->{bool} = 'OR';
foreach (@$words) {
($_) and $cond->add($column,'LIKE',"%$_%");
}
my $sth = $table->select ($cond);
my $hits = $table->hits();
....
And then create a link db.cgi?do=search_results&db=<%db%>&let=black%20white&col=column_name or you can create a form for searching words.

Hope that helps,

TheStone.

B.
Quote Reply
Re: [TheStone] searching for multiple words In reply to
Hello,

Thanks for the quick response. But I didn't mean it was in the letter_search section, whcih works fine. I mean searching multiple words in the regular title field or in the keyword field. I tried searching in your demo for the image_gallery and found the same. For example, in the demo keyword search, if I search for: golden gate bridge, it returns 3 hits. But if I search for golden bridge, I got nothing. Strange.
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] searching for multiple words In reply to
Hi,

DBMan SQL doesn't support for searching words (colum like '%word1%' or column like '%word2%'..), so you have to create a plugin for that. It kind of likes the scripts in my last posted, you just change a little bit.

Cheers,

TheStone.

B.

Last edited by:

TheStone: Jan 18, 2002, 10:26 AM
Quote Reply
Re: [TheStone] searching for multiple words In reply to
Thanks. That clarifies it.

I am really not up to the task, though, and will really have rely on your expertise. Please take a look at: http://www.indiana.edu/~libej/new.html . All I really need for now is to be able to search for multiple words that are not adjacent to each other in the title field.

I don't want to make any changes in the letter_search subroutine, which is exactly want I want.

Thanks a lot.
Jian Liu
Indiana University Libraries
Quote Reply
Re: [jiliu] searching for multiple words In reply to
Hi,

Alright, just make a little change:

....
my $db = $home->{cgi}->{db};
my $table = $DB->table($db);
$table->select_options("Order by $column",$limit);
my $cond = GT::SQL::Condition->new ();
if ($home->{cgi}->{mul}) { #search words
my $words = [split /\s/,$letter];
$cond->{bool} = 'OR';
foreach (@$words) {
($_) and $cond->add($column,'LIKE',"%$_%");
}
}
else { # search starting with a letter
$cond->add($column,'LIKE',"$letter%");
}
my $sth = $table->select ($cond);
my $hits = $table->hits();
....

It should work for both, if you wanna search words then pass mul=1 or add <input name=mul value=1 type=hidden> in your search form.

Cheers,

TheStone.


B.

Last edited by:

TheStone: Jan 18, 2002, 10:53 AM
Quote Reply
Re: [TheStone] searching for multiple words In reply to
Aha, now it is working. It also seems to have resolved the problem I reported at http://www.gossamer-threads.com/...orum.cgi?post=177630

I really appreciate it. Thank you.

BTW, I changed the boolean operator to an "AND", which is what I want.

I am still puzzled with the record-merging part. I'll probably ask for help later. But for now, I am happy. :-)
Jian Liu
Indiana University Libraries

Last edited by:

jiliu: Jan 18, 2002, 11:37 AM
Quote Reply
Re: [TheStone] searching for multiple words In reply to
Hi Where can I get a copy of the letterSearch mod? Wink
Reena
Quote Reply
Re: [Reena0330] searching for multiple words In reply to
Have a look at:
http://www.gossamer-threads.com/...orum.cgi?post=192816

B.
Quote Reply
Re: [TheStone] searching for multiple words In reply to
Wouldn't it be a good idea to add this plugin (LetterSearch) to the DBMan SQL Resource section and the GT Plugin Download??
Quote Reply
Re: [jai] searching for multiple words In reply to
I've been thinking about it. Actually, the keyword search plugin hasn't finished yet. I think that more features should be added.

I cannot say when it will be done, 'cause I'm a little loaded down right now.

TheStone.

B.
Quote Reply
Re: [jai] searching for multiple words In reply to
You can check it out at your download plugin area Wink

TheStone.

B.