For developers: Index external content
Sitefinity CMS can index data items that are managed on external systems.
For example, if you have blog posts, which are managed on an external system, by retrieving values of the posts' data fields, adding them to a search document, and updating Sitefinty's index, the blog posts are indexed in Sitefinity.
The data content that you want to index must be compatible with Sitefinity CMS Search. This means that the fields that you want to participate in the index must be of type string, int, or DateTime.
To index external content in Sitefinity's indexes, you must create a search document for each indexed item and push it into the current Search Service implementation. When search documents are indexed, they are displayed in search results and search suggestions in Sitefinity.
The following code demonstrates a creation of a search document, populated with a number fields, which is pushed into Sitefinity CMS index:
/// <summary>
/// Creates a new document and adds it to the search index.
/// </summary>
public
void
AddSearchDocument()
{
var fields =
new
List<IField>();
// The identity field
var identityFld =
new
Field();
identityFld.Name =
"IdentityField"
;
identityFld.Value =
"some unique identifier"
;
// Use lowercase only
fields.Add(identityFld);
var myTitleField =
new
Field();
myTitleField.Name =
"Title"
;
myTitleField.Value =
"Here goes the title"
;
fields.Add(myTitleField);
var lastModifiedField =
new
Field();
lastModifiedField.Name =
"LastModified"
;
lastModifiedField.Value = DateTime.UtcNow;
fields.Add(lastModifiedField);
// Create the document, containing the fields that we constructed
var doc =
new
Document(fields,
"IdentityField"
);
// index the created document
ServiceBus.ResolveService<ISearchService>().UpdateIndex(
"index"
,
new
List<IDocument>() { doc });
}