hi,

i am able to index the database but while searching
it does'nt
show any result

i am sending u part of my code just chk and tell me
where is error

code---

class DBReader
{
static final File INDEX_DIR = new File("index");
public static void main(String args[])
{
try {
// The newInstance() call is a work
around for some
// broken Java implementations

Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("driver loaded
successfully");
} catch (Exception ex) {
System.out.println("DBError:"+ex);
}

try {
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/experience?user=root&password=");
System.out.println("connection success");

// Do something with the Connection ....
Statement stmt = conn.createStatement();
String select_query = "SELECT
resume_name,years,months,details FROM info";
ResultSet rs =
stmt.executeQuery(select_query);

IndexWriter writer = new
IndexWriter(INDEX_DIR, new StandardAnalyzer(),
true);

while (rs.next()) {
String resume_name =
rs.getString("resume_name");
float years = rs.getFloat("years");
float months = rs.getFloat("months");
String details =
rs.getString("details");

//System.out.println(resume_name+"\t"+years+"\t"+months+"\t"+details);
//try {
//Thread.sleep(1000);
//}
//catch(InterruptedException e) {
// probably fine to ignore
this exception
//}
writer.setMaxFieldLength(25000);

final Document doc = new Document();
doc.add(new Field("resume_name",
resume_name, Store.YES, Index.UN_TOKENIZED));
doc.add(new Field("details", details,
Store.YES, Index.UN_TOKENIZED));
writer.addDocument(doc);
}
writer.optimize();
writer.close();

IndexReader reader =
IndexReader.open("index");
Searcher searcher = new
IndexSearcher(reader);
Analyzer analyzer = new
StandardAnalyzer();
BufferedReader in = new
BufferedReader(new InputStreamReader(System.in,
"UTF-8"));
String field = "contents";
QueryParser parser = new
QueryParser(field, analyzer);

while (true)
{
System.out.print("Query: ");

String line = in.readLine();

if (line == null ||
line.length() == -1)
break;

Query query = parser.parse(line);
System.out.println("Searching
for: " + query.toString(field));

Hits hits =
searcher.search(query);

System.out.println(hits.length() + " total matching
documents");

final int HITS_PER_PAGE = 10;
for (int start = 0; start <
hits.length(); start += HITS_PER_PAGE)
{
int end =
Math.min(hits.length(), start + HITS_PER_PAGE);
for (int i = start; i
< end; i++)
{
Document docs
= hits.doc(i);
String path =
docs.get("path");
if (path != null)
{

System.out.println((i+1) + ". " + path);
String
title = docs.get("title");
if
(title != null)
{

System.out.println(" Title: " + docs.get("title"));
}
}else{

System.out.println((i+1) + ". " + "No path for this
document");
}
}

if (hits.length() > end)
{

System.out.print("more (y/n) ? ");
line =
in.readLine();
if
(line.length() == 0 || line.charAt(0) == 'n')
break;
}
}//end of for(int start = 0;
start < hits.length(); start += HITS_PER_PAGE)
}//end of while(true)

} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " +
ex.getMessage());
System.out.println("SQLState: " +
ex.getSQLState());
System.out.println("VendorError: " +
ex.getErrorCode());
}
catch(IOException ex)
{
}
catch(Exception e)
{
}
}
}

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the 
property of Persistent Systems Pvt. Ltd. It is intended only for the use of the 
individual or entity to which it is addressed. If you are not the intended 
recipient, you are not authorized to read, retain, copy, print, distribute or 
use this message. If you have received this communication in error, please 
notify the sender and delete all copies of this message. Persistent Systems 
Pvt. Ltd. does not accept any liability for virus infected mails.

Reply via email to