I'm new to Coveo. I'm trying to work out the best way to index wildcard pages. So when you publish a wildcard item, all the corresponding wildcard pages get indexed nicely with their correct URL's.

I've achieved this many times before with Lucene and Solr using trickery with custom item crawlers. But I know that Coveo for Sitecore has has bunch of different pipelines for you took hook in to.

I feel certain the answer is in there somewhere, but I don't know enough to find it.

up vote 6 down vote accepted

In Coveo for Sitecore you can use the coveoItemProcessingPipeline to add other items that should also be indexed. This is similar in concept to the Sitecore indexing.getDependencies pipeline

public class IndexWildcardItems : IProcessor<CoveoItemProcessingPipelineArgs>
{
    public void Process(CoveoItemProcessingPipelineArgs p_Args)
    {
        var indexableItem = p_Args.Item as SitecoreIndexableItem;
        if (indexableItem != null && indexableItem.Item != null && IsCustomWildcardItem(indexableItem.Item))
        {
            IEnumerable<Item> wildcards = GetWildcardItems(indexableItem.Item);

            p_Args.OutputItems.AddRange(wildcards.Select(x => (SitecoreIndexableItem)x));
        }
    }

And patch the config in:

<pipelines>
  <coveoItemProcessingPipeline>
    <processor type="MySite.Custom.ContentSearch.Processors.IndexWildcardItems, MySite.Custom" />
  </coveoItemProcessingPipeline>
</pipelines>

You will need to provide the correct logic for IsCustomWildcardItem() to determine if the current item being indexed is a valid Wildcard item and the logic required for GetWildcardItems(indexableItem.Item) to return the all the items for this particular wildcard.

The items are then added to the indexing queue and will be indexed as normal like any other item.

You'll also need to handle indexing the URLs for your items. The tricky part here is determining which site an item belongs to and how to determine which wildcard an item belongs to. There are so many factors that can affect this, such as your exact set up and content architecture, so is beyond the scope of this answer without a lot more information. By default, Coveo will resolve the ClickUri field when it is returned by the REST service. This means that if you have your LinkProvider set up to generate the correct link then the returned URL will be generated correctly.

You can read more information about the Coveo coveoProcessParsedRestResponse pipeline and the ResolveResultClickableUriProcessor processor which resolves the ClickUri:

<coveoProcessParsedRestResponse patch:source="Coveo.SearchProvider.Rest.config">
  <!--
    This processor resolves the REST results clickUri field in the context of 
    the current site using the Sitecore LinkManager. 
  -->
  <processor type="Coveo.SearchProvider.Rest.Processors.CoveoProcessParsedRestResponse.ResolveResultClickableUriProcessor, Coveo.SearchProvider.Rest"/>
</coveoProcessParsedRestResponse>

Note: The above is true for Coveo version 3, the pipelines and processors involved may be slightly different for Coveo version 4 but the concepts remain the same.

  • Perfect, just what I needed! – Martin Davies Oct 12 '16 at 19:19
  • 2
    I confirm this answer also applies to Coveo for Sitecore 4.0. Great answer @jammykam! – jflheureux Oct 12 '16 at 20:41

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.