public void search(String q, File index, String [] fields, ArrayList subresult, int numresults) throws Exception {
Directory fsDir = FSDirectory.getDirectory(index, false);
IndexSearcher is = new IndexSearcher(fsDir);
Analyzer analyzer = new StandardAnalyzer();
Fragmenter fragmenter = new SimpleFragmenter(100);
QueryParser queryparser = new MultiFieldQueryParser (fields, analyzer);
Query query = queryparser.parse(q);
Hits hits = is.search(query);
IndexReader reader=null;
query=query.rewrite(reader);
QueryScorer scorer = new QueryScorer(query);
SimpleHTMLFormatter formatter= new SimpleHTMLFormatter("<span class=\"highlight\">","</span>");
Highlighter high = new Highlighter(formatter,scorer);
high.setTextFragmenter(fragmenter);
numresults = numresults == -1 || numresults > hits.length() ? hits.length() : numresults;
String rating = "";
for (int i = 0; i <numresults; i++) {
if (hits.score(i)>schwelli){
float f = hits.score(i);
if (0.9f <= f) {rating = "******";}
else if (0.8f <= f && f<0.9f){rating = "*****";}
else if (0.7f <= f && f<0.8f){rating = "****";}
else if (0.6f <= f && f<0.7f){rating = "***";}
else if (0.5f <= f && f<0.6f){rating = "**";}
else if (f <= 0.5f){rating = "*";}
Document doc = hits.doc(i);
String abstracts =doc.get("ABSTRACTS");
String title = doc.get("TITLE");
TokenStream abstract_stream = analyzer.tokenStream(q, new StringReader(abstracts));
TokenStream title_straem = analyzer.tokenStream(q, new StringReader(title));
String fragment_abstract = high.getBestFragments(abstract_stream,abstracts, 5, "...");
String fragment_title = high.getBestFragments(title_straem,title, 5, "...");
if(fragment_title.length()==0){
setAusgabeTitle(doc.get("TITLE"));
}else{
setAusgabeTitle(fragment_title);
}
if(fragment_abstract.length()==0){
setAusgabeAbstract(doc.get("ABSTRACTS"));
}else{
setAusgabeAbstract(fragment_abstract);
}
//list.add(i+1+"\t"+q+"\t"+doc.get(entry_medline)+"\t"+hits.score(i)+"\t"+abstract_stream+"\t"+title_straem+"\t"+"MEDLINE");
/*int No = i;
subresult.add((new Integer(No)).toString());*/
subresult.add(doc.get(entry_medline));
subresult.add("No Id");
subresult.add("No Id");
float sco = hits.score(i);
subresult.add(rating);//(hits.score(i));
subresult.add(fragment_abstract);
subresult.add(fragment_title);
subresult.add("No hits for this index");
subresult.add("MEDLINE");
}
}
}