Friday, May 15, 2009

Compiling audience object model.

Refer the community content by me at
http://msdn.microsoft.com/en-us/library/microsoft.office.server.audience.audiencemanager.aspx

MSDN Note "Compiling audiences is not supported in the object model."
Actually we can compile the audience.
Following code to compile all the audiences.
Add Reference Microsoft Search Component(Microsoft.Office.Server.Search.dll)
using Microsoft.Office.Server.Search.Administration;

using (SPSite site = new SPSite(txtSite.Text))
{
ServerContext context = ServerContext.GetContext(site);
SearchContext searchContext = SearchContext.GetContext(context);
string[] args = new string[3];
args[0] = searchContext.Name;
args[1] = "1"; //"1" = start job, "0" = stop job
args[2] = "1"; //"1" = full compilation, "0" = incremental compilation (optional, default = 0)
AudienceJob.RunAudienceJob(args);
System.Threading.Thread.Sleep(3000);
}

To Compile a specific audience, add the optional arg[3] after making the String array size to 4 and specify the Audience Name.

No comments: