Hi,
I have look at the examples from lucene source, and try out myself but it
doesn't work. Perhaps u can point out where I did wrong. Below r the codes
that I developed:
public String search(String searchString) throws IOException, Exception
{
//System.out.println("inside search util");
IndexReader reader = null;
StringBuffer buff = new StringBuffer();
BooleanQuery bq1 = new BooleanQuery();
//BooleanQuery bq2 = new BooleanQuery();
//ArrayList resultList = new ArrayList();
try
{
reader = IndexReader.open(DsConstant.indexDir);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer();
QueryParser parser = new
QueryParser(DsConstant.idxFileContent,
analyzer);
Query query = parser.parse(searchString);
bq1.add(query, BooleanClause.Occur.MUST);
bq1.add(new BooleanClause(query,
BooleanClause.Occur.MUST));
//bq2.add(query, BooleanClause.Occur.MUST);
//bq1.add(bq2, BooleanClause.Occur.MUST);
searchHits = searcher.search(bq1);
if(searchHits.length() > 0)
{
QueryScorer scorer = new QueryScorer(query);
Highlighter highlighter = new Highlighter(new
SimpleHTMLFormatter("<span
style='background-color:yellow; font-weight:bold;'>",
"</span>"),
scorer);
for(int i = 0; i < searchHits.length(); i++)
{
Document doc = searchHits.doc(i);
String text =
doc.get(DsConstant.idxFileContent);
TokenStream tokenstream =
analyzer.tokenStream(DsConstant.idxFileContent, new StringReader(text));
//buff.append("<p> '" +
DsConstant.userDir
buff.append("<p " +
searchHits.doc(i).get(DsConstant.idxPath) + " "
+
searchHits.doc(i).get("docName") + " <br>");
//buff.append("score: " +
searchHits.score(i) + "<br>");
buff.append(highlighter.getBestFragments(tokenstream, text, 3, "...")+
"</p>");
buff.append("!");
}
//System.out.println("Folder path is ::: "
+DsConstant.folderPath);
searcher.close();
}
System.out.println("Found "+searchHits.length()+"
searchHits with query =
"+query);
}
catch(Exception e)
{
e.printStackTrace();
}
return buff.toString();
//return resultList;
}
Thanks.
regards,
Wooi Meng
--
View this message in context:
http://www.nabble.com/search-within-search-tf2558237.html#a7152393
Sent from the Lucene - Java Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]