Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

Posts Tagged ‘enrichment web service’

Content Enrichment Web Service

Posted by Paul on May 21, 2014

In this article we can explore an Advanced Search feature of SharePoint 2013.

What is Content Enrichment Web Service?

SharePoint 2013 allows developers to add a custom step between content processing. SharePoint while content source crawl will call our custom web service. We can create or change the metadata properties associated with the crawl item.

Under the hood, the web service is actually implementing a pre-defined interface. Each crawl item will be passed to the interface method where item URL & properties can be accessed.

Scenarios

We can use Content Enrichment Web Service for the following scenarios:

1. You have multiple web content sources configured. You need to create new Managed Properties based on each URL. Example: Blog, Website etc.

2. You have a content source with limited metadata information. You need to add new Managed Properties based on the content.

3. You have a content source with metadata information. You need to correct the Managed Properties.

4. You have a SharePoint list where Age column exists. You need to classify the content as Minor & Major using Managed Properties.

Infrastructure

Following are the Infrastructure need:

1. Visual Studio 2012

2. IIS website to host the service

3. WCF service

Practical

To perform the Practical, we need to setup the following.

1. SharePoint 2013 Enterprise site

2. Create Enterprise Search Center site

3. Central Administration > Search > Create Content Source > Add www.jeanpaulva.com

4. Central Administration > Search > Create Content Source > Add www.sharepointcto.com

5. Central Administration > Create Crawl Rules > Include query strings (?) for both URLs

6. Server > IE Enhanced Security Configuration > Off

7. Perform Full Crawl for both content sources

After the above steps, Try searching for sharepointcto from the Enterprise Search Center site & you should be able to see results from both the URLs as shown below.

image

Our aim is to provide refiners like below.

image

Steps

Step 1: Create Service

Create a new WCF service application project.

image

Delete the existing Service files & create a new Service.

image

You can delete the interface file as well. The Solution Explorer looks like below.

image

Add Reference to the following assembly:

· 15HIVESearchApplicationsExternalMicrosoft.Office.Server.Search.ContentProcessingEnrichment.dll

Step 2: Implement Interface

Open the SVC file & implement pre-defined interface IContentProcessingEnrichmentService as shown below.

image

The only method named ProcessItem passes an Item argument and returns ProcessedItem argument.

The interface IContentProcessingEnrichmentService belongs to the ContentProcessingEnrichment assembly.

The Item type has a property named ItemProperties which contains pre-defined Name-Value pairs of:

ContentType

Access the Content Type of the item

Name

Access the Name of the item

Title

Access the Title of the item

Path

Access the Path of the item

ContentSource

Access the ContentSource name

We can specify the input & output properties while registering the service. In our case we are using the Path property.

Step 3: Create Method

Replace the method with the following code. Right click & Resolve type name errors.

public ProcessedItem ProcessItem(Item item)

{

ProcessedItem processedItem = new ProcessedItem();

processedItem.ItemProperties = new List<AbstractProperty>();

var p = item.ItemProperties.Where(n => n.Name == “Path”).First();

string url = p.ObjectValue.ToString();

if (!string.IsNullOrEmpty(url))

if (url.StartsWith(“http://www.sharepointcto.com&#8221;))

{

Property<string> property = new Property<string>()

{

Name = “WebType”,

Value = “Site”

};

processedItem.ItemProperties.Add(property);

}

else if (url.StartsWith(“http://www.jeanpaulva.com&#8221;))

{

Property<string> property = new Property<string>()

{

Name = “WebType”,

Value = “Blog”

};

processedItem.ItemProperties.Add(property);

}

return processedItem;

}

The above code performs the following:

1. Get the Path property value

2. If Path value is of www.sharepointcto.com then creates a Managed Property WebType and set value to Site

3. If Path value is of www.jeanpaulva.com then creates a Managed Property WebType and set value to Blog

4. The processedItem object will be returned by method

Step 5: Run the Service

Save & Run the Service.

image

Step 6: Create Managed Property

Open Central Administration > Service Applications > Search Service Application > Search Schema > New Managed Property page. Enter the following details.

image

· Name as WebType

· Type as Text

· Searchable enable

· Queryable enable

· Refinable yes-active

Step 7: Register Service using PowerShell

Open PowerShell ISE editor & Paste the following code.

# Add PowerShell Snapin

if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)

{

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

}

# Get SearchServiceApplication

$ssa = Get-SPEnterpriseSearchServiceApplication

Remove-SPEnterpriseSearchContentEnrichmentConfiguration –SearchApplication $ssa

$c = New-SPEnterpriseSearchContentEnrichmentConfiguration

$c.Endpoint = “http://localhost:52156/WebsiteEnrichmentService.svc&#8221;

$c.DebugMode = $false

$c.SendRawData = $false

$c.InputProperties = “Path”

$c.OutputProperties = “WebType”

Set-SPEnterpriseSearchContentEnrichmentConfiguration –SearchApplication $ssa –ContentEnrichmentConfiguration $c

Please remember to use the correct URL for the service.

Save & Run. If no errors, your service is installed successfully.

Step 8: Perform Full Crawl

Open Central Administration & Perform Full Crawl for the following content sources.

1. Web content source for www.sharepointcto.com

2. Web content source for www.jeanpaulva.com

Step 9: Add Refiners to Result Page

Open the Enterprise Search Center result page, bring the page to edit mode, edit the refiner web part & add the WebType refiner. You can view References section on how to add Search Refiners.

Step 10: Test Search

Open the Enterprise Search Center Site & Try searching for content. You can see the Web Type refiner appearing & try clicking on the values.

image

If the result is filtered based on Blog or Site values, it means the Refiners are working correctly.


As the Content Enrichment Web Service will be called for all the Content Sources, Performance can become sluggish as there is a delay involved in the service invocation. It is recommended that we should deploy the service closer to the SharePoint system. Alternatively, one can try Asynchronous mode too.

We can also debug the service. Ensure the Service is running & set breakpoints.

image

References

http://msdn.microsoft.com/en-us/library/office/jj163982(v=office.15).aspx

http://www.jeanpaulva.com/index.php/2014/04/20/search-refiners/

Summary

In this article we have explored Content Enrichment Web Service. The source code & script is attached along with for download.

Advertisements

Posted in SharePoint 2013 | Tagged: , , | Leave a Comment »