Hi,
I am relatively new to Lucene. My indexing process is
going fine, as and when I upload the files. But when I
search the index file for those existing words, the
'hits' return no records. Can somebody point out what
could be my mistake in the following code?
Any help/suggestions are appreciated.
Thanks,
Vinu
----------------------------------------------------
package com.proj.search;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import com.proj.Repository.DocumentForm;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.lucene.analysis.*;
import org.apache.lucene.document.Document;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Hits;
public class SearchIndexDir {
public static ArrayList SearchFiles(String indexDir,
String docDir, String queryString, int BUCKET,
ActionErrors errors)
{
IndexSearcher searcher = null;
Query query = null;
Hits hits = null;
ArrayList list = null;
try {
searcher = new
IndexSearcher(IndexReader.open(indexDir));
// searcher = new IndexSearcher(indexDir);
} catch (Exception e) {
errors.add("missingIndex", new
ActionError("errors.search.lucene.index.missing"));
}
if (errors.empty())
{
if ( queryString.equals("") || null == queryString)
{
errors.add("emptyQueryString", new
ActionError("errors.search.lucene.enter.query.missing"));
}
Analyzer analyzer = new StopAnalyzer();
try { // search the entire content
query = QueryParser.parse(queryString,
"content", analyzer);
// System.out.println(query.toString());
} catch (ParseException e) {
// close(searcher);
errors.add("noResults", new
ActionError("errors.search.lucene.results.notfound"));
}
}
// iterate through the results, which is an array of
documents
if (errors.empty() && searcher != null) {
int start = 0;
try
{
hits = searcher.search(query);
}
catch (IOException e)
{
System.err.println("search "+e);
}
int end = Math.min(BUCKET, hits.length());
if(hits.length() > 0)
{
list = new ArrayList();
Document doc = null;
int length = docDir.length()+1; // plus the '/'
for(int i = start; i < end; i++)
{
try
{
doc = hits.doc(i);
//get the next
document
}
catch (IOException e)
{
System.out.println("get doc from hits "+e);
}
//get its url
String url = doc.get("url");
url = url.substring(length);
int _ind = url.indexOf("_");
String id = url.substring(0, _ind);
System.out.println("Found "+id);
DocumentForm form = new
DocumentForm(id);
list.add(form);
}
}
}
return list;
}
}
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>