Hi
I trying to implement SearchableContentType from documentation
https://community.telligent.com/community/10/w/developer-training/53163/search
but search does not work for me. Search by keywords like 'google', 'best', etc in the search box on the tom of community does not return anything from "Links".
I added a log for method
public IList<SearchIndexDocument> GetContentToIndex()
and don't see any calls for it in events.
Also tried to call it mannually - but search still does not work.
All extensions enabled and custom widget showing data.
Maybe I miss something?
public class LinkItemContentType : ISearchableContentType, IPlugin {
IContentStateChanges _contentState = null;
private static readonly SimpleLog Log = new SimpleLog(typeof(LinkItemContentType).Name);
#region IPlugin Members
public string Description {
get { return "Items in a Links collection"; }
}
public void Initialize() {
Log.Info("Initialize");
// Apis.Get<SearchIndexing>().Delete(new SearchIndexDeleteOptions() {Category = "linkitem"});
// GetContentToIndex();
}
public string Name {
get { return "Link Items"; }
}
#endregion
#region IContentType Members
public Guid[] ApplicationTypes {
get { return new[] {ContentTypes.LinksApplicationId}; }
}
public void AttachChangeEvents(IContentStateChanges stateChanges) {
_contentState = stateChanges;
}
public Guid ContentTypeId {
get { return ContentTypes.LinksItemId; }
}
public string ContentTypeName {
get { return "Links Item"; }
}
public IContent Get(Guid contentId) {
return LinksData.GetLink(contentId);
}
#endregion
#region ISearchableContentType
public void SetIndexStatus(Guid[] contentIds, bool isIndexed) {
Log.Info("SetIndexStatus " + isIndexed);
LinksData.UpdateStatus(contentIds, isIndexed);
}
public IList<SearchIndexDocument> GetContentToIndex() {
Log.Info("GetContentToIndex");
var docs = new List<SearchIndexDocument>();
var links = LinksData.ListLinks().Where(link => !link.IsIndexed);
foreach (var link in links) {
Log.Info("" + link.Name);
if (link == null) {
continue;
}
var doc = Apis.Get<ISearchIndexing>().NewDocument(link.ContentId, link.ContentTypeId, "linkitem", link.Url, link.HtmlName("web"),
link.HtmlDescription("web"));
doc.AddField("date", Apis.Get<ISearchIndexing>().FormatDate(link.CreatedDate));
doc.AddField(Apis.Get<SearchIndexing>().Constants.Category, "linkitem");
doc.AddField(Apis.Get<SearchIndexing>().Constants.IsContent, true.ToString());
doc.AddField(Apis.Get<SearchIndexing>().Constants.CollapseField, "links:" + link.ContentId.ToString());
docs.Add(doc);
}
return docs;
}
public int[] GetViewSecurityRoles(Guid contentId) {
Log.Info("GetViewSecurityRoles");
var content = LinksData.GetLink(contentId);
if (content == null) {
return new int[] { };
}
if (content.Application == null) {
return new int[] { };
}
return Apis.Get<IRoles>().Find("Registered Users").Select(r => r.Id.GetValueOrDefault()).ToArray();
}
public string GetViewHtml(IContent content, Target target) {
Log.Info("GetViewHtml");
if (content == null) {
return null;
}
var user = Apis.Get<IUsers>().Get(new UsersGetOptions {Id = content.CreatedByUserId});
var author = String.Format(@"<a href=""{0}"" class=""internal-link view-user-profile""><span></span>{1}</a>",
Apis.Get<Html>().EncodeAttribute(user.ProfileUrl), Apis.Get<Html>().Encode(user.DisplayName));
var appLink = content.Application != null
? String.Format(@"<a href=""{0}"">{1}</a>", Apis.Get<Html>().EncodeAttribute(content.Application.Url),
content.Application.HtmlName(target.ToString()))
: String.Empty;
var groupLink = content.Application != null && content.Application.Container != null
? String.Format(@"<a href=""{0}"">{1}</a>", Apis.Get<Html>().EncodeAttribute(content.Application.Container.Url),
content.Application.Container.HtmlName(target.ToString()))
: String.Empty;
return String.Format(@"
<div class=""abbreviated-post-header""></div>
<div class=""abbreviated-post ui-searchresult"">
<div class=""post-metadata"">
<ul class=""property-list"">
<li class=""property-item date"">{0}</li>
<li class=""property-item author"">
<span class=""user-name"">{1}</span>
</li>
<li>
<ul class=""details"">
<li class=""property-item type""></li>
</ul>
</li>
</ul>
</div>
<h4 class=""post-name"">
<a class=""internal-link view-post"" title=""{3}"" href=""{4}"">
{2}
</a>
</h4>
<div class=""post-summary"">{5}</div>
<div class=""post-application"">
{6}
{7}
</div>
</div>
<div class=""abbreviated-post-footer""></div>", Apis.Get<ILanguage>().FormatDate(content.CreatedDate), author, content.HtmlName("web"),
content.HtmlName("web"), Apis.Get<Html>().EncodeAttribute(content.Url), content.HtmlDescription("web"), appLink, groupLink);
}
public bool IsCacheable {
get { return false; }
}
public bool VaryCacheByUser {
get { return false; }
}
#endregion
}