/* Perform the search */
try {
Query bQuery = ModelSearchQueries.createQuery(conditions, matchAllConditions);
/* Make sure the searcher is in sync */
final IndexSearcher currentSearcher = getCurrentSearcher();
final List<SearchHit<NewsReference>> resultList = new ArrayList<SearchHit<NewsReference>>();
final Map<Long, Long> searchResultNewsIds = new HashMap<Long, Long>();
/* Use custom hit collector for performance reasons */
HitCollector collector = new HitCollector() {
@Override
public void collect(int doc, float score) {
try {
Document document = currentSearcher.doc(doc);
/* Receive Stored Fields */
long newsId = Long.parseLong(document.get(SearchDocument.ENTITY_ID_TEXT));
INews.State newsState = NEWS_STATES[Integer.parseInt(document.get(NewsDocument.STATE_ID_TEXT))];
Map<Integer, INews.State> data = new HashMap<Integer, INews.State>(1);
data.put(INews.STATE, newsState);
/*
* Under some circumstances the index might contain the same news
* twice. This can happen in situations where RSSOwl is quitting in
* an emergent way (e.g. the OS shutting down while RSSOwl is
* running). To avoid issues, we filter out duplicate results from
* the search. See http://dev.rssowl.org/show_bug.cgi?id=1264
*/
if (!searchResultNewsIds.containsKey(newsId)) {
resultList.add(new SearchHit<NewsReference>(new NewsReference(newsId), score, data));
searchResultNewsIds.put(newsId, newsId);
}
} catch (IOException e) {
Activator.safeLogError(e.getMessage(), e);
}
}
};
/* Perform the Search */
try {
currentSearcher.search(bQuery, collector);
return resultList;
} finally {
disposeIfNecessary(currentSearcher);
}
} catch (IOException e) {