I'm developing an eclipse plugin where a user can search a java code given some text query, similar to the usual java search dialog in eclipse.
I'm using the following code to search for a text provided by user
SearchPattern pattern = SearchPattern.createPattern("<search_string>",
IJavaSearchConstants.TYPE, IJavaSearchConstants.PARAMETER_DECLARATION_TYPE_REFERENCE,
SearchPattern.R_EXACT_MATCH);
// step 2: Create search scope
// IJavaSearchScope scope = SearchEngine.createJavaSearchScope(packages);
IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
// step3: define a result collector
SearchRequestor requestor = new SearchRequestor()
{
public void acceptSearchMatch(SearchMatch match)
{
System.out.println(match.getElement());
}
};
// step4: start searching
SearchEngine searchEngine = new SearchEngine();
try {
searchEngine.search(pattern, new SearchParticipant[] { SearchEngine
.getDefaultSearchParticipant() }, scope, requestor,
null);
} catch (CoreException e) {
e.printStackTrace();
}
Also I'm able to pass the query string from Search Dialogue to a class implementing ISearchPage.
public class QuerySearchPage extends DialogPage implements ISearchPage
{
...
public boolean performAction()
{
System.out.println(txtQuery.getText());
search();//search using the SearchEngine
SearchOperation so = new SearchOperation(iFileSet);
IRunnableWithProgress query = so;
try
{
container.getRunnableContext().run(true, true, query);
}
catch (InvocationTargetException | InterruptedException e)
{
e.printStackTrace();
}
return true;
}
}
Finally I got stuck at the point where I need to pass the search result to ISearchResultView. Basically, I have two questions:
- Matched results are of type Object. How to pass these results to ISearchResultView which takes IFile as input?
- How to get results in the below format?
I have already gone through the following links:
- http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fsearch_page.htm
- http://agile.csc.ncsu.edu/SEMaterials/tutorials/plugin_dev/
- http://grepcode.com/file/repository.grepcode.com/java/eclipse.org/3.5.2/org.eclipse/search/3.5.1/org/eclipse/search/ui/ISearchResult.java?av=f
- http://codeandme.blogspot.de/2015/07/a-custom-search-provider.html
- http://scg.unibe.ch/archive/projects/Bals10b-EclipsePlugins.pdf
- How can I develop Eclipse search Plugin?
- http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fsearch%2Fui%2FISearchResult.html
- https://wiki.eclipse.org/FAQ_How_do_I_implement_a_search_operation%3F
Any help is highly welcomed.


ISearchResultViewis deprecated,ISearchResultPagedeclared using theorg.eclipse.search.searchResultViewPagesis the recommended method. - greg-449