Gossamer Forum
Home : Products : DBMan : Customization :

Simultaneous field searching

Quote Reply
Simultaneous field searching
I would like a search option on the user interface to search more than one field (but not all). I want to ALSO have the keyword search, which would search all fields.

Is there a simple solution, preferabley in the html file, but I can adit the cgi file if I have to... maybe something like this:

<INPUT TYPE="TEXT"
NAME="Author, Title" VALUE="$rec{'Author', 'Title'}" SIZE="40"
MAXLENGTH="255">

Except that it would work?

The exact example is a sheet music database. I want the user to be able to find "ode to joy" by entering a title search on either "ode to joy" OR "An die freude," etc. But I want the alternative titles to be in separate fields, if possible.

Thanks in advance.
Quote Reply
Re: Simultaneous field searching In reply to
Well, it will not work the way you have written it.

What you can do is use only a few fields (including the keyword field) in your search form, like the following:

Code:
Author: <input type="text" name="Author" size="40">
Title: <input type="text" name="Title" size="40">
Keywords: <input type="text" name="keyword" size="40">

I have created a sub-routine in the html.pl file called sub html_search_form. I have included only the fields that I want to search for.
Then in the sub view_search routine, I have replaced html_record with html_search_form.

Hope this helps.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Simultaneous field searching In reply to
thanks, Eliot, but I guess I didn't explain what I want to do very well.

I want these separate fields:

Uniform Title
Alternative Title
Title of Larger Work

for the admin mode. That part is easy. But I want the end user to have only a title field to fill in that would search all three filed in the db file. So the user wouldn't have to know that

Symphony no. 9, Opus 125

is actually the title of the larger work.

Does that make more sense? The user could type in "Ode to Joy" in the title field and the record would come up regardless of that being the Uniform Title, Alternative Title, or the Title of Larger Work

It would be like a keyword search, but it wouldn't search all the fields, only three of them.
Quote Reply
Re: Simultaneous field searching In reply to
If you don't mind my asking, whats the harm in searching all fields..?
Quote Reply
Re: Simultaneous field searching In reply to
If there's no easy way to do this, I probably will just include a keyword search for the user to look for a title.

I'm doing this for the music librarian, and that's how she asked me to do it, so I'm trying to comply with what she wants.

But there could be a few problem searhcing across all the fields. For example, when I used dbman to arrange the library's indexes and databases, and I was using a keyword search. Users looking for the database "ERIC" had to sift through three pages of things published by "the AmERICan academy..."

I don't know if our sheet music has anything that would create similar problems, i.e. a publisher called "Sonata Publications." then, if a user was looking for a sonata using keyword search, they would have to sift through those by that publisher also. I'm not familiar enough with the collection to know if that will be a problem.
Quote Reply
Re: Simultaneous field searching In reply to
Ok I think this will work for you... it is kink of clunky but it will do what you want...

####CHANGE#####
Insert the following sub-routine in the appropriate db_html.pl, originally I said to put it in the db.cgi but that would not be the best idea if you ever start to use more than one database.

Code:
sub combined_field_search {
# --------------------------------------------------------
# This sub will let you search on specific fields
# from just one field in the search form. The
# name in the search form must be unique, meaning
# that it can not be the same name as any of your
# fields in the db.cfg.

# Set this to the unique name from the search form
### SET THIS VARIABLE ###
my ($search_term) = 'city_search';

# Set this list below to match the field names that you
# would like to search from your one input field.
# The list should be seperated with commas and each
# field should be enclosed with singe quote "'".
### SET THIS VARIABLE ###
my (@multi_fields) = ('city','cities');

# Check to see $search_term was even queried
# if not then we don't need to do anything
if (!$in{$search_term}) { return; }

# Now we know that we are going to need to search
# more than one field on this search so we
# are going to populate the $in variable as if the
# search was made individually for each field
my ($field);
foreach $field (@multi_fields) {
$in{$field} = $in{$search_term};
}
# If Match Any is off this search will only
# return the records where all of the fields
# contain the search term.
$in{'ma'} = 'on';
}

Then in the "sub view_records" add the following code just above the line that reads:
my ($status, @hits) = &query("view");

Code:
# Added this sub to populate the $in variable
# with some more search fields if neccessary
&combined_field_search;

So your sub view_records should look like this: (You could actually just replace the sub with the code below)
Code:
sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.

# Added this sub to populate the $in variable
# with some more search fields if neccessary
&combined_field_search;

my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure($status);
}
}

Now in your db.html search form you should set up your input line so that the name matches the name you assigned to $search_term above. In the code above it is assigned "city_search":

Example:
<input type="text" name="city_search" size="40">

Got it?

Good luck,
Steve Plant


------------------
_____________________________________
OutreachONE Media Services
www.or1.com

[This message has been edited by StevePlant (edited October 13, 1999).]

[This message has been edited by StevePlant (edited October 14, 1999).]
Quote Reply
Re: Simultaneous field searching In reply to
Thank you so much for that, Steve!! I don't know if I got it or not, but I will try and let you know.

You all are so helpful.
Sigrid
Quote Reply
Re: Simultaneous field searching In reply to
... that worked beautifully. Thank you again. If you want to see it (a very rough, in progress work) its at http://www.lib.lsu.edu/cgi-bin/dbman/dbman/music.cgi?db=music&uid=default

Quote Reply
Re: Simultaneous field searching In reply to
Your welcome, and I'm glad it worked for you!!

I'll check back to your site once you get a few more records in there, but it looks like it works fine.

B/R
Steve Plant





------------------
_____________________________________
OutreachONE Media Services
www.or1.com

Quote Reply
Re: Simultaneous field searching In reply to
Steve, still working great... I think you should put it in the "Resource Center" section. I do have one more question- please forgive my total ignorance of cgi. How would I do more than one? For example, now I also want to creat a "Name" field that will search all the "composer" "performer" "arranger", etc. fields. How can this be done?

Also, just a small note... I have the add-on from the resource center that only displays fields that are filled in. With this script, it displays all the fields under the larger one, regardless of whether they are empty. i.e. if I don't have an "Alternate Title" (see above), it still displays that field. This is no biggie, just an observation.

Quote Reply
Re: Simultaneous field searching In reply to
The above works if it works independently.....

However, if used along with other fields as well, it almost return all kinds of records, as if it automatically turns "Match Any" on....

e.g. if I have the following fields:
Make, Model1, Model2

let's say I have a field named "ModelSearch" in my search form, and "ModelSearch" is pointed to the fields "Model1" & "Model2".

If I have the following records:
Make, Model1, Model2
Chrysler Neon LX
Chrysler LX Intreprid
Chrysler Intreprid ES
Chrysler Cirrus LX

and in my search form, I have Make=Chrsyler and ModelSearch=Intreprid.....

Instead of only showing record 1 and 2, the thing will return all the records shown above! because I have the additional field Make=Chrysler. I have "Match Any" turned off.

Is there any way around it? or is there other places in this forum that discusses this?