Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to extend the CoreResultsWebPart in order to render search results in a custom fashion. I know that I could use the XSL in order to customize the results but given the need to perform some lookup's against other data sources the XSL isn't sufficient.

It seems like doing:

protected override void RenderContents(HtmlTextWriter writer) {
     // code
}

Should work, but anything I put in this function doesn't seem to have any impact on the web part. If I override the Render method that seems to work, but my understanding is the Render method breaks the WebPart object model so you really shouldn't use it.

I've also tried CreateChildControls but this seems to be called much earlier in the stack before the KeywordQuery is executed so the search results aren't available at the time CreateChildControls executes.

I'm getting the search result data by overriding the GetXNavigator method, which seems to work fairly well but I'm not sure if there is a better way.

Any ideas or suggestions for overriding the CoreResultsWebPart in this way?

share|improve this question
add comment

3 Answers

CoreResultsWebPart is not calling RenderContents so that's why it doesn't matter that you override that. You can override RenderWebPart, but I'd recommend to use XSLT, in ModifyXsltArgumentList you can add ExtensionObjects to do your lookup. (If it can take more than 1 second, then you need to apply February 2012 CU).

Another thing to consider is that if you're not going to use the XSLT part of CoreResultsWebPart, then you might be better of creating your own web part instead of inheriting from CoreResultsWebPart.

share|improve this answer
add comment

If your requirement is fulfilled by custom rendering or manipulating with search query (by accessing the QueryManager object by overriding the GetXPathNavigator method), you should inherit from CoreResultsWebPart.

Otherwise,You should go for custom search webpart. You can use KeywordQuery to search. You can find the details here : http://extreme-sharepoint.com/2011/10/28/sharepoint-keywordquery/

share|improve this answer
add comment

In a recent project, I built a couple of WebParts that inherit from the CoreResultsWebPart. In those WebParts, I used the ShareQueryManager to get a reference to the QueryManager and iterated through the search results XML document & bound those results to a GridView or Repeater.

Overriding the "OnInit" method allowed me to dynamically load my GridView or Repeater control, and then overriding the "CreateChildControls" method allowed me to iterate through the search results XML document and bind those results to the appropriate control.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.