Trying to add custom content to search

Hello,

I am trying to make some content from an API available in Telligent's search results. So I followed the documentation here community.telligent.com/.../search and I implemented and released locally. I have the Job scheduler running, but my content is not available via Search. 
More specifically I can't see the GetContentToIndex being called at all. Has any of you managed to implement it this ISearchableContentType interface and find the results in Search?

Thank you for your response

Parents Reply
  • Hi Mathew,  I have included the code.

    #region ISearchableContentType
    	public bool IsCacheable => true;
    
    	public bool VaryCacheByUser => true;
    	
    	public void SetIndexStatus(Guid[] contentIds, bool isIndexed)
    	{
    		
    	}
    
    	public IList<SearchIndexDocument> GetContentToIndex()
    	{
    		var docs = new List<SearchIndexDocument>();
    		var assets = AssetData.GetAssets();
    		foreach (var asset in assets)
    		{
    			if (asset == null) { continue; }
    			var searchDocument = Apis.Get<ISearchIndexing>().NewDocument(asset.ContentId, asset.ContentTypeId, "Material", asset.Url, asset.Name, asset.HtmlDescription(asset.Description));
    			docs.Add(searchDocument);
    		}
    
    		return docs;
    	}
    
    	public int[] GetViewSecurityRoles(Guid contentId)
    	{
    		var roles = Apis.Get<IRoles>().Find("Everyone").Select(r => r.Id.GetValueOrDefault()).ToArray();
    		return roles;
    	}
    
    	public string GetViewHtml(IContent content, Target target)
    	{
    		if (content == null) { return null; }
    		return string.Format("FOUND ITEM " + content.Url);
    	}
    #endregion

Children
  • Can you confirm that GetViewSecurityRoles is returning the correct id(s) in the array?

  • Hi Steven,

    I tried to return from GetViewSecurityRoles  both Apis.Get<IRoles>().List().Select(r => r.Id.GetValueOrDefault()).ToArray(); (ids = 1,2,3,4,26)

    and 
    Apis.Get<IRoles>().Find("Everyone").Select(r => r.Id.GetValueOrDefault()).ToArray();

  • We found that this is because the collapse field is required to be added to the indexed content.

    The problem arises because, when using Fiddler to inspect the search request the platform makes to Solr, I noticed that one of the fq parameters was {!collapse field=collapse}. This requires the results to be collapsed, based on the value in the ‘collapse’ field. However, as you are not setting this, it’s excluded from results. Luckily, the fix should be simple. If you add the line highlighted below to your code, once the content is indexed again it should start to show up in results as expected.

     

                foreach (var asset in assets)

                {

                    if (asset == null) { continue; }

                                   searchDocument.AddField(Apis.Get<SearchIndexing>().Constants.CollapseField, "ContentName:" + id);

                   docs.Add(searchDocument);

                }