Search Results
<%@ include file="rightcolumncontentheader.html" %>
Please enter a search term.
<%@ include file="footer.html" %>
<%
con.close();
return;
}
else {
//out.println("
");
out.println("
");
out.println("
");
}
PreparedStatement ps1 = null;
PreparedStatement ps2 = null;
if(con!=null){
ps1 = con.prepareStatement("SELECT a.article_id,a.section_id,a.url,a.title, b.code FROM articles a, article_age_group b, age_groups c WHERE a.article_id=b.article_id AND a.status_code='LIV' AND b.code=c.code AND b.code= ? AND ((LOWER(a.url)||'.html') = ? OR LOWER(a.url) = ? ) AND a.section_id= ? " );
ps2 = con.prepareStatement("SELECT a.article_id,a.section_id,a.url,a.title FROM articles a WHERE a.status_code='LIV' AND ((LOWER(a.url)||'.html') = ? OR LOWER(a.url) = ? ) AND a.section_id = ? " );
}
StringBuffer parentSb = new StringBuffer("
Articles for parents\n");
StringBuffer teenSb = new StringBuffer("
Articles for teens\n");
StringBuffer kidSb = new StringBuffer("
TEST THIS\n");
int parentCtr=0,teenCtr=0,kidCtr=0;
StringBuffer allSb = new StringBuffer();
String parentIcon="", teenIcon="", kidIcon="";
//commented out by satish
/**st = con.createStatement();
rs = st.executeQuery("SELECT * FROM sections");
while (rs.next()) {
String sectionName = OtherUtils.noNull(rs.getString("section_name"));
String iconName = OtherUtils.noNull(rs.getString("icon_name"));
if (sectionName.toLowerCase().indexOf("parent") != -1) parentIcon = iconName;
if (sectionName.toLowerCase().indexOf("teen") != -1) teenIcon = iconName;
if (sectionName.toLowerCase().indexOf("kid") != -1) kidIcon = iconName;
}
st.close();**/
parentIcon = "parentarticle_icon.gif";
teenIcon = "teenarticle_icon.gif";
kidIcon = "kidarticle_icon.gif";
int number = 0,lowResult=0,highResult=0;
String nextResults="";
String results="";
boolean ok = true;
if (DEBUG) {
out.println("initial displayedTotal: " + displayedTotal);
out.println("
searchAge: " + searchAge);
out.println("
searchSection: " + searchSection);
}
int firstHit = 0;
firstHit = hitStartInt;
// final int MAXCHARS = 3;
// final String QTCHARS[][] = {{"+","%2B"},
// {" ","%20"},
// {"\"","%22"}};
//Satish Modified for search case-insensitivity
//String qtStr = searchText.replace('\n',' ').replace('\r',' ');
String qtStr = searchText.replace('\n',' ').replace('\r',' ').toLowerCase();
/*****
int ix = 0;
int loopGuard2 = 0;
for (int k=0; k
99) break;
int pos = qtStr.indexOf(QTCHARS[k][0],ix);
if (pos != -1) {
StringBuffer sb = new StringBuffer(qtStr);
sb.replace(pos,pos+1,QTCHARS[k][1]);
qtStr = sb.toString();
ix = pos;
} else ix++;
} catch (Exception e) {}
} // while
} // for
*****/
out.println(" ");
if (isPrev) {
//nextSeekUrl = seekUrl = "http://"+request.getHeader("host")+":"+ultraSeekPort+"/saquery.spy?qt="+qtStr.trim()+"&nh=10&col="+collectionId+"&st="+prevStart;
nextSeekUrl = seekUrl = "http://"+ultraSeekHost+":"+ultraSeekPort+"/saquery.spy?qt="+URLEncoder.encode(qtStr.trim(), "UTF-8")+"&nh=10&col=khclass&st="+prevStart;
}
if (!nextSeekUrl.equals(""))
seekUrl = nextSeekUrl;
else {
if (isHitDB) {
//seekUrl = "http://"+request.getHeader("host")+":"+ultraSeekPort+"/saquery.spy?qt="+qtStr.trim()+"&nh=999999&col="+collectionId+"&st=1";
seekUrl = "http://"+ultraSeekHost+":"+ultraSeekPort+"/saquery.spy?qt="+URLEncoder.encode(qtStr.trim(), "UTF-8")+"&nh=999999&col=khclass&st=1";
}
else {
//seekUrl = "http://"+request.getHeader("host")+":"+ultraSeekPort+"/saquery.spy?qt="+qtStr.trim()+"&nh=10&col="+collectionId+"&st=1";
seekUrl = "http://"+ultraSeekHost+":"+ultraSeekPort+"/saquery.spy?qt="+URLEncoder.encode(qtStr.trim(), "UTF-8")+"&nh=10&col=khclass&st=1";
}
}
//out.println(seekUrl);
if (DEBUG) {
out.println("seekUrl: " + seekUrl);
//out.println("
searchAge: " + searchAge);
//out.println("
searchSection: " + searchSection);
out.println("
");
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
URL url = new URL (seekUrl);
InputStream content = (InputStream)url.getContent();
//BufferedReader in = new BufferedReader (new InputStreamReader (content,"iso-8859-1"));
BufferedReader in = new BufferedReader (new InputStreamReader (content,"utf-8"));
String line;
while ((line = in.readLine()) != null) {
pw.println (line);
pw.println("
");
}
content.close();
} catch (MalformedURLException e) {
pw.println ("Invalid URL");
} catch (IOException e) {
pw.println ("Error reading URL");
}
pw.close();
hitStartInt++;
number=0;
nextResults="";
StringReader sr = new StringReader(sw.toString());
BufferedReader br = new BufferedReader(sr);
String line = "";
String sub = "";
String prevQt = "";
try {
number = Integer.valueOf(getResultVal(sw,"number:")).intValue();
} catch (NumberFormatException nfe) {
if (DEBUG) {
out.println("number format exc converting number
");
}
number = 0;
}
String urlStr = "";
String urlFile = "";
String htmlFile = "";
URL url ;
File file;
results = "";
if (number!=0) {
totalResults = number;
nextResults = getResultVal(sw,"next results:");
results = getResultVal(sw,"results:");
if (!results.equals(""))
{
StringTokenizer stok = new StringTokenizer(results,"-");
String loRange = stok.nextToken().trim();
String hiRange = stok.nextToken().trim();
try {
lowResult = Integer.parseInt(loRange);
highResult = Integer.parseInt(hiRange);
} catch (NumberFormatException nfe) { lowResult=0;highResult=0; }
if (DEBUG) {
out.println("loRange: " + loRange);
out.println("
hiRange: " + hiRange);
out.println("
");
}
}
sr = new StringReader(sw.toString());
br = new BufferedReader(sr);
//boolean isParent,isTeen,isKid,isResearch,isBreaking;
boolean isParent,isTeen,isKid;
boolean isInAgeGroup;;
while ((line=br.readLine()) != null) {
isParent=false; isKid=false; isTeen=false;isInAgeGroup=false;
// parse url
if (line.trim().length() >= "URL:".length()) {
sub = line.substring(0,"url:".length());
if (sub.toLowerCase().equals("url:")) {
urlStr = line.substring("url:".length()).trim();
// do not include printer-version html
//if (urlStr.toLowerCase().indexOf("_prt") != -1) break;
//do not include index.html
//if (urlStr.toLowerCase().equals("index.html") ) break;
//boolean isDup = resultsAL.contains(urlStr);
//if (!isDup) { resultsAL.add(urlStr); }
//else break;
url = new URL(urlStr);
urlFile = url.getFile();
file = new File(urlFile);
String fileParent = file.getParent();
if (DEBUG) {
out.println("
getParent: " + fileParent);
out.println("
url: " + urlStr);
}
int sectionId = 0;
if (fileParent!=null) {
try {
isParent = (fileParent.toLowerCase().substring(1,"parent".length()+1)).equals("parent");
if (isParent)
sectionId = 1;
}
catch (Exception e) { isParent=false; }
try {
isTeen = (fileParent.toLowerCase().substring(1,"teen".length()+1)).equals("teen");
if (isTeen)
sectionId = 2;
}
catch (Exception e) { isTeen=false; }
try {
isKid = (fileParent.toLowerCase().substring(1,"kid".length()+1)).equals("kid");
if (isKid)
sectionId = 3;
}
catch (Exception e) { isKid =false; }
}
//else { isParent = true; }
htmlFile = file.getName().trim().toLowerCase();
if (isHitDB) {
if (!searchAge.equals("ALL")) {
ps1.clearParameters();
ps1.setString(1,searchAge);
ps1.setString(2,htmlFile);
ps1.setString(3,htmlFile);
ps1.setInt(4,sectionId);
rs = ps1.executeQuery();
}
else {
ps2.clearParameters();
ps2.setString(1,htmlFile);
ps2.setString(2,htmlFile);
ps2.setInt(3,sectionId);
rs = ps2.executeQuery();
}
if (rs.next()) {
isInAgeGroup = true;
totalDBResults++;
}
else isInAgeGroup = false;
rs.close();
} else isInAgeGroup = true;
if (isInAgeGroup ) {
String title = "", summary="";
while ((line=br.readLine()) != null) {
title = getResultVal(line,"title:");
if (!title.equals("")) break;
if (title.equals("") && isFound(line,"title:")) break;
}
while ((line=br.readLine()) != null) {
summary = getResultVal(line,"summary:");
if (!summary.equals("")) break;
if (summary.equals("") && isFound(line,"summary:")) break;
}
//////////////Displays results
displayCtr++;
//String icon = "misc_icon.gif";
String icon = "Nbutton.gif";
if(isParent) icon = parentIcon;
if(isTeen) icon = teenIcon;
if(isKid) icon = kidIcon;
//////////////Actual Results
allSb.append(""+(icon.equals("")?"":"") + "" +StrUtils.htmlStrForSearchResults(title)+"" + (isHitDB?totalDBResults:lowResult++)+"
");
allSb.append("" + StrUtils.htmlStrForSearchResults(noLongStrings(summary,95))+ "");
if (DEBUG) out.println("
Found! " + displayCtr + "");
ok = true;
if (DEBUG) {
out.println("
"+file.getParent()+"-");out.println(urlFile);out.println(htmlFile); out.println("
");
if (isParent) out.println("is parent
");
if (isTeen) out.println(" is teen
");
if (isKid) out.println(" is kid
");
} // if debug
} // isinagegroup
}
} // if line
} // while
if (number == highResult) ok = false;
} // if number!=0
else ok=false;
sw.close();
sr.close();
if (DEBUG) {
out.println("
number of articles found: " + number);
out.println("
results: " + results);
out.println("
next results: " + nextResults);
out.println("
hi result: " + highResult);
out.println("
");
}
if(con!=null){
ps1.close();
ps2.close();
con.close();
}
if (isHitDB) totalResults = totalDBResults;
String prevLink="";
String nextLink="";
if (DEBUG) {
out.println("displayctr: " + displayCtr);
out.println("
displayedTotal: " + displayedTotal);
out.println("
firstHit: " + firstHit);
}
if (displayCtr > 0 || displayedTotal !=0) {
if (displayCtr==0 && displayedTotal!=0) {
allSb.append("
K KidsHealth.org");
allSb.append("
KidsHealth.org homepage
");
}
////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////RESULTS START HERE/////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
%>
Search Results
<%
int lowRes = lowResult - 1;
if (isHitDB) lowRes = totalResults;
out.println("
(" + Integer.toString(firstHit) + " to " + Integer.toString(lowRes) + " of " + totalResults + ")" + "
");
%>
<%@ include file="rightcolumncontentheader.html" %>