SharePoint 2010 Development Example Highlights: sortable Search Core Results

Source: Internet
Author: User
Tags constructor extend object model visual studio 2010

Although the SharePoint 2010 out-of-the-Box Search interface is already intuitive and easy to use for information workers, it is still possible to create your own search experience as a superuser. SharePoint Server 2010 includes a number of powerful Web Parts related to search that support a custom search experience for super users, including search for best bets, thin panels, search core results, related queries, and more. The following figure is a standard search class WebPart.

IT Pros or developers can configure the built-in search Web Parts to customize the search experience. As a developer, you can also extend these webpart to change the behavior of the built-in search webpart on the search results page. You only need to inherit and extend on an existing basis without creating a new WebPart.

In addition, we can use query logging when customizing Search WebPart, and access the search service at any time through the query object model.

Example: Extended search Core Results Web Part

Let's create a new search WebPart with Visual Studio 2010. The WebPart in this example inherits from CoreResultsWebPart and displays the data from a custom source. The standard search core results WebPart includes a constructor and two methods, which we will modify in this example.

The first step is to create a new WebPart class. Create a new WebPart project and inherit from the CoreResultsWebPart class. Overwrite CreateChildControls to add any controls required by the interface, and then overwrite the CreateDataSource. This is the entrance to our operation query. In the overwrite, we will create an instance of the custom data source class that is created later.

class MSDNSample : CoreResultsWebPart
{
     public MSDNSample()
     {
         //默认构造器:支持为了序列化所以必须存在
     }
     protected override void CreateChildControls()
     {
         base.CreateChildControls();
         //在此处添加界面上用到的控件
     }
     protected override void CreateDataSource()
     {
         //base.CreateDataSource();
         this.DataSource = new MyCoreResultsDataSource(this);
     }

The second step is to create a new class that inherits from the Coreresultsdatasource class. In CreateDataSource's overwrite, the DataSource property is set to the class. In the Coreresultsdatasource constructor, create an instance of the custom data source view class that you created later. At this point, there is no need to overwrite any other content.

public class MyCoreResultsDataSource : CoreResultsDatasource
{
     public MyCoreResultsDataSource(CoreResultsWebPart ParentWebpart)
         : base(ParentWebpart)
     {
         //如果在这里我们需要引用该WebPart的属性或方法
         //那么可以通过 ParentWebPart 参数获取
         //创建将用于此数据源的视图
         this.VIEw = new MyCoreResultsDataSourceView(this, "MyCoreResults");
     }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.