Hello friends here is my search page for the AUEP Search engine you can see 2 kinds of searching here
1.Normal Search
2.AUEP Search (Searching based on the classification of regions)
And here is the code
Search.jsp
---------------
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%!ResultSet rs = null,rs1 = null;
%>
<% String dbip="";
String dbcon=(String)application.getAttribute("dbcon");
String cip=java.net.Inet4Address.getLocalHost().getHostAddress();
String str = "select * from regions where startip='";
String curreg="";
cip= "127.0.0.1";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ndb");
Statement st = con.createStatement();
rs=st.executeQuery(str+cip+"'");
while(rs.next())
{
dbip=rs.getString("startip");
curreg=rs.getString("region");
}
if(cip.equalsIgnoreCase(dbip))
{
application.setAttribute("yip",cip);
application.setAttribute("dbcountry",curreg);
}
else
{
application.setAttribute("yip",dbip);
application.setAttribute("dbcon",dbcon);
}
}
catch (Exception ex)
{
out.println("Unable to connect to database. " + ex);
}
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>
<style type="text/css">
<!--
.b:hover {background:url(images/templatemo_menu_hover.jpg);}
.b { width: 78px;
background: url(images/templatemo_menu_hover.png) no-repeat 0 0;
height: 41px;
line-height: 29px;
padding: 0;
font-weight: bold;
padding-left: 11px;
color: #fff;
}
.l { width: 106px;
background: url(images/templatemo_menu_hover.jpg) no-repeat 0 0;
height: 44px;
font-weight: bold;
font-size: 25;
color: #fff;
}
.l:hover{background: url(images/templatemo_menu_hover.png) no-repeat 0 0;}
.s {
font-family:Courier, monospace;
font-size: 16px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-decoration: none;
background-repeat: no-repeat;
text-transform: capitalize;
word-spacing: normal;
cursor: auto;
}
-->
</style>
<script type="text/javascript">
function log()
{
alert("Successfully Logout !");
document.location.href="index.jsp";
}
</script>
</head>
<body>
<input type="button" class="l" value="Logout" onclick="log()"/>
<table width="1076" height="413" border="0" class="s">
<tr>
<td height="409"><form id="form1" name="form1" method="post" action="response.jsp">
<div align="center"><h1>Welcome </h1>
<%String un=(String)application.getAttribute("uname");
%>
<h2><font size="5" color="green"><%out.println(un);%><br/>
<%String dbc=(String)application.getAttribute("dbcountry");
out.println("Your ip is :"+cip+"<br/>"+"Your current location is "+dbc);%></font></h2>
<p><h1>Search Content</h1></p>
<p><img src="icon3.gif" width="140" height="121" /></p>
<p>
<label>
<input type="radio" name="radio" id="rbnormal" value="rbnormal" />
Normal Search</label>
</p>
<p>
<label>
<input type="radio" name="radio" id="rbauep" checked="checked" value="rbauep" />
AUEP Search
</label>
</p>
<p>
<input type="text" name="tsearch" id="tsearch" size="75"/>
<input class="b" type="submit" name="bsearch" id="bsearch" value="Search"/>
</p>
</div>
</form></td>
</tr>
</table>
</body>
</html>
1.Normal Search
2.AUEP Search (Searching based on the classification of regions)
And here is the code
Search.jsp
---------------
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%!ResultSet rs = null,rs1 = null;
%>
<% String dbip="";
String dbcon=(String)application.getAttribute("dbcon");
String cip=java.net.Inet4Address.getLocalHost().getHostAddress();
String str = "select * from regions where startip='";
String curreg="";
cip= "127.0.0.1";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ndb");
Statement st = con.createStatement();
rs=st.executeQuery(str+cip+"'");
while(rs.next())
{
dbip=rs.getString("startip");
curreg=rs.getString("region");
}
if(cip.equalsIgnoreCase(dbip))
{
application.setAttribute("yip",cip);
application.setAttribute("dbcountry",curreg);
}
else
{
application.setAttribute("yip",dbip);
application.setAttribute("dbcon",dbcon);
}
}
catch (Exception ex)
{
out.println("Unable to connect to database. " + ex);
}
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>
<style type="text/css">
<!--
.b:hover {background:url(images/templatemo_menu_hover.jpg);}
.b { width: 78px;
background: url(images/templatemo_menu_hover.png) no-repeat 0 0;
height: 41px;
line-height: 29px;
padding: 0;
font-weight: bold;
padding-left: 11px;
color: #fff;
}
.l { width: 106px;
background: url(images/templatemo_menu_hover.jpg) no-repeat 0 0;
height: 44px;
font-weight: bold;
font-size: 25;
color: #fff;
}
.l:hover{background: url(images/templatemo_menu_hover.png) no-repeat 0 0;}
.s {
font-family:Courier, monospace;
font-size: 16px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-decoration: none;
background-repeat: no-repeat;
text-transform: capitalize;
word-spacing: normal;
cursor: auto;
}
-->
</style>
<script type="text/javascript">
function log()
{
alert("Successfully Logout !");
document.location.href="index.jsp";
}
</script>
</head>
<body>
<input type="button" class="l" value="Logout" onclick="log()"/>
<table width="1076" height="413" border="0" class="s">
<tr>
<td height="409"><form id="form1" name="form1" method="post" action="response.jsp">
<div align="center"><h1>Welcome </h1>
<%String un=(String)application.getAttribute("uname");
%>
<h2><font size="5" color="green"><%out.println(un);%><br/>
<%String dbc=(String)application.getAttribute("dbcountry");
out.println("Your ip is :"+cip+"<br/>"+"Your current location is "+dbc);%></font></h2>
<p><h1>Search Content</h1></p>
<p><img src="icon3.gif" width="140" height="121" /></p>
<p>
<label>
<input type="radio" name="radio" id="rbnormal" value="rbnormal" />
Normal Search</label>
</p>
<p>
<label>
<input type="radio" name="radio" id="rbauep" checked="checked" value="rbauep" />
AUEP Search
</label>
</p>
<p>
<input type="text" name="tsearch" id="tsearch" size="75"/>
<input class="b" type="submit" name="bsearch" id="bsearch" value="Search"/>
</p>
</div>
</form></td>
</tr>
</table>
</body>
</html>
It is just design part for the search page the actual code shown below...
NormalSearch.jsp
-------------------
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import ="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.StringTokenizer.*"%>
<%!ResultSet rs = null,rs1 = null;
String results[];
String fname = "";
int i,j;%>
<%
String sw = (String) application.getAttribute("sw");
String swd = (String) application.getAttribute("swd");
StringTokenizer tok=new StringTokenizer(sw," ");
int c=tok.countTokens();
int k=0;
String sw1[]=new String[c];
for(i=0;i<c;i++)
{
sw1[i]=tok.nextToken();
}
String sw2[]=new String[c];
String loc[] =new String[c];
String result = "";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ndb");
Statement st = con.createStatement();
rs1=st.executeQuery("select filename from floc");
while(rs1.next())
{
for(i=0;i<c;i++)
{
if(sw1[i].equalsIgnoreCase(rs1.getString("filename")))
{
sw2[i]=sw1[i];
k++;
}
}
}
for(i=0;i<k;i++)
{
rs = st.executeQuery("select location from floc where filename='" + sw2[i] + "'");
while (rs.next())
{
loc[i] = rs.getString("location");
}
File path = new File(loc[i]);
File files[] = path.listFiles();
if (files != null)
{
for (j = 0; j < files.length; j++)
{
if (files.length == 0)
{
out.println("");
}
else
{
try
{
fname = files[j].toString();
result = result + fname + "#";
}
catch (Exception ee)
{
ee.printStackTrace();
response.sendRedirect("notfound.jsp");
}
}
}
}
else
{
response.sendRedirect("notfound.jsp");
}
}
}
catch (Exception ex)
{
out.println("Unable to connect to database. " + ex);
response.sendRedirect("notfound.jsp");
}
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>
<style type="text/css">
<!--
.b:hover {background:url(images/templatemo_menu_hover.jpg);}
.b { width: 78px;
background: url(images/templatemo_menu_hover.png) no-repeat 0 0;
height: 41px;
line-height: 29px;
padding: 0;
font-weight: bold;
padding-lef: 11px;
color: #fff
}
.s {
font-family:Courier, monospace;
font-size: 16px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-decoration: none;
background-repeat: no-repeat;
text-transform: capitalize;
word-spacing: normal;
cursor: auto;
}
.l { width: 106px;
background: url(images/templatemo_menu_hover.jpg) no-repeat 0 0;
height: 44px;
font-weight: bold;
font-size: 25;
color: #fff;
}
.l:hover{background: url(images/templatemo_menu_hover.png) no-repeat 0 0;}
-->
</style>
<script type="text/javascript">
function log()
{
alert("Successfully Logout !");
document.location.href="index.jsp";
}
</script>
</head>
<body>
<input type="button" class="l" value="Logout" onclick="log()"/>
<table width="1076" height="413" border="0" class="s">
<tr>
<td height="409"><form id="form1" name="form1" method="get" action="response.jsp">
<div align="center"><h1>Welcome</h1>
<%String un = (String) application.getAttribute("uname");
String ip = (String) application.getAttribute("yip");
String dbcountry=(String) application.getAttribute("dbcountry");%>
<h2><font size="5" color="green"><%out.println(un);%><br/>
<%out.println("Your ip is :" +ip+"<br/>"+"Your current location is "+dbcountry);%></font></h2>
<p><h1>Search Content</h1></p>
<p><img src="icon3.gif" width="140" height="121" /></p>
<p>
<label>
<input type="radio" name="radio" id="rbnormal" checked="checked" value="rbnormal" />
Normal Search</label>
</p>
<p>
<label>
<input type="radio" name="radio" id="rbauep" value="rbauep" />
AUEP Search
</label>
</p>
<p>
<input type="text" name="tsearch" id="tsearch" value="<%=swd%>" size="75"/>
<input class="b" type="submit" name="bsearch" id="bsearch" value="Search"/>
</p>
</div>
<%
results = result.split("#");
for (i = 0; i < results.length; i++)
{
File fn = new File(results[i]);
String sfile = results[i].replace('\\', '&');
String filename[] = sfile.split("&");
try
{
BufferedReader br = new BufferedReader(new FileReader(fn));
String line = "";
String pages= filename[filename.length-1].replaceAll(".txt", "");
String add = results[i].replaceAll(" ", "%20");
out.println("<a href=result.jsp?file="+add+">"+pages+"<br></a>");
String content = "";
String address = "";
while ((line = br.readLine()) != null)
{
content=content+line+"\t";
address = line;
}
out.println(content.substring(0, 90)+"<br>");
out.println("<link href=''>" + "<font color='green'>" + address + "</font></link><br><br>");
}
catch (Exception ee)
{
response.sendRedirect("notfound.jsp");
}
}
%>
</form></td>
</tr>
</table>
</body>
</html>
AUEP Search.jsp
--------------------
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import ="java.lang.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.StringTokenizer.*"%>
<%!ResultSet rs = null, rs1 = null, rs2 = null, filtrs = null;
String dbfiles[] = new String[50];
String content[] = new String[100];
String fname[] = new String[50];
String link[] = new String[50];
String dbfiles1[] = new String[50];
String content1[] = new String[100];
String fname1[] = new String[50];
String link1[] = new String[50];
String flag = "";int count=0;%>
<%
String sw = (String) application.getAttribute("sw");
String swd = (String) application.getAttribute("swd");
StringTokenizer tok = new StringTokenizer(sw, " ");
String ipaddr = (String) application.getAttribute("yip");
String str = "select region from regions where startip='";
int c = tok.countTokens();
int i = 0, j = 0, l = 0, l1 = 0, r = 0, r1 = 0, y = 0,f=0;
String dbcon1 = (String) application.getAttribute("dbcon");
String curreg1 = (String) application.getAttribute("dbcountry");
String sw1[] = new String[c];
String sw2[] = new String[100];
String sw3 = sw + " ";
String tem = new String();
String dbreg = "", dbfname = "", dbfname1 = "";
String dbloc = "", dbloc1 = "";
String dbcontent = "", dblink = "", dbcontent1 = "", dblink1 = "";
if (dbcon1.equalsIgnoreCase(curreg1))
{
flag = "0";
}
else
{
flag = "1";
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection("jdbc:odbc:ndb");
Statement st = con.createStatement();
rs = st.executeQuery(str + ipaddr + "'");
while (rs.next())
{
dbreg = rs.getString("region");
}
application.setAttribute("dbreg", dbreg);
filtrs=st.executeQuery("select region from regions");
while(filtrs.next())
{
if(sw.contains(filtrs.getString("region")))
{
if(sw.contains("american"))
{
sw=sw.replace("american","").trim();
dbreg="america".trim();
}
else if(sw.contains("indian"))
{
sw=sw.replace("indian","").trim();
dbreg="india".trim();
}
else
{
sw=sw.replace(filtrs.getString("region"),"").trim();
dbreg=filtrs.getString("region").trim();
}
break;
}
}
sw2[0] = " "+sw;
//out.println(sw2[0]);
for (r = 1, r1 = 1; r <= 5; r++)
{
filtrs = st.executeQuery("select * from filtering where level=" + r);
while (filtrs.next())
{
if (sw3.contains(filtrs.getString("keyword")))
{
tem = sw3.replace(" " + filtrs.getString("keyword") + " ", " ");
sw3 = " "+tem;
}
}
if (!sw2[r1 - 1].equalsIgnoreCase(tem.trim()))
{
if(sw3.trim().equalsIgnoreCase(sw2[0].trim()))
continue;
sw2[r1] = tem.trim();
//out.println(sw2[r1]+"<br/>");
r1++;
}
}
i = 0;
j = 0;
for (y = 0; y < r1; y++)
{
rs1 = st.executeQuery("select location,content,filename,link from" + " " + dbreg + " " + "where keyword='" + sw2[y].trim() + "'" + " " + "order by counter desc");
while (rs1.next())
{
dbloc = rs1.getString("location");
dbcontent = rs1.getString("content");
dbfname = rs1.getString("filename");
dblink = rs1.getString("link");
dbfiles[i] = dbloc;
content[i] = dbcontent;
fname[i] = dbfname.replace(".txt", "");
link[i] = dblink;
i++;
count=count+1;
}
l = i;
rs2 = st.executeQuery("select location,content,filename,link from" + " " + dbcon1 + " " + "where keyword='" + sw2[y].trim() + "'" + " " + "order by counter desc");
while (rs2.next())
{
dbloc1 = rs2.getString("location");
dbcontent1 = rs2.getString("content");
dbfname1 = rs2.getString("filename");
dblink1 = rs2.getString("link");
dbfiles1[j] = dbloc1;
content1[j] = dbcontent1;
fname1[j] = dbfname1.replace(".txt", "");
link1[j] = dblink1;
j++;
count=count+1;
}
l1 = j;
}
if (count == 0) {
count=0;
response.sendRedirect("notfound.jsp");
}
}
catch (Exception ex)
{
out.println("Unable to connect to database. " + ex);
response.sendRedirect("notfound.jsp");
}
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Page</title>
<style type="text/css">
<!--
.b:hover {background:url(images/templatemo_menu_hover.jpg);}
.b { width: 78px;
background: url(images/templatemo_menu_hover.png) no-repeat 0 0;
height: 41px;
line-height: 29px;
padding: 0;
font-weight: bold;
padding-lef: 11px;
color: #fff
}
.s {
font-family:Courier, monospace;
font-size: 16px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-decoration: none;
background-repeat: no-repeat;
text-transform: capitalize;
word-spacing: normal;
cursor: auto;
}
.l { width: 106px;
background: url(images/templatemo_menu_hover.jpg) no-repeat 0 0;
height: 44px;
font-weight: bold;
font-size: 25;
color: #fff;
}
.l:hover{background: url(images/templatemo_menu_hover.png) no-repeat 0 0;}
-->
</style>
<script type="text/javascript">
function log()
{
alert("Successfully Logout !");
document.location.href="index.jsp";
}
</script>
</head>
<body>
<input type="button" class="l" value="Logout" onclick="log()"/>
<table width="1076" height="413" border="0" class="s">
<tr>
<td height="409"><form id="form1" name="form1" method="post" action="response.jsp">
<div align="center"><h1>Welcome</h1>
<%String un = (String) application.getAttribute("uname");
String ip = (String) application.getAttribute("yip");
String dbcountry = (String) application.getAttribute("dbcountry");%>
<h2><font size="5" color="green"><%out.println(un);%><br/>
<%out.println("Your ip is :" + ip + "<br/>" + "Your current location is " + dbcountry);%></font></h2>
<p><h1>Search Content</h1></p>
<p><img src="icon3.gif" width="140" height="121" /></p>
<p>
<label>
<input type="radio" name="radio" id="rbnormal" value="rbnormal" />
Normal Search</label>
</p>
<p>
<label>
<input type="radio" name="radio" id="rbauep" checked="checked" value="rbauep" />
AUEP Search
</label>
</p>
<p>
<input type="text" name="tsearch" id="tsearch" value="<%=swd%>" size="75"/>
<input class="b" type="submit" name="bsearch" id="bsearch" value="Search"/>
</p>
</div>
<%
for (i = 0; i < l; i++)
{
dbfiles[i] = dbfiles[i].replaceAll(" ", "%20");
fname[i].replaceAll(" ", "%20");
out.println("<a href=result1.jsp?file=" + dbfiles[i].replace("/", "\\") + "\\" + fname[i].replaceAll(" ", "%20") + ".txt>" + fname[i] + "<br/>" + "</a>");
out.println("<link href=''>" + content[i] + "<br/>" + "<font color='green'>" + link[i] + "</font></link><br><br>");
count=0;
}
if (flag.equalsIgnoreCase("1"))
{
for (j = 0; j < l1; j++)
{
dbfiles1[j] = dbfiles1[j].replaceAll(" ", "%20");
fname1[j].replaceAll(" ", "%20");
out.println("<a href=result1.jsp?file=" + dbfiles1[j].replace("/", "\\") + "\\" + fname1[j].replaceAll(" ", "%20") + ".txt>" + fname1[j] + "<br/>" + "</a>");
out.println("<link href=''>" + content1[j] + "<br/>" + "<font color='green'>" + link1[j] + "</font></link><br><br>");
}
flag = "0";
}
%>
</form></td>
</tr>
</table>
</body>
</html>
You can see that the page has a similarity with google search engine and here i'm displaying the search page content from my local mysql database but the way of fetching the data is different there is the search engine actually works.That will be discussed later.

No comments:
Post a Comment