use of org.eclipse.help.internal.search.QueryTooComplexException in project tdi-studio-se by Talend.
the class TalendEditorPaletteFactory method getRelatedComponentNamesFromHelp.
protected static Set<String> getRelatedComponentNamesFromHelp(final String keyword) {
if (keyword == null || keyword.isEmpty()) {
return null;
}
// This method will cost lots of time to complete when it is called the first time
final List<SearchHit> querySearchResult = new ArrayList<SearchHit>();
if (searchInHelpJob != null && searchInHelpJob.getState() != Job.NONE) {
searchInHelpJob.cancel();
}
searchInHelpJob = new Job(SEARCHING_FROM_HELP) {
@SuppressWarnings("restriction")
@Override
protected IStatus run(IProgressMonitor monitor) {
String helpKeyword = keyword;
try {
TalendPaletteSearchIndex searchIndex = TalendPaletteSearchIndex.getInstance();
LocalSearchManager localSearchManager = BaseHelpSystem.getLocalSearchManager();
// if not work or null, maybe should throw a warn to inform user and help us trace
// if (searchIndex != null && localSearchManager != null) {
localSearchManager.ensureIndexUpdated(monitor, searchIndex);
//$NON-NLS-1$
final String WHITESPACE = " ";
//$NON-NLS-1$//$NON-NLS-2$
helpKeyword = helpKeyword + WHITESPACE + "OR" + WHITESPACE + helpKeyword + "*";
ISearchQuery searchQuery = new SearchQuery(helpKeyword, false, new ArrayList<String>(), Platform.getNL());
searchIndex.search(searchQuery, new ISearchHitCollector() {
@Override
public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
// nothing need to do
}
@Override
public void addHits(List<SearchHit> hits, String wordsSearched) {
querySearchResult.addAll(hits);
}
});
// }
} catch (Throwable e) {
CommonExceptionHandler.process(e, Priority.WARN);
}
return Status.OK_STATUS;
}
@Override
public boolean belongsTo(Object family) {
return family.equals(FederatedSearchJob.FAMILY);
}
};
try {
searchInHelpJob.setPriority(Job.INTERACTIVE);
searchInHelpJob.schedule();
searchInHelpJob.join();
} catch (Throwable e) {
CommonExceptionHandler.process(e, Priority.WARN);
}
Set<String> componentNames = new LinkedHashSet<String>();
// the limitation has been moved to it's caller
// int limit = PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
// int i = 1;
Iterator<SearchHit> iter = querySearchResult.iterator();
while (iter.hasNext()) {
// if (limit < i) {
// break;
// }
SearchHit result = iter.next();
String label = result.getLabel();
if (label == null || label.trim().length() == 0) {
continue;
}
componentNames.add(label);
// i++;
}
return componentNames;
}
Aggregations