London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Skipping products from being indexed

Vote:
 

I would like to NOT index every product in my catalogue. I am overriding the method IndexCatalogEntryDto by inherritence from CatalogIndexBuilder. What do I return if the product entry should not be indexed?

#193412
May 30, 2018 8:30
Vote:
 

Also, how can I verify what has been indexed? Is there a table to go to?

#193414
May 30, 2018 8:52
Vote:
 

Just return 0 is enough. You can try to search for a product after rebuild the index. If it is not found then it was not indexed, right? 

#193470
May 30, 2018 9:46
Vote:
 

And if the product shall be indexed I return base.IndexCatalogEntryDto(indexer, entryRow, defaultCurrency, languages); ? That row always seems to return 1.

#193489
May 30, 2018 13:52
Vote:
 

yes, just return that. 

The result is actually the number of languages you have in your catalog 

#193491
May 30, 2018 14:02
Vote:
 

Okay. So, when 1 is returned from that overriden method, that particular entry is indexed?

#193494
May 30, 2018 14:09
Vote:
 

Yes. But I'm not sure why you should care about it. 

public class CustomCatalogIndexer : CatalogIndexer 

{

 protected override int IndexCatalogEntryDto (...)

 if (ShouldNotIndex(entryRow)) 

{

 return 0; 

}

return base.IndexCatalogEntryDto(...)

}

}

#193495
May 30, 2018 14:12
Vote:
 

Perhaps there have been some misscommunication. After I added this overriden method, no products are indexed, which makes me wonder.

#193496
May 30, 2018 14:15
Vote:
 

Did you try to debug it - was your ShouldNotIndex method too aggressive? 

#193498
May 30, 2018 14:27
Vote:
 

this is my code

        protected override int IndexCatalogEntryDto(IndexBuilder indexer, CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string[] languages)
        {
            var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId);
            var bySource = _relationRepository.Service.GetRelationsBySource<NodeRelation>(entryLink);
            var product = _contentLoader.Service.Get<ProductContent>(entryLink);
            var node = product.GetNodeRelations().FirstOrDefault();

            if (node != null)
            {
                var currentNode = _contentLoader.Service.Get<NodeContent>(node.Target);
                if (_indexingService.ShallBeIndexed(currentNode))
                {
                    //if (product.DisplayName.Contains("daniels"))
                    //{
                        return base.IndexCatalogEntryDto(indexer, entryRow, defaultCurrency, languages);
                    //}
                }
            }


            return 0;
        }
#193501
May 30, 2018 14:35
Vote:
 

Some comments:

  • It seems that you don't use bySource, that line can be removed
  • So you are only indexing products? I suggest to load EntryContentBase instead of ProductContent so it will cover more case
  • Did you debug to see if it reach
    var currentNode = _contentLoader.Service.Get<NodeContent>(node.Target);

    line ?

  • What is it checking in 
    _indexingService.ShallBeIndexed(currentNode)
#193505
May 30, 2018 15:20
Vote:
 

ShallBeIndexed check if the node has a parent with name "private", if so the product will be indexed, in other case not. My product is under the private-node, but does not show up in my product-variable in my method. I start to think that this row is not fetching the right stuff that I intend:

var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId);

I am only indexing products in this case.

#193506
May 30, 2018 15:24
Vote:
 

var entryLink = _referenceConverter.GetEntryContentLink(entryRow.CatalogEntryId);

this should work.

can you post the code of your ShallBeIndexed here? 

#193507
May 30, 2018 15:29
Vote:
 
        public bool ShallBeIndexed(IContent currentNode)
        {

            if (currentNode.ParentLink != null)
            {
                var node = _contentLoader.Service.Get<CatalogContentBase>(currentNode.ParentLink);

                if (node.Name.Equals("Privat"))
                {
                    return true;
                }
                else
                {
                    return ShallBeIndexed(node as IContent);
                }
            }
            else
                return false;
        }
#193508
May 30, 2018 15:40
Vote:
 

I misspelled Privat earlier, the name of my catalog node is Privat, and not Private.

#193509
Edited, May 30, 2018 15:41
Vote:
 

It seems that you are skipping the currentNode. So if your structure is like this

Catalog => Node => Privat Node => product

then you are checking Node and Catalog, but not Privat Node.

As a side comment ShallBeIndexed should take CatalogContentBase and you don't have to cast it back to IContent.

#193510
May 30, 2018 15:46
Vote:
 

My structure looks more like Catalog => Private Node => Category => product. So that shouldn't be an issue here.

#193546
May 31, 2018 7:51
Vote:
 

Then let's get back to the original question: can you debug it and does it hit the code inside 

ShallBeIndexed
#193548
May 31, 2018 8:58
Vote:
 

The debugger goes into ShallBeIndexed.

#193598
Jun 01, 2018 7:49
Vote:
 

The overridden method IndexCatalogEntryDto has the effect that nothing gets indexed. If I comment out that method, products gets indexed as normal. Strange this is.

#193611
Jun 01, 2018 9:48
Vote:
 

The problem I now have at hand is getting a node's parent node in accorance with episerver commerce catalog tree. How can this be achived?

#193803
Jun 05, 2018 13:03
Vote:
 

node.ParentLink should point you to the direct parent of a node. However if you are looking at linked nodes, you would need to use GetRelationsBySource(node.ContentLink)

#193813
Jun 05, 2018 14:57
Vote:
 

Well, I can get the products parent node, but not the parent node's parent node. The only clue I got is that the parent/child relationship may not follow the commerce tree.

#193815
Jun 05, 2018 15:00
Vote:
 

My node is not linked.

#193819
Jun 05, 2018 15:07
Vote:
 

Sorry, I now realized my misstake. The parent actually was retreived as it should.

#193821
Jun 05, 2018 15:13
Vote:
 

It turned out that our index was malfunctioning for other reasons. The solution provided by Quan in this thread worked as expected on our test and production servers.

#194849
Jul 04, 2018 14:24
Vote:
 

Glad to hear. And it's great that you comeback and update the result - one thing that I wish more people on World would do :) 

#194850
Jul 04, 2018 14:26
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.