microgao - by - 16 六月, 2006 16:55

页面1:

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="org.apache.lucene.analysis.*"%>
<%@ page import="org.apache.lucene.analysis.standard.*"%>
<%@ page import="org.apache.lucene.search.*"%>
<%@ page import="org.apache.lucene.queryParser.*"%>
<%@ page import="org.apache.lucene.document.*"%>
<%@ page import="java.util.*"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title></title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<link href="../../include/style.css" rel="stylesheet" type="text/css">
<body>
<br>
<br>
<%
Analyzer anlzr = new StandardAnalyzer();

try{


String contentget =request.getParameter("content");
//
Query q = QueryParser.parse(contentget, "contents", anlzr);

//System.out.println("Searching for : " + q.toString("contents"));



Searcher serch = new IndexSearcher("C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex");


Hits hts = serch.search(q);

for(int i=0; i<hts.length(); i++){
Document doc = hts.doc(i);
String path = doc.get("path");
// System.out.println("Find: " +(i+1)+": "+ path);
//System.out.println("Find: " + doc.get("modified"));
//System.out.println("Find: " + doc.get("path"));
String[] pathes=path.split("");
path=pathes[pathes.length-1];
out.print("<a href='files"+path+"'>"+path+"</a><br>");
out.print("<br>");

}
out.print("一共找到: " + hts.length()+"个文件");
//System.out.println("Find Total: " + hts.length());
serch.close();
}catch(Exception e){
System.out.println(e);
}
%>
</body>
</html>
*************************************************************

页面2:


<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="org.apache.lucene.index.*"%>
<%@ page import="org.apache.lucene.analysis.standard.*"%>
<%@ page import="org.apache.lucene.document.*"%>
<%@ page import="java.io.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>


<title>My JSP 'search_main.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<link href="../../include/style.css" rel="stylesheet" type="text/css">
<body>

<p>
<%

try{

boolean indexExist = IndexReader.indexExists("C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex");
if(indexExist)
{
String path = "C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex";
java.io.File[] entries = new java.io.File(path).listFiles();
for (int index = 0; index < entries.length; index++)
{
//System.out.print("index is Exist,need delte");
entries[index].delete();
}
response.sendRedirect("search_main.jsp");
// IndexWriter writer = new IndexWriter("C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex", new StandardAnalyzer(), true);
}
else
{

IndexWriter writer = new IndexWriter("C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex", new StandardAnalyzer(), true);


//IndexWriter writer = new IndexWriter("C:eclipseworkspacegyfedaWebRootbusinessdocumentmyindex", new StandardAnalyzer(), true);

File files = new File("C:eclipseworkspacegyfedaWebRootbusinessdocumentfiles");

String[] Fnamelist = files.list();
for (int i = 0; i < Fnamelist.length; i++){

File file = new File(files,Fnamelist[i]);

Document doc = new Document();
Field fld = Field.Text("path", file.getPath());
doc.add(fld);

fld = Field.Keyword("modified", DateField.timeToString(file.lastModified()));
doc.add(fld);

FileInputStream in = new FileInputStream(file);
Reader reader = new BufferedReader(new InputStreamReader(in));
fld = Field.Text("contents", reader);

doc.add(fld);

writer.addDocument(doc);
//System.out.println("Added : " + doc.get("path"));

}

writer.optimize();
writer.close();

// System.out.println("Has Added Total: " + Fnamelist.length);



}

}catch(Exception e){
System.out.println(e);
}
%>
</p>
<p>&nbsp; </p>
<form action="search_creat.jsp" method="post" name="form1" id="form1" >
<p></p>
<p>&nbsp; </p>

<table width="95%" height="170" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><p> </p>
<p align="center">
<input type="text" name="content">
<input type="submit" name="Submit2" value="搜索">
</p></td>
</tr>
</table>
</form>
<br>
</body>
</html>



    最新回复


发表评论







博客日历
« 八月 2008 »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
搜索
管理控制台
TOP_Read
TOP_Reply
New_Reply
网站链接
新闻聚合
RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3