Searcher searcher = null;
try {
outer:for(int i=0;i<files.length;i++) {
if(removeCorrupt(files[i]))continue;
String strFile=files[i].toString();
SearchIndex si = indexes.get(files[i].getName());
if(si==null)continue;
ct=si.getCategoryTree();
c=ListUtil.arrayToList(si.getCategories(), ",");
// check category tree
if(!matchCategoryTree(ct,categoryTree))continue;
if(!matchCategories(si.getCategories(),category))continue;
Document doc;
String id=files[i].getName();
data.addRecordsSearched(_countDocs(strFile));
reader = _getReader(id,false);
if(query==null && "*".equals(criteria)) {
int len=reader.numDocs();
for(int y=0;y<len;y++) {
if(startrow>++count)continue;
if(maxrows>-1 && list.size()>=maxrows) break outer;
doc = reader.document(y);
list.add(createSearchResulItem(highlighter,analyzer,doc,id,1,ct,c,aa.getContextPassages(),aa.getContextBytes()));
}
}
else {
if(spellcheck)spellCheckIndex.add(id);
// search
searcher = new IndexSearcher(reader);
Hits hits = searcher.search(query);
int len=hits.length();
for (int y=0; y<len; y++) {
if(startrow>++count)continue;
if(maxrows>-1 && list.size()>=maxrows) break outer;
//list.add(new SearchResulItemHits(hits,y,highlighter,analyzer,id,ct,c,aa.getContextPassages(),aa.getContextBytes()));
doc = hits.doc(y);
list.add(createSearchResulItem(highlighter,analyzer,doc,id,hits.score(y),ct,c,aa.getContextPassages(),aa.getContextBytes()));
}
}
}
}
finally {
close(reader);
close(searcher);
}
// spellcheck
//SearchData data=ThreadLocalSearchData.get();
if(spellcheck && data!=null) {
if(data.getSuggestionMax()>=list.size()) {
Map suggestions = data.getSuggestion();
Iterator it = spellCheckIndex.iterator();
String id;
Literal[] literals = queryParser.getLiteralSearchedTerms();
String[] strLiterals = queryParser.getStringSearchedTerms();
boolean setSuggestionQuery=false;
while(it.hasNext()) {
id=(String) it.next();
// add to set to remove duplicate values
SuggestionItem si;
SpellChecker sc = getSpellChecker(id);
for(int i=0;i<strLiterals.length;i++) {
String[] arr = sc.suggestSimilar(strLiterals[i], 1000);
if(arr.length>0){
literals[i].set("<suggestion>"+arr[0]+"</suggestion>");
setSuggestionQuery=true;
si=(SuggestionItem) suggestions.get(strLiterals[i]);
if(si==null)suggestions.put(strLiterals[i],new SuggestionItem(arr));
else si.add(arr);
}
}
}
if(setSuggestionQuery)data.setSuggestionQuery(op.toString());
}