View Full Version : Customized Keyword Search using Java Script
Triadfad
Apr-19-2009, 11:49 AM
I shoot sporting events and have need to create a customized search bar in my SmugMug site. I have read several threads from people like Pat Kene, JCMX, and Devbobo. All of them are good but I can't get my JS working. I know it has something to do with it not capturing all of the variables and passing them to the Keyword URL but I can't figure out how to make that happen. Below is the JS and HTML I'm using.
Any help is appreciated....
27162
jfriend
Apr-19-2009, 11:57 AM
It looks to me like your script isn't in <script> tags. We could offer better help if you could give us a link to the actual page where you are trying this.
Triadfad
Apr-20-2009, 04:42 PM
It looks to me like your script isn't in <script> tags. We could offer better help if you could give us a link to the actual page where you are trying this.
Sorry.... Here is the site: www.jarandell.smugmug.com (http://www.jarandell.smugmug.com)
I didn't have the search bar in place becuase it wasn't working and I didn't want to cause confusion for my clients. I'll go ahead a post it so you can see what it is doing. Thanks for the help...
Also, if you enter in just a last name, like: Randell
and press "search" it works. It just does not work with any other single word searches or multiple, combination searches.
jfriend
Apr-20-2009, 05:14 PM
Sorry.... Here is the site: www.jarandell.smugmug.com (http://www.jarandell.smugmug.com)
I didn't have the search bar in place becuase it wasn't working and I didn't want to cause confusion for my clients. I'll go ahead a post it so you can see what it is doing. Thanks for the help...
Also, if you enter in just a last name, like: Randell
and press "search" it works. It just does not work with any other single word searches or multiple, combination searches. You'll have to be more specific about what doesn't work.
If I put "duathlon" into the Last Name field and select "Run" from the Event type, I get this page which is what it is supposed to be:
http://www.jarandell.smugmug.com/keyword/run-duathlon
If I put two words into the Last Name field separated by a space, it does not work because you are not forming the keyword URL properly. Multiple keywords must be separated with a "-" in the URL with no spaces.
If I just pick "Thin Blue Line" for the Race, it doesn't work either because it makes the wrong URL with two dashes at the end like this: http://www.jarandell.smugmug.com/keyword/tbl--. If I edit off the two extra dashes at the end, it all works.
You have it all there, you just need to make sure that no matter what data is entered by the user, you get a series of keywords with a single dash between each one. You need to plan for all possible combinations of data entry and anything that they can type in the editable fields.
For example, if I type "hane sowles" into the Last Name field, it finds nothing because the URL is wrongly constructed. If I edit the URL to have a dash between the words instead of a space between the words, it all works.
Triadfad
Apr-20-2009, 07:01 PM
Thanks John... I know the JS is not coded correctly for what I'm trying to achieve. You're absolutely correct in that I must account for all possible entires into the free form fields.
Here are the requirements for what I'm trying to achieve with the JS search:
1. Client should be able to search by race number using 1 to 4 bytes to find their photos. Example: 7, 67, 176, or 1078
2. Client should be able to search on a combination of one or more fields to find their photos. Example: RACE NUMBER: 7 EVENT: duathlon
3. Client should be able to search on all fields to find their photos. Example: RACE NUMBER: 7 RACE: MIO EVENT: candid LAST NAME: franklin
4. The LAST NAME field should allow for multiple keyword entries if the client decides to enter in "more" than just their last name. I did not test for that; "Good Catch" on your part. :wink
My over arching goal in using this search is the help the client find their photos quickly using a narrow search string. RACE NUMBER, and EVENT, are not enough to make their searches quick and accurate. The LAST NAME field is used so I can have subsequent photo sells from past races. Example.... Let's say that I have 5 years worth of races on SmugMug and I have shot Sally Smugger in 7 different races over the course of those 5 years but she's never purchased a photo. One day Sally wants to do a photo book of all her races so she logs onto my site and enters her LAST NAME: "smugger" into the "last name" field. Becuase I've tagged all Sally's photos with her last name she finds "all" her pictures over the last 5 years. Ching Ching $$$$ :thumb
jfriend
Apr-20-2009, 08:34 PM
Thanks John... I know the JS is not coded correctly for what I'm trying to achieve. You're absolutely correct in that I must account for all possible entires into the free form fields.
Here are the requirements for what I'm trying to achieve with the JS search:
1. Client should be able to search by race number using 1 to 4 bytes to find their photos. Example: 7, 67, 176, or 1078
2. Client should be able to search on a combination of one or more fields to find their photos. Example: RACE NUMBER: 7 EVENT: duathlon
3. Client should be able to search on all fields to find their photos. Example: RACE NUMBER: 7 RACE: MIO EVENT: candid LAST NAME: franklin
4. The LAST NAME field should allow for multiple keyword entries if the client decides to enter in "more" than just their last name. I did not test for that; "Good Catch" on your part. :wink
My over arching goal in using this search is the help the client find their photos quickly using a narrow search string. RACE NUMBER, and EVENT, are not enough to make their searches quick and accurate. The LAST NAME field is used so I can have subsequent photo sells from past races. Example.... Let's say that I have 5 years worth of races on SmugMug and I have shot Sally Smugger in 7 different races over the course of those 5 years but she's never purchased a photo. One day Sally wants to do a photo book of all her races so she logs onto my site and enters her LAST NAME: "smugger" into the "last name" field. Becuase I've tagged all Sally's photos with her last name she finds "all" her pictures over the last 5 years. Ching Ching $$$$ :thumb I understand what you are trying to do. What exactly are you asking for help with?
Triadfad
Apr-21-2009, 01:51 PM
I need someone to help me code the JS correctly to meet my requirments. This code does not work:
27180
jfriend
Apr-22-2009, 09:11 PM
I need someone to help me code the JS correctly to meet my requirments. This code does not work:
27180
OK, here's some new code that I think does what you need. It allows multiple parameters to be specified in either the race or name field and the multiple parameters can be separated by either spaces, commas or dashes. The user can specify 1, 2, 3 or all 4 fields. If no fields are specified, the search button just doesn't do anything.
function processMultiples(str)
{
var newStr = str.replace(/,|-/g, " "); // replace commas or dashes with spaces (so they can be used as a delimiter between multiple search params)
newStr = TrimString(newStr); // remove leading or trailing spaces
return(newStr.replace(/\s+/g, "-")); // replace any sequence of one or more consecutive spaces with a single dash
}
function addNewParam(resultSoFar, newParam)
{
var newResult = resultSoFar;
if (newParam && (newParam != ""))
{
if (resultSoFar != "")
{
newResult += "-";
}
newResult += newParam;
}
return(newResult);
}
function doTheSearch()
{
var raceNumber = document.racesearch.number.value;
var race = document.racesearch.race.options[document.racesearch.race.selectedIndex].value;
var eventType = document.racesearch.event.options[document.racesearch.event.selectedIndex].value;
var name = document.racesearch.lname.value;
raceNumber = processMultiples(raceNumber);
name = processMultiples(name);
var newUrl = "";
newUrl = addNewParam(newUrl, raceNumber);
newUrl = addNewParam(newUrl, race);
newUrl = addNewParam(newUrl, eventType);
newUrl = addNewParam(newUrl, name);
if (newUrl != "")
{
window.location = "/keyword/" + newUrl;
}
}
Triadfad
Apr-23-2009, 09:11 AM
John.... you're the BEST!!!! In my initial testing everthing appears to be working GREAT!!! It's Smuggers like you who make this application "all-it-can-be!" and should be highly recognized for your efforts!!!!
Hat's off to you and your skills :clap
vBulletin v3.5.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.